A package to run cron jobs(events)
Project description
Cron Events
This module provides a way to schedule recurring events using a cron-like syntax. Events can be scheduled to run at specific intervals or at specific times on specific days.
Table of Contents
Installation
pip install cronevents
Learn by Example
"""Cron-like event scheduling module.
This module provides a way to schedule recurring events using a cron-like syntax.
Events can be scheduled to run at specific intervals or at specific times on specific days.
Syntax:
'(`every` | `in` | `on`) (`Weekday` | `n unit [n unit ...]`) [@ hh[:mm[:ss]] ["am" | "pm"]] [Timezone]'
Combine multiple schedules with `||`:
'every Monday @ 9:00 am || every Friday @ 5:00 pm'
Examples:
'every 2 days @ 10:00:00 pm'
'every Monday @ 23'
'every 5 seconds'
'every 2 days 1 hours 23 minutes 2 seconds'
'every 1 days @ 9:00 am America/New_York'
Note:
Using '@' will run the event at least once a day.
Timezone defaults to UTC. Append any IANA timezone name (e.g. America/New_York)
or a custom abbreviation registered with add_timezone_abbr().
"""
# Uncomment to register events to the event manager
# import os
# os.environ['REGISTER_CRON_EVENT'] = 'true'
from cronevents.event_manager import event, add_timezone_abbr
@event('every 31 seconds')
def test():
"""Write 'test' to a file and print it every 31 seconds."""
with open('test.txt', 'a') as f:
f.write('test\n')
print('test')
@event('every 2 days 1 hours 23 minutes 2 seconds')
def test2():
"""Write 'test2' to a file and print 'test2' every 2 days, 1 hour, 23 minutes, and 2 seconds."""
with open('test.txt', 'a') as f:
f.write('test2\n')
print('test2')
@event('every 1 days @ 2:00 pm')
def test3():
"""Write 'test3' to a file and print it daily at 2:00 PM."""
with open('test.txt', 'a') as f:
f.write('test3\n')
print('test3')
@event('every Friday')
def test4():
"""Write 'test4' to a file and print it every Friday."""
with open('test.txt', 'a') as f:
f.write('test4\n')
print('test4')
@event('every Tuesday @ 3:00')
def test5():
"""Write 'test5' to a file and print it every Tuesday at 3:00 AM."""
with open('test.txt', 'a') as f:
f.write('test5\n')
print('test5')
# Use a full IANA timezone name appended to the query
@event('every 1 days @ 9:00 am America/New_York')
def test6():
"""Write 'test6' to a file and print it daily at 9:00 AM Eastern time."""
with open('test.txt', 'a') as f:
f.write('test6\n')
print('test6')
# Or register a custom abbreviation and use that instead
add_timezone_abbr('America/Los_Angeles', 'PT')
@event('every Monday @ 8:00 am PT')
def test7():
"""Write 'test7' to a file and print it every Monday at 8:00 AM Pacific time."""
with open('test.txt', 'a') as f:
f.write('test7\n')
print('test7')
License
- MIT License
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
cronevents-0.0.42.tar.gz
(35.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cronevents-0.0.42.tar.gz.
File metadata
- Download URL: cronevents-0.0.42.tar.gz
- Upload date:
- Size: 35.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1448a5280abfd6affebd578bf168ae84390589309f8cdda4918bb0f390fa9ccf
|
|
| MD5 |
0a28c5e50d2010053dcf36b7c07b7781
|
|
| BLAKE2b-256 |
7295214d8dd41afab5a3eea4f414962bd0a089f0a85f6ba749b2e06c7835effc
|
File details
Details for the file cronevents-0.0.42-py3-none-any.whl.
File metadata
- Download URL: cronevents-0.0.42-py3-none-any.whl
- Upload date:
- Size: 45.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e855322f6911865e700417988968e2ee463e3e17d708dd12f0d592840553f44
|
|
| MD5 |
ad680e8f19003c17c5d7a3d59eebebd7
|
|
| BLAKE2b-256 |
a2c5430088f90e2c6c8721b6d9bde003d4a303617cc7b820bfac09ad36bbd402
|