Skip to main content

async_cron

Downloads PyPI version

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

Event loops

CronJob, Scheduler, JobLoader, and FileJobLoader reuse an explicitly supplied loop or the current event loop. When no loop exists, they create and install one, including on Python 3.14 and in worker threads. If you construct these objects synchronously, run them on that same loop and close the loop on shutdown. When using asyncio.run(main()), construct them inside main() so their asynchronous work uses the running loop.

Tests

Install the package and run either test entry point:

python -m pip install -e .
python runtests.py -v
python -m unittest discover -s tests -p 'test_*.py' -v

License

The async_cron is offered under MIT license.

Metadata

Release files for async-cron 1.6.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for async-cron 1.6.3
File Size Uploaded Provenance Actions
async_cron-1.6.3.tar.gz 12.0 kB Without provenance Details for async_cron-1.6.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for async-cron 1.6.3
File Interpreter ABI Platform Actions
async_cron-1.6.3-py3-none-any.whl Python 3 none any Details for async_cron-1.6.3-py3-none-any.whl

Total release size: 21.4 kB

Release files / async_cron-1.6.3.tar.gz

Download URL async_cron-1.6.3.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b10f41b18517ed7d2257577b6db505b3d75d8c9bc32128472d65df37454bacb1
BLAKE2b-256 checksum
How to use checksums
e2d06ce8e06284f8aeb896fa35ebd59c655e971406aa4eb60b9c8c47ff188970
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.4

Release files / async_cron-1.6.3-py3-none-any.whl

Download URL async_cron-1.6.3-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40ea5e109dd4bd4ca4fe9b143f3cd10497b6f761649e4d3747d7431c2671666e
BLAKE2b-256 checksum
How to use checksums
471db5cb788bb0a93a0e59ee1fe3cae66424f689fbcce299d8a43283cb84f57e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.4

Security for async-cron 1.6.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page