asyncio crontab utils
Project description
async_cron
this repo is influenced by schedule.
we supply a async scheduler and async function support
you can easily integrate this lib to you async program,with no blocking
Install
pip install async-cron
Usage examples
import asyncio
from async_cron.job import CronJob
from async_cron.schedule import Scheduler
async def test(*args, **kwargs):
print(args, kwargs)
def tt(*args, **kwargs):
print(args, kwargs)
msh = Scheduler(locale="zh_CN")
myjob = CronJob(name='test', run_total=3).every(
5).second.go(test, (1, 2, 3), name=123)
job2 = CronJob(name='exact', tolerance=100).at(
"2019-01-15 16:12").go(tt, (5), age=99)
job3 = CronJob(name='very_hour').every().hour.at(
":44").go(tt, (5), age=99)
job3 = CronJob(name='hour').every().hour.at(
":00").go(tt, (5), age=99)
job4 = CronJob(name='minute').every(1).minute.go(tt, (5), age=99)
job5 = CronJob(name='weekday').weekday(2).at("11:18").go(tt, (5), age=99)
job6 = CronJob(name='monthday').monthday(16).at("11:22").go(tt, (5), age=99)
job7 = CronJob(name='monthday').every(5).monthday(
16).at("11:22").go(tt, (5), age=99)
msh.add_job(myjob)
msh.add_job(job2)
msh.add_job(job3)
msh.add_job(job4)
msh.add_job(job5)
msh.add_job(job6)
msh.add_job(job7)
# jobload is only a special job,who gen jobs from config
# below means, this job load will check every 1 second for cron updates
# if any updates found,new job will be add to scheduler
# you dont have the direct way to delete jobs
# but you can modify the crons total_times to 0 or 1 to delete it
# by default,FileJobLoader use MultiThread,you can use MultiProcess by add
# thread=False
f_cron = FileJobLoader(name='f_cron', file_path='t_cron', log_path='.',thread=False)
fjob = CronJob(name='fjob', run_total=1).every(
1).second.go(f_cron.run, msh)
msh.add_job(fjob)
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(msh.start())
except KeyboardInterrupt:
print('exit')
cron file useage:
parameter separate by blank.in item separate by comma
cron | name | job | env | run_times |
---|---|---|---|---|
*/1,*,*,*,* |
test | /bin/python,tt.py | aa=123,bb=345 | 10 |
example as follow:
common cron
*/1,*,*,*,*
test /bin/python,tt.py aa=123,bb=345 1
delete cron
*/1,*,*,*,*
test /bin/python,tt.py aa=123,bb=345 0
cron only support:
*
,10
,*/10
format. which fulfills mostly screen
License
The async_cron is offered under 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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file async_cron-1.6.2-py3-none-any.whl
.
File metadata
- Download URL: async_cron-1.6.2-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d534562d82288d0e30e03e45509d7d2e8c62838b83c7c59403d64ed9ee4ca58f |
|
MD5 | 393ca87172b474bfd351eff10f69b5ae |
|
BLAKE2b-256 | 90c4695681ae46af9d60d5f2a8e6cce556c5e7e32be23e891e85e245e9b45650 |