@@ -244,10 +244,12 @@ def create_and_enqueue_job(
244
244
raise TypeError (f"Invalid type for when=`{ when } `" )
245
245
return job_model
246
246
247
- def job_handle_success (self , job : JobModel , result : Any , result_ttl : int , connection : ConnectionType ):
247
+ def job_handle_success (
248
+ self , job : JobModel , result : Any , job_info_ttl : int , result_ttl : int , connection : ConnectionType
249
+ ):
248
250
"""Saves and cleanup job after successful execution"""
249
251
job .after_execution (
250
- result_ttl ,
252
+ job_info_ttl ,
251
253
JobStatus .FINISHED ,
252
254
prev_registry = self .active_job_registry ,
253
255
new_registry = self .finished_job_registry ,
@@ -280,40 +282,26 @@ def job_handle_failure(self, status: JobStatus, job: JobModel, exc_string: str,
280
282
exc_string = exc_string ,
281
283
)
282
284
283
- def run_job (self , job : JobModel ) -> JobModel :
284
- """Run the job
285
- :param job: The job to run
286
- :returns: The job result
287
- """
285
+ def run_sync (self , job : JobModel ) -> JobModel :
286
+ """Run a job synchronously, meaning on the same process the method was called."""
287
+ job .prepare_for_execution ("sync" , self .active_job_registry , self .connection )
288
288
try :
289
289
result = perform_job (job , self .connection )
290
290
291
- result_ttl = job .success_ttl
292
291
with self .connection .pipeline () as pipeline :
293
- self .job_handle_success (job , result = result , result_ttl = result_ttl , connection = pipeline )
294
- job .expire (result_ttl , connection = pipeline )
292
+ self .job_handle_success (
293
+ job , result = result , job_info_ttl = job .job_info_ttl , result_ttl = job .success_ttl , connection = pipeline
294
+ )
295
+
295
296
pipeline .execute ()
296
- except Exception as e :
297
+ except Exception as e : # noqa
297
298
logger .warning (f"Job { job .name } failed with exception: { e } " )
298
299
with self .connection .pipeline () as pipeline :
299
300
exc_string = "" .join (traceback .format_exception (* sys .exc_info ()))
300
301
self .job_handle_failure (JobStatus .FAILED , job , exc_string , pipeline )
301
302
pipeline .execute ()
302
303
return job
303
304
304
- def run_sync (self , job : JobModel ) -> JobModel :
305
- """Run a job synchronously, meaning on the same process the method was called."""
306
- job .prepare_for_execution ("sync" , self .active_job_registry , self .connection )
307
-
308
- try :
309
- self .run_job (job )
310
- except : # noqa
311
- with self .connection .pipeline () as pipeline :
312
- exc_string = "" .join (traceback .format_exception (* sys .exc_info ()))
313
- self .job_handle_failure (JobStatus .FAILED , job , exc_string , pipeline )
314
- pipeline .execute ()
315
- return job
316
-
317
305
@classmethod
318
306
def dequeue_any (
319
307
cls ,
0 commit comments