Skip to main content

This library is designed for asynchronous execution of scheduled tasks.

Project description

AIOBGJOBS DOCS

En - docs

This library is designed for asynchronous execution of scheduled tasks.

Simple example:

import asyncio
import datetime

from aiobgjobs.dispatcher import BgDispatcher
from aiobgjobs.types import Every, Repeats

bg_dp = BgDispatcher()


@bg_dp.handler_job(
    every=Every.seconds(15),
    count_repeats=3
)
async def simple_func_every_second():
    print('Test')


@bg_dp.handler_job(
    every=Every.weekdays.monday(hour=11, minute=40),
    count_repeats=Repeats.infinity
)
async def simple_func_infinity_monday():
    print('Test2')


@bg_dp.handler_job(
    every=Every.minutes(2),
    count_repeats=Repeats.infinity
)
async def simple_func_every_2_minutes():
    print('Test3')


@bg_dp.handler_job(
    count_repeats=Repeats.one,
    datetime_start=datetime.timedelta(minutes=2.0)
)
async def simple_func_delta_to_start():
    print('Test4')


async def main():
    await asyncio.create_task(bg_dp.start(relax=.3))


if __name__ == '__main__':
    loop = asyncio.new_event_loop()
    try:
        loop.run_until_complete(main())
    except KeyboardInterrupt:
        print('Goodbye!')

Example without using decorators:

import asyncio
import datetime

from aiobgjobs.dispatcher import BgDispatcher
from aiobgjobs.handlers import Handler
from aiobgjobs.jobs import Job
from aiobgjobs.types import Every, Repeats

bg_dp = BgDispatcher()

async def simple_func_every_seconds():
    print('Test')

async def simple_func_infinity_monday():
    print('Test2')

async def simple_func_every_2_minutes():
    print('Test3')

async def simple_func_delta_to_start():
    print('Test4')


bg_dp.register_handler(
    Handler(
        job=Job(
            func=simple_func_every_seconds,
            name='Job - 1',
            kwargs=None
        ),
        count_repeats=3,
        every=Every.seconds(15)
    )
)

bg_dp.register_handler(
    Handler(
        job=Job(
            func=simple_func_infinity_monday,
            name='Job - 2',
            kwargs=None
        ),
        count_repeats=Repeats.infinity,
        every=Every.weekdays.monday()
    )
)

bg_dp.register_handler(
    Handler(
        job=Job(
            func=simple_func_every_2_minutes,
            name='Job - 3',
            kwargs=None
        ),
        count_repeats=Repeats.infinity,
        every=Every.minutes(2)
    )
)

bg_dp.register_handler(
    Handler(
        job=Job(
            func=simple_func_delta_to_start,
            name='Job - 4',
            kwargs=None
        ),
        count_repeats=Repeats.one,
        datetime_start=datetime.timedelta(minutes=2)
    )
)


async def main():
    await asyncio.create_task(bg_dp.start(relax=.3))


if __name__ == '__main__':
    loop = asyncio.new_event_loop()
    try:
        loop.run_until_complete(main())
    except KeyboardInterrupt:
        print('Goodbye!')

Ru - docs

Эта библиотека предназначена для асинхронного выполнения задач по расписанию.

Простой пример:

import asyncio
import datetime

from aiobgjobs.dispatcher import BgDispatcher
from aiobgjobs.types import Every, Repeats

bg_dp = BgDispatcher()


@bg_dp.handler_job(
    every=Every.seconds(15),
    count_repeats=3
)
async def simple_func_every_second():
    print('Test')


@bg_dp.handler_job(
    every=Every.weekdays.monday(hour=11, minute=40),
    count_repeats=Repeats.infinity
)
async def simple_func_infinity_monday():
    print('Test2')


@bg_dp.handler_job(
    every=Every.minutes(2),
    count_repeats=Repeats.infinity
)
async def simple_func_every_2_minutes():
    print('Test3')


@bg_dp.handler_job(
    count_repeats=Repeats.one,
    datetime_start=datetime.timedelta(minutes=2.0)
)
async def simple_func_delta_to_start():
    print('Test4')


async def main():
    await asyncio.create_task(bg_dp.start(relax=.3))


if __name__ == '__main__':
    loop = asyncio.new_event_loop()
    try:
        loop.run_until_complete(main())
    except KeyboardInterrupt:
        print('Goodbye!')

Пример без использования декораторов:

import asyncio
import datetime

from aiobgjobs.dispatcher import BgDispatcher
from aiobgjobs.handlers import Handler
from aiobgjobs.jobs import Job
from aiobgjobs.types import Every, Repeats

bg_dp = BgDispatcher()

async def simple_func_every_seconds():
    print('Test')

async def simple_func_infinity_monday():
    print('Test2')

async def simple_func_every_2_minutes():
    print('Test3')

async def simple_func_delta_to_start():
    print('Test4')


bg_dp.register_handler(
    Handler(
        job=Job(
            func=simple_func_every_seconds,
            name='Job - 1',
            kwargs=None
        ),
        count_repeats=3,
        every=Every.seconds(15)
    )
)

bg_dp.register_handler(
    Handler(
        job=Job(
            func=simple_func_infinity_monday,
            name='Job - 2',
            kwargs=None
        ),
        count_repeats=Repeats.infinity,
        every=Every.weekdays.monday()
    )
)

bg_dp.register_handler(
    Handler(
        job=Job(
            func=simple_func_every_2_minutes,
            name='Job - 3',
            kwargs=None
        ),
        count_repeats=Repeats.infinity,
        every=Every.minutes(2)
    )
)

bg_dp.register_handler(
    Handler(
        job=Job(
            func=simple_func_delta_to_start,
            name='Job - 4',
            kwargs=None
        ),
        count_repeats=Repeats.one,
        datetime_start=datetime.timedelta(minutes=2)
    )
)


async def main():
    await asyncio.create_task(bg_dp.start(relax=.3))


if __name__ == '__main__':
    loop = asyncio.new_event_loop()
    try:
        loop.run_until_complete(main())
    except KeyboardInterrupt:
        print('Goodbye!')

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

aiobgjobs-0.1.6.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

aiobgjobs-0.1.6-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file aiobgjobs-0.1.6.tar.gz.

File metadata

  • Download URL: aiobgjobs-0.1.6.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Darwin/20.6.0

File hashes

Hashes for aiobgjobs-0.1.6.tar.gz
Algorithm Hash digest
SHA256 93b01ba143b3b5ddc01d2ec515667543d3f8d4f979fe41397a1a79df5278431a
MD5 018cceb316a092ca7e0d46e4a4f0ddc5
BLAKE2b-256 e566457c72af24d1b7ffd774dae98bb330dd65eb5a88e09795f95a3635a88409

See more details on using hashes here.

File details

Details for the file aiobgjobs-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: aiobgjobs-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Darwin/20.6.0

File hashes

Hashes for aiobgjobs-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1499ce787f035b76c76b4451d8e433fb9e99a3cfbb7d24d63029bdb6bc214387
MD5 43e4bfd82566d3c651ceab553777b9f7
BLAKE2b-256 93926d8940a321c4cd3540242f84976ce7f6922ea5724d5f0244000b10ec6e40

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