@@ -235,12 +235,13 @@ def dispatch(
235235
236236 execute_now = immediate and not called_from_content_app ()
237237 assert deferred or immediate , "A task must be at least `deferred` or `immediate`."
238- send_wakeup_signal = True if not immediate else False
238+ send_wakeup_signal = not execute_now
239239 function_name = get_function_name (func )
240240 versions = get_version (versions , function_name )
241241 colliding_resources , resources = get_resources (exclusive_resources , shared_resources , immediate )
242+ app_lock = None if not execute_now else AppStatus .objects .current () # Lazy evaluation...
242243 task_payload = get_task_payload (
243- function_name , task_group , args , kwargs , resources , versions , immediate , deferred
244+ function_name , task_group , args , kwargs , resources , versions , immediate , deferred , app_lock
244245 )
245246 task = Task .objects .create (** task_payload )
246247 task .refresh_from_db () # The database will have assigned a timestamp for us.
@@ -278,9 +279,10 @@ async def adispatch(
278279 function_name = get_function_name (func )
279280 versions = get_version (versions , function_name )
280281 colliding_resources , resources = get_resources (exclusive_resources , shared_resources , immediate )
281- send_wakeup_signal = False
282+ send_wakeup_signal = not execute_now
283+ app_lock = None if not execute_now else AppStatus .objects .current () # Lazy evaluation...
282284 task_payload = get_task_payload (
283- function_name , task_group , args , kwargs , resources , versions , immediate , deferred
285+ function_name , task_group , args , kwargs , resources , versions , immediate , deferred , app_lock
284286 )
285287 task = await Task .objects .acreate (** task_payload )
286288 await task .arefresh_from_db () # The database will have assigned a timestamp for us.
@@ -302,7 +304,7 @@ async def adispatch(
302304
303305
304306def get_task_payload (
305- function_name , task_group , args , kwargs , resources , versions , immediate , deferred
307+ function_name , task_group , args , kwargs , resources , versions , immediate , deferred , app_lock
306308):
307309 payload = {
308310 "state" : TASK_STATES .WAITING ,
@@ -317,7 +319,7 @@ def get_task_payload(
317319 "immediate" : immediate ,
318320 "deferred" : deferred ,
319321 "profile_options" : x_task_diagnostics_var .get (None ),
320- "app_lock" : None if not immediate else AppStatus . objects . current (), # Lazy evaluation...
322+ "app_lock" : app_lock ,
321323 }
322324 return payload
323325
0 commit comments