File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change 1+ from django .db import transaction
2+
3+ from ..constants import HookLogStatus
14from ..models .hook import Hook
25from ..models .hook_log import HookLog
36from ..tasks import service_definition_task
@@ -19,9 +22,16 @@ def call_services(asset_uid: str, submission_id: int) -> bool:
1922 success = False
2023
2124 for hook_id in hooks_ids :
22- if not HookLog .objects .filter (
23- submission_id = submission_id , hook_id = hook_id
24- ).exists ():
25- success = True
26- service_definition_task .delay (hook_id , submission_id )
25+ with transaction .atomic ():
26+ # Create a pending log in case the celery task fails
27+ log , created = HookLog .objects .get_or_create (
28+ submission_id = submission_id ,
29+ hook_id = hook_id ,
30+ defaults = {'status' : HookLogStatus .PENDING .value },
31+ )
32+ if created :
33+ success = True
34+ transaction .on_commit (
35+ lambda : service_definition_task .delay (hook_id , submission_id )
36+ )
2737 return success
You can’t perform that action at this time.
0 commit comments