Support scheduling of task via command line interface.
Project description
CLI Scheduler
Library support scheduling of task via command line interface.
Installation
pip3 install python-cli-scheduler
Usage
Scheduler format: ^<run_now>@<interval>/<delay>$<end_timestamp>#<retry>
Parameters:
run_now
: Execute now. Default:True
interval
: Repeat execute after number of seconds. If set toNone
, execute one time and not repeat. Default:None
delay
: Execute at seconddelay
-th at each interval. Default: `0end_time
: Execute untilend_time
. If set toNone
, infinite repeat. Default:None
retry
: Retry if exception when executed. Default:True
Example
Use with decorator
Coming soon
Use with scheduler job class
Example job to print a lucky number at second 3 every minute.
import time
import random
from cli_scheduler.scheduler_job import SchedulerJob
class RotationLuckJob(SchedulerJob):
def __init__(self, scheduler):
super().__init__(scheduler=scheduler)
def _pre_start(self):
self.logger.info('Rotation luck. Have fun !')
def _start(self):
self.n = random.randint(0, 1000)
def _execute(self, *args, **kwargs):
self.logger.info(f'The lucky number is {self.n}')
def _end(self):
del self.n
def _follow_end(self):
self.logger.info('Done')
if __name__ == '__main__':
end_time = int(time.time()) + 5 * 60
# ^false: Not execute now
# @60: Repeat execute every 60 second
# /3: Execute at second 3
# ${end_time}: Run until end_time
# #false: Don't retry if exception when execute
job = RotationLuckJob(scheduler=f'^false@60/3${end_time}#false')
job.run()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for python-cli-scheduler-1.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4acced7926aefef4f804e3da966bf041bfe58d3a6012f5176b963f387a920e4f |
|
MD5 | 757e60e8ebb4820ee9f97e1fa2eac465 |
|
BLAKE2b-256 | a6719cad4765e1b5e3cfd9d190902522ab66ed7facd8d2130b723892b3319e10 |
Close
Hashes for python_cli_scheduler-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43194862e9ab6763a3931c7552ca9f93cb2d2cff9f011ea3d6f80d5905162326 |
|
MD5 | 15e9d014cd77c84d8db46886e6c3f84f |
|
BLAKE2b-256 | 978cc399cd8f85e061a6471ffe8d8ad9e3a0faa4cd2aa2d50e457cc6a1668a19 |