Skip to content

Commit

Permalink
Merge pull request #1 from dapper91/dev
Browse files Browse the repository at this point in the history
release 0.1.0
  • Loading branch information
dapper91 authored Mar 20, 2021
2 parents fc92883 + 86b3681 commit 32a4dd8
Show file tree
Hide file tree
Showing 13 changed files with 997 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .flake8
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
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
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/*
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ dmypy.json

# Pyre type checker
.pyre/

.idea/

Pipfile.lock
52 changes: 52 additions & 0 deletions .pre-commit-config.yaml
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
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Changelog
=========

0.1.0 (2021-03-19)
------------------

- Initial release
14 changes: 14 additions & 0 deletions Pipfile
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"
109 changes: 109 additions & 0 deletions README.rst
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())
55 changes: 55 additions & 0 deletions examples/quickstart.py
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())
10 changes: 10 additions & 0 deletions rescheduler/__about__.py
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'
34 changes: 34 additions & 0 deletions rescheduler/__init__.py
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',
]
Loading

0 comments on commit 32a4dd8

Please sign in to comment.