@@ -16,6 +16,7 @@ async def null_callback(*args):
1616
1717def wrap_func (func ):
1818 """wrap in a coroutine"""
19+
1920 @wraps (func )
2021 async def wrapper (* args , ** kwargs ):
2122 result = func (* args , ** kwargs )
@@ -27,9 +28,18 @@ async def wrapper(*args, **kwargs):
2728
2829
2930class Cron (object ):
30-
31- def __init__ (self , spec , func = None , args = (), kwargs = None , start = False ,
32- uuid = None , loop = None , tz = None , croniter_kwargs = None ):
31+ def __init__ (
32+ self ,
33+ spec ,
34+ func = None ,
35+ args = (),
36+ kwargs = None ,
37+ start = False ,
38+ uuid = None ,
39+ loop = None ,
40+ tz = None ,
41+ croniter_kwargs = None ,
42+ ):
3343 self .spec = spec
3444 if func is not None :
3545 kwargs = kwargs or {}
@@ -63,7 +73,7 @@ async def next(self, *args):
6373 self .initialize ()
6474 self .future = asyncio .Future (loop = self .loop )
6575 self .handle = self .loop .call_at (self .get_next (), self .call_func , * args )
66- return ( await self .future )
76+ return await self .future
6777
6878 def initialize (self ):
6979 """Initialize croniter and related times"""
@@ -72,9 +82,7 @@ def initialize(self):
7282 self .datetime = datetime .now (self .tz )
7383 self .loop_time = self .loop .time ()
7484 self .croniter = croniter (
75- self .spec ,
76- start_time = self .datetime ,
77- ** self .croniter_kwargs
85+ self .spec , start_time = self .datetime , ** self .croniter_kwargs
7886 )
7987
8088 def get_next (self ):
@@ -92,16 +100,14 @@ def call_next(self):
92100 def call_func (self , * args , ** kwargs ):
93101 """Called. Take care of exceptions using gather"""
94102 """Check the version of python installed"""
95- if ( sys .version_info [0 :2 ] >= (3 , 10 ) ):
103+ if sys .version_info [0 :2 ] >= (3 , 10 ):
96104 asyncio .gather (
97- self .cron (* args , ** kwargs ),
98- return_exceptions = True
99- ).add_done_callback (self .set_result )
105+ self .cron (* args , ** kwargs ), return_exceptions = True
106+ ).add_done_callback (self .set_result )
100107 else :
101108 asyncio .gather (
102- self .cron (* args , ** kwargs ),
103- loop = self .loop , return_exceptions = True
104- ).add_done_callback (self .set_result )
109+ self .cron (* args , ** kwargs ), loop = self .loop , return_exceptions = True
110+ ).add_done_callback (self .set_result )
105111
106112 def set_result (self , result ):
107113 """Set future's result if needed (can be an exception).
@@ -125,11 +131,13 @@ def __call__(self, func):
125131 return self
126132
127133 def __str__ (self ):
128- return ' {0.spec} {0.func}' .format (self )
134+ return " {0.spec} {0.func}" .format (self )
129135
130136 def __repr__ (self ):
131- return ' <Cron {0.spec} {0.func}>' .format (self )
137+ return " <Cron {0.spec} {0.func}>" .format (self )
132138
133139
134140def crontab (spec , func = None , args = (), kwargs = None , start = True , loop = None , tz = None ):
135- return Cron (spec , func = func , args = args , kwargs = kwargs , start = start , loop = loop , tz = tz )
141+ return Cron (
142+ spec , func = func , args = args , kwargs = kwargs , start = start , loop = loop , tz = tz
143+ )
0 commit comments