Skip to content

Commit

Permalink
Merge pull request #37 from shpaker/feat-kwargs-in-cron-class
Browse files Browse the repository at this point in the history
kwargs for function in Cron constructor
  • Loading branch information
gawel authored Mar 29, 2023
2 parents 8899455 + aca1397 commit b396c78
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.7, 3.8, 3.9, "3.10"]
python: [3.7, 3.8, 3.9, "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
aiocron - Crontabs for asyncio
================================================

.. image:: https://travis-ci.org/gawel/aiocron.svg?branch=master
:target: https://travis-ci.org/gawel/aiocron

.. image:: https://img.shields.io/pypi/v/aiocron.svg
:target: https://pypi.python.org/pypi/aiocron
.. image:: https://img.shields.io/pypi/dm/aiocron.svg
Expand Down
17 changes: 9 additions & 8 deletions aiocron/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
from croniter.croniter import croniter
from datetime import datetime
from functools import wraps, partial
from tzlocal import get_localzone
from uuid import uuid4
import time
import functools
import asyncio
import sys
import inspect
Expand All @@ -16,7 +16,7 @@ async def null_callback(*args):

def wrap_func(func):
"""wrap in a coroutine"""
@functools.wraps(func)
@wraps(func)
async def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
if inspect.isawaitable(result):
Expand All @@ -28,11 +28,12 @@ async def wrapper(*args, **kwargs):

class Cron(object):

def __init__(self, spec, func=None, args=(), start=False, uuid=None,
loop=None, tz=None, croniter_kwargs=None):
def __init__(self, spec, func=None, args=(), kwargs=None, start=False,
uuid=None, loop=None, tz=None, croniter_kwargs=None):
self.spec = spec
if func is not None:
self.func = func if not args else functools.partial(func, *args)
kwargs = kwargs or {}
self.func = func if not (args or kwargs) else partial(func, *args, **kwargs)
else:
self.func = null_callback
self.tz = get_localzone() if tz is None else tz
Expand Down Expand Up @@ -110,7 +111,7 @@ def set_result(self, result):
if isinstance(result, Exception):
self.future.set_exception(result)
elif not self.future.done():
self.future.set_result(result)
self.future.set_result(result)
self.future = None
elif isinstance(result, Exception):
raise result
Expand All @@ -130,5 +131,5 @@ def __repr__(self):
return '<Cron {0.spec} {0.func}>'.format(self)


def crontab(spec, func=None, args=(), start=True, loop=None, tz=None):
return Cron(spec, func=func, args=args, start=start, loop=loop, tz=tz)
def crontab(spec, func=None, args=(), kwargs=None, start=True, loop=None, tz=None):
return Cron(spec, func=func, args=args, kwargs=kwargs, start=start, loop=loop, tz=tz)
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ def read(name):
'Environment :: Web Environment',
'Intended Audience :: Developers',
'Operating System :: POSIX',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'License :: OSI Approved :: MIT License',
'Topic :: Software Development :: Libraries :: Python Modules',
],
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py37,py38,py39,py310
envlist = py{37,38,39,310,311}

[testenv]
commands =
Expand Down

0 comments on commit b396c78

Please sign in to comment.