Skip to main content

a small crontab deploying package for python

Project description

Build Status pypi  GitHub license 

cronpi

A small tool for deploying crontab jobs into a unix-like system, eg. Linux/Mac from python.

cronpi makes jobs more human readable and works on both 2.X and 3.X version.

Installation

pip install cronpi

Usage

cronpi has following functions

SN Name Description
1. run_by_date job that runs just by setting date in format YYYY-MM-DD HH:mm
2. run_every_day job that runs every day at given time HH:mm
3. run_every_week job that runs every week at the given time of given weekdays
4. run_every_month job that runs every month at the given time of given days of a month
5. run_every_year job that runs at the given time of given days of given months
6. run_custom command will be exactly similar to single line which we write during "crontab -e"

Each functions take two parameters

<command to execute>, <isOverwrite=bool>?
parameter type description
command string This command will be executed as scheduled
isOverwrite bool It is optional and default value is false, which means cronpi will always insert new job

cronpi will always install a new cron job if only command is passed as parameter or isOverwrite is set to False. If command passed as first parameter already exists in cronjon and "isOverwrite=True" is passed as second parameter ,then it will update the time of running the job instead of adding new job.

cronpi.XXXX("/some/command", isOverwrite=True)

Time used as parameter can contain or may not contain AM|PM prefix. For eg, following two parameters represent same time.

5:30pm = 17:30

Use Case 1 - Run By Date

  1. Run a job at 20th october 2020 at 5:30PM
import cronpi
cronpi.run_by_date("/some/command").on("2020-10-20 5:30pm")

※ This command will run every year after if the command is not deleted from crontab manually.

Use Case 2 - Run every day

  1. Run a job daily at 5:30PM
import cronpi
cronpi.run_every_day("/some/command").on("5:30pm")

Use Case 3 - Run every week

  1. Run a job at every sunday at 5:30PM
import cronpi
cronpi.run_every_week("/some/command").on("sunday", time="17:30")
  1. Run a job at every saturday and sunday at 5:30PM
import cronpi
cronpi.run_every_week("/some/command").on(["sat", "sun"], time="5:30PM")

Use Case 4 - Run every month

  1. Run a job at every 10th of a month at 5:30PM
import cronpi
cronpi.run_every_month("/some/command").on(10, time="17:30")
  1. Run a job at every 10th and 20th of a month at 5:30PM
import cronpi
cronpi.run_every_month("/some/command").on([10,20], time="17:30")

Use Case 5 - Run every year

  1. Run a job at every 10th january at 5:30am
import cronpi
cronpi.run_every_year("/some/command").on("january", day=10, time="5:30am")
  1. Run a job at every 10th of january, april and october at 5:30AM
import cronpi
cronpi.run_every_year("/some/command").on(["jan", "oct"], day=10, time="5:30")

Use Case 6 - run like crontab

Add a job to crontab by passing the command that we input to "crontab -e" command.

  1. Run a job that runs at every minute
import cronpi
cronpi.run_custom("* * * * * /some/command")
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │                                   7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * command to execut

Helper Function - Get list of current jobs

cronpi has a helper function named "get_job_list" which will retrive the the job items in list.

import cronpi
cronpi.get_job_list()

Release information

Nov 12th, 2019 (ver@2.0.0)

  • restructured the library format so that it is more human readable.
    cronpi.run_every_month("/some/command")
        .on([10,20], time="1:30AM")

Nov 7th, 2019 (ver@1.0.0)

  • released first version

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

cronpi-2.0.1.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

cronpi-2.0.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file cronpi-2.0.1.tar.gz.

File metadata

  • Download URL: cronpi-2.0.1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

File hashes

Hashes for cronpi-2.0.1.tar.gz
Algorithm Hash digest
SHA256 f01553594e3bdf3f2f2750d84a4a7ef9e6d801e861abeb2e5857d69aed67f6b0
MD5 c35c20aa653eb041f0701ab905996654
BLAKE2b-256 e47231171460dbf78323582f7ad4e1c8f2e426c69bb1e7306d80d04b462bac9c

See more details on using hashes here.

File details

Details for the file cronpi-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: cronpi-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

File hashes

Hashes for cronpi-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ca766233216e00937cd1a6d5cc18cb5c3cea80c80024f71bcbc1b02f57259b68
MD5 e8219fc1a440d5cbc15a6d7e5bd0dacd
BLAKE2b-256 9a2df52de2a6f6f9f675aa01e8be66c925c855deaf57d955fd23de1e60556251

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