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.0.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_cli_scheduler-1.0.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python-cli-scheduler-1.0.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.9

File hashes

Hashes for python-cli-scheduler-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e168342e1d4b2bab1ddb5bfa83c6f8ee561e9c902a86e086345a14cb915cd6ba
MD5 0b1e995ba100991bad356d77e3537431
BLAKE2b-256 90577d093ed27dd944c9730459bb1e055c60bc690d2e640e006dc2fb723d24cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_cli_scheduler-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6958cd6a9ef433ae909d99c332347e167a92c0f17794fe0cea574133eb965fb
MD5 283727958fa324a550d5ce50a8e923fd
BLAKE2b-256 5b86d00e1172e919022e20209a287b97cee7a14840012ff37efab19a10f118fa

See more details on using hashes here.

Supported by

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