-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dapper91/dev
release 0.1.0
- Loading branch information
Showing
13 changed files
with
997 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[flake8] | ||
max-line-length = 130 | ||
per-file-ignores = | ||
rescheduler/*__init__.py: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: release | ||
|
||
on: | ||
release: | ||
types: | ||
- released | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools wheel twine | ||
- name: Build and publish | ||
env: | ||
TWINE_USERNAME: __token__ | ||
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} | ||
run: | | ||
python setup.py sdist | ||
twine upload dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,7 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
.idea/ | ||
|
||
Pipfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v3.4.0 | ||
hooks: | ||
- id: check-docstring-first | ||
stages: | ||
- commit | ||
- push | ||
- id: check-merge-conflict | ||
stages: | ||
- push | ||
- id: trailing-whitespace | ||
stages: | ||
- commit | ||
- push | ||
- id: end-of-file-fixer | ||
stages: | ||
- commit | ||
- push | ||
- id: mixed-line-ending | ||
stages: | ||
- commit | ||
- push | ||
args: | ||
- --fix=lf | ||
- id: no-commit-to-branch | ||
stages: | ||
- commit | ||
- repo: https://github.com/pre-commit/mirrors-autopep8 | ||
rev: v1.5.6 | ||
hooks: | ||
- id: autopep8 | ||
stages: | ||
- commit | ||
- push | ||
args: | ||
- --max-line-length=130 | ||
- --diff | ||
- repo: https://github.com/asottile/add-trailing-comma | ||
rev: v2.1.0 | ||
hooks: | ||
- id: add-trailing-comma | ||
stages: | ||
- commit | ||
- push | ||
- repo: https://gitlab.com/pycqa/flake8 | ||
rev: 3.9.0 | ||
hooks: | ||
- id: flake8 | ||
stages: | ||
- commit | ||
- push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Changelog | ||
========= | ||
|
||
0.1.0 (2021-03-19) | ||
------------------ | ||
|
||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[[source]] | ||
name = "pypi" | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
|
||
[dev-packages] | ||
pytest = "~=6.0" | ||
|
||
[packages] | ||
aiojobs = "~=0.0" | ||
aioredis = "~=1.0" | ||
async-lru = "~=1.0" | ||
crontools = "~=0.0" | ||
tzlocal = "~=2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
=========== | ||
rescheduler | ||
=========== | ||
|
||
.. image:: https://github.com/dapper91/rescheduler/actions/workflows/test.yml/badge.svg | ||
:target: https://github.com/dapper91/rescheduler/actions/workflows/test.yml | ||
:alt: Build status | ||
.. image:: https://img.shields.io/pypi/l/rescheduler.svg | ||
:target: https://pypi.org/project/rescheduler | ||
:alt: License | ||
.. image:: https://img.shields.io/pypi/pyversions/rescheduler.svg | ||
:target: https://pypi.org/project/rescheduler | ||
:alt: Supported Python versions | ||
|
||
|
||
``rescheduler`` is a task scheduler built on top of redis. It stores all jobs and schedules in redis which provides | ||
persistency (depends on redis persistent level configuration), distributed work (multiple schedulers allowed to be | ||
run simultaneously) and fault tolerance (in case of one scheduler crash the others takes away its jobs). | ||
|
||
|
||
Installation | ||
------------ | ||
|
||
You can install rescheduler with pip: | ||
|
||
.. code-block:: console | ||
$ pip install rescheduler | ||
Quickstart | ||
---------- | ||
|
||
Server side: | ||
~~~~~~~~~~~~ | ||
|
||
.. code-block:: python | ||
import asyncio | ||
import aioredis | ||
from rescheduler import Scheduler, Job | ||
def tick(): | ||
print("tick") | ||
def tack(): | ||
print("tack") | ||
async def callback(job: Job): | ||
if job.data['method'] == 'tick': | ||
tick() | ||
elif job.data['method'] == 'tack': | ||
tack() | ||
async def main(): | ||
conn_pool = await aioredis.create_redis_pool(('localhost', 6379)) | ||
async with Scheduler(conn_pool=conn_pool, job_callback=callback, use_keyspace_notifications=True): | ||
await asyncio.sleep(30) | ||
conn_pool.close() | ||
await conn_pool.wait_closed() | ||
if __name__ == '__main__': | ||
asyncio.run(main()) | ||
Client side: | ||
~~~~~~~~~~~~ | ||
|
||
.. code-block:: python | ||
import asyncio | ||
import aioredis | ||
from rescheduler import Scheduler, Job, CronTrigger | ||
async def main(): | ||
conn_pool = await aioredis.create_redis_pool(('localhost', 6379)) | ||
scheduler = Scheduler(conn_pool=conn_pool, job_callback=lambda: None) | ||
await scheduler.add_job( | ||
Job( | ||
id='tick-task', | ||
trigger=CronTrigger.parse(expr='*/10 * * * * *', seconds_ext=True), | ||
data={'method': 'tick'}, | ||
) | ||
) | ||
await scheduler.add_job( | ||
Job( | ||
id='tack-task', | ||
trigger=CronTrigger.parse(expr='*/10 * * * * *', seconds_ext=True), | ||
data={'method': 'tack'}, | ||
), | ||
delay=5.0, | ||
) | ||
conn_pool.close() | ||
await conn_pool.wait_closed() | ||
if __name__ == '__main__': | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import asyncio | ||
|
||
import aioredis | ||
from rescheduler import Scheduler, Job, CronTrigger | ||
|
||
|
||
def tick(): | ||
print("tick") | ||
|
||
|
||
def tack(): | ||
print("tack") | ||
|
||
|
||
async def callback(job: Job): | ||
if job.data['method'] == 'tick': | ||
tick() | ||
|
||
elif job.data['method'] == 'tack': | ||
tack() | ||
|
||
|
||
async def main(): | ||
conn_pool = await aioredis.create_redis_pool(('localhost', 6379), maxsize=20) | ||
async with Scheduler(conn_pool=conn_pool, job_callback=callback, use_keyspace_notifications=True) as scheduler: | ||
await scheduler.add_job( | ||
Job( | ||
id='tick', | ||
trigger=CronTrigger.parse(expr='*/10 * * * * *', seconds_ext=True), | ||
data={'method': 'tick'}, | ||
), | ||
) | ||
|
||
await scheduler.add_job( | ||
Job( | ||
id='tack', | ||
trigger=CronTrigger.parse(expr='*/10 * * * * *', seconds_ext=True), | ||
data={'method': 'tack'}, | ||
), | ||
delay=5.0, | ||
) | ||
|
||
await asyncio.sleep(60) | ||
|
||
await scheduler.cancel_job(job_id='tick') | ||
await scheduler.cancel_job(job_id='tack') | ||
|
||
print(await scheduler.get_jobs()) | ||
|
||
conn_pool.close() | ||
await conn_pool.wait_closed() | ||
|
||
|
||
if __name__ == '__main__': | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
__title__ = 'rescheduler' | ||
__description__ = 'Python redis scheduler' | ||
__url__ = 'https://github.com/dapper91/rescheduler' | ||
|
||
__version__ = '0.1.0' | ||
|
||
__author__ = 'Dmitry Pershin' | ||
__email__ = '[email protected]' | ||
|
||
__license__ = 'Public Domain License' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Python redis scheduler. | ||
""" | ||
|
||
from .job import Job, Trigger, OneShotTrigger, PeriodicTrigger, CronTrigger | ||
from .scheduler import Scheduler | ||
|
||
|
||
from .__about__ import ( | ||
__title__, | ||
__description__, | ||
__url__, | ||
__version__, | ||
__author__, | ||
__email__, | ||
__license__, | ||
) | ||
|
||
__all__ = [ | ||
'__title__', | ||
'__description__', | ||
'__url__', | ||
'__version__', | ||
'__author__', | ||
'__email__', | ||
'__license__', | ||
|
||
'CronTrigger', | ||
'Job', | ||
'OneShotTrigger', | ||
'PeriodicTrigger', | ||
'Scheduler', | ||
'Trigger', | ||
] |
Oops, something went wrong.