55
66
77class BaseTask (object ):
8- STATUS_PENDING = ' pending'
9- STATUS_RUNNING = ' running'
10- STATUS_HALTED = ' halted'
11- STATUS_COMPLETE = ' complete'
8+ STATUS_PENDING = " pending"
9+ STATUS_RUNNING = " running"
10+ STATUS_HALTED = " halted"
11+ STATUS_COMPLETE = " complete"
1212
1313 is_standalone = True
1414
@@ -131,7 +131,8 @@ def find_root(cls, task):
131131 def then (self , task ):
132132 if self ._next :
133133 raise RuntimeError (
134- 'Unsupported operation. Multiple then operations are not support. Use a CompositeTask instead.' )
134+ "Unsupported operation. Multiple then operations are not support. Use a CompositeTask instead."
135+ )
135136
136137 task = task .local_root
137138 self ._next = task
@@ -140,23 +141,25 @@ def then(self, task):
140141
141142 def _get_task_data (self ):
142143 return {
143- ' class' : type_to_string (type (self )),
144- ' max_runs' : self .max_runs ,
145- 'id' : self ._id ,
146- ' name' : self ._name ,
147- ' needs_prev_result' : self ._needs_prev_result ,
148- ' runs' : self ._runs ,
149- ' status' : self ._status ,
150- ' result' : self ._result ,
151- ' is_standalone' : self .is_standalone
144+ " class" : type_to_string (type (self )),
145+ " max_runs" : self .max_runs ,
146+ "id" : self ._id ,
147+ " name" : self ._name ,
148+ " needs_prev_result" : self ._needs_prev_result ,
149+ " runs" : self ._runs ,
150+ " status" : self ._status ,
151+ " result" : self ._result ,
152+ " is_standalone" : self .is_standalone ,
152153 }
153154
154155 def to_list (self ):
155156 result = [self ._get_task_data ()]
156- result [0 ].update ({
157- 'prev' : self ._prev .id if self ._prev else None ,
158- 'next' : self ._next .id if self ._next else None ,
159- })
157+ result [0 ].update (
158+ {
159+ "prev" : self ._prev .id if self ._prev else None ,
160+ "next" : self ._next .id if self ._next else None ,
161+ }
162+ )
160163
161164 if self ._next :
162165 result .extend (self ._next .to_list ())
@@ -167,16 +170,16 @@ def to_list(self):
167170 def from_data (cls , task_data ):
168171 result = cls ()
169172
170- result .max_runs = task_data [' max_runs' ]
171- result ._runs = task_data [' runs' ]
172- result ._status = task_data [' status' ]
173- result ._result = task_data [' result' ]
174- result ._id = task_data ['id' ]
175- result ._name = task_data [' name' ]
176- result ._needs_prev_result = task_data [' needs_prev_result' ]
173+ result .max_runs = task_data [" max_runs" ]
174+ result ._runs = task_data [" runs" ]
175+ result ._status = task_data [" status" ]
176+ result ._result = task_data [" result" ]
177+ result ._id = task_data ["id" ]
178+ result ._name = task_data [" name" ]
179+ result ._needs_prev_result = task_data [" needs_prev_result" ]
177180
178- if task_data [' prev' ]:
179- task_data [' prev' ].then (result )
181+ if task_data [" prev" ]:
182+ task_data [" prev" ].then (result )
180183
181184 return result
182185
@@ -216,22 +219,19 @@ def run(self, **kwargs):
216219 self ._exc_info = sys .exc_info ()
217220
218221 def __str__ (self ):
219- return self ._name if self ._name else f' { function_to_string (self ._func )} :{ self ._args } '
222+ return self ._name if self ._name else f" { function_to_string (self ._func )} :{ self ._args } "
220223
221224 def _get_task_data (self ):
222225 result = super ()._get_task_data ()
223- result .update ({
224- 'func' : function_to_string (self ._func ),
225- 'args' : self ._args
226- })
226+ result .update ({"func" : function_to_string (self ._func ), "args" : self ._args })
227227
228228 return result
229229
230230 @classmethod
231231 def from_data (cls , task_data ):
232232 result = super ().from_data (task_data )
233- result ._func = function_from_string (task_data [' func' ])
234- result ._args = task_data [' args' ]
233+ result ._func = function_from_string (task_data [" func" ])
234+ result ._args = task_data [" args" ]
235235 return result
236236
237237 @classmethod
@@ -282,24 +282,22 @@ def get_all_tasks(self):
282282 return self ._sub_tasks [:]
283283
284284 def run (self , ** kwargs ):
285- raise RuntimeError (' Composite tasks cannot be run directly' )
285+ raise RuntimeError (" Composite tasks cannot be run directly" )
286286
287287 def to_list (self ):
288288 result = []
289289 for sub_task in self ._sub_tasks :
290290 result += sub_task .to_list ()
291291
292292 base_list = super ().to_list ()
293- base_list [0 ].update ({
294- 'sub_tasks' : [sub_task .id for sub_task in self ._sub_tasks ]
295- })
293+ base_list [0 ].update ({"sub_tasks" : [sub_task .id for sub_task in self ._sub_tasks ]})
296294
297295 return result + base_list
298296
299297 @classmethod
300298 def from_data (cls , task_data ):
301299 result = super ().from_data (task_data )
302- result ._sub_tasks = [sub_task .local_root for sub_task in task_data [' sub_tasks' ] or []]
300+ result ._sub_tasks = [sub_task .local_root for sub_task in task_data [" sub_tasks" ] or []]
303301 for sub_task in result ._sub_tasks :
304302 sub_task ._parent = result
305303
0 commit comments