Skip to main content

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 to None, execute one time and not repeat. Default: None
  • delay: Execute at second delay-th at each interval. Default: `0
  • end_time: Execute until end_time. If set to None, 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-cli-scheduler-1.1.1.tar.gz (7.3 kB view hashes)

Uploaded Source

Built Distribution

python_cli_scheduler-1.1.1-py3-none-any.whl (8.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page