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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file python-cli-scheduler-1.1.1.tar.gz.

File metadata

  • Download URL: python-cli-scheduler-1.1.1.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for python-cli-scheduler-1.1.1.tar.gz
Algorithm Hash digest
SHA256 66b919b55bbe9aab1fd1de1434d5c29756f89813efb90e2c5a40648e320d7039
MD5 3cfe16801f74957a9a2c7dc851a2c35b
BLAKE2b-256 4efc1970d0ad08d77401e3bc9adb3140c7e5d07116f2574ebe658362c560b180

See more details on using hashes here.

File details

Details for the file python_cli_scheduler-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_cli_scheduler-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 19bf25513ef15f64e3008ee248576e91dcdc2b237d8f5faee7c21edecdf45f2e
MD5 b4f698078b89ca825ea3e7d1ded310b8
BLAKE2b-256 9fb5fcc9bdbb231415694d6aec6c84a3c0694aa25878039314d78302683ee8f9

See more details on using hashes here.

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