@@ -111,6 +111,74 @@ def add_with_task_args(self, a, b):
111111 create .assert_called_once_with ("new_name" , value_max = 10 , actions = actions , status = StatusEnum .PENDING )
112112
113113
114+ def test_celery_record_args (celery_session_app , celery_session_worker , bind_settings ):
115+ @celery_session_app .task (bind = True , base = Task )
116+ def add_with_task_args (self , a , b ):
117+ assert self .taskbadger_task is not None
118+ return a + b
119+
120+ celery_session_worker .reload ()
121+
122+ with (
123+ mock .patch ("taskbadger.celery.create_task_safe" ) as create ,
124+ mock .patch ("taskbadger.celery.update_task_safe" ),
125+ mock .patch ("taskbadger.celery.get_task" ),
126+ ):
127+ create .return_value = task_for_test ()
128+
129+ result = add_with_task_args .apply_async (
130+ (2 , 2 ),
131+ taskbadger_name = "new_name" ,
132+ taskbadger_value_max = 10 ,
133+ taskbadger_kwargs = {"data" : {"foo" : "bar" }},
134+ taskbadger_record_task_args = True ,
135+ )
136+ assert result .get (timeout = 10 , propagate = True ) == 4
137+
138+ create .assert_called_once_with (
139+ "new_name" ,
140+ value_max = 10 ,
141+ data = {"foo" : "bar" , "celery_task_args" : (2 , 2 ), "celery_task_kwargs" : {}},
142+ status = StatusEnum .PENDING ,
143+ )
144+
145+
146+ def test_celery_record_task_kwargs (celery_session_app , celery_session_worker , bind_settings ):
147+ @celery_session_app .task (bind = True , base = Task )
148+ def add_with_task_args (self , a , b , c = 0 ):
149+ assert self .taskbadger_task is not None
150+ return a + b + c
151+
152+ celery_session_worker .reload ()
153+
154+ with (
155+ mock .patch ("taskbadger.celery.create_task_safe" ) as create ,
156+ mock .patch ("taskbadger.celery.update_task_safe" ),
157+ mock .patch ("taskbadger.celery.get_task" ),
158+ ):
159+ create .return_value = task_for_test ()
160+
161+ actions = [Action ("stale" , integration = EmailIntegration (to = "test@test.com" ))]
162+ result = add_with_task_args .delay (
163+ 2 ,
164+ 2 ,
165+ c = 3 ,
166+ taskbadger_name = "new_name" ,
167+ taskbadger_value_max = 10 ,
168+ taskbadger_kwargs = {"actions" : actions },
169+ taskbadger_record_task_args = True ,
170+ )
171+ assert result .get (timeout = 10 , propagate = True ) == 7
172+
173+ create .assert_called_once_with (
174+ "new_name" ,
175+ value_max = 10 ,
176+ data = {"celery_task_args" : (2 , 2 ), "celery_task_kwargs" : {"c" : 3 }},
177+ actions = actions ,
178+ status = StatusEnum .PENDING ,
179+ )
180+
181+
114182def test_celery_task_with_args_in_decorator (celery_session_app , celery_session_worker , bind_settings ):
115183 @celery_session_app .task (
116184 bind = True ,
0 commit comments