@@ -114,11 +114,21 @@ def __init__(
114114 self .project = project
115115 self .event_id = event_id
116116
117- def _process (self , task_name : str , path : str , ** kwargs ):
117+ def _process (
118+ self ,
119+ task_name : str ,
120+ path : str ,
121+ kwargs_cb : Callable [[], dict [str , Any ]] | None = None ,
122+ ** kwargs : Any ,
123+ ) -> Any :
118124 """
119125 This function will submit a symbolication task to a Symbolicator and handle
120126 polling it using the `SymbolicatorSession`.
121127 It will also correctly handle `TaskIdNotFound` and `ServiceUnavailable` errors.
128+
129+ `kwargs_cb`, if provided, is called on every new task submission and its result
130+ is merged over `kwargs`. Use this for values that must be fresh on each
131+ (re)submission, such as expiring tokens.
122132 """
123133 session = SymbolicatorSession (
124134 url = self .base_url ,
@@ -137,7 +147,8 @@ def _process(self, task_name: str, path: str, **kwargs):
137147 try :
138148 if not task_id :
139149 # We are submitting a new task to Symbolicator
140- json_response = session .create_task (path , ** kwargs )
150+ create_kwargs = {** kwargs , ** (kwargs_cb () if kwargs_cb else {})}
151+ json_response = session .create_task (path , ** create_kwargs )
141152 else :
142153 # The task has already been submitted to Symbolicator and we are polling
143154 json_response = session .query_task (task_id )
@@ -201,7 +212,12 @@ def process_minidump(
201212 "rewrite_first_module" : rewrite_first_module ,
202213 },
203214 }
204- res = self ._process ("process_minidump" , "symbolicate-any" , json = json )
215+
216+ def cb () -> dict [str , Any ]:
217+ json ["symbolicate" ]["storage_token" ] = session .mint_token ()
218+ return {"json" : json }
219+
220+ res = self ._process ("process_minidump" , "symbolicate-any" , kwargs_cb = cb )
205221 return process_response (res )
206222
207223 data = {
@@ -233,7 +249,12 @@ def process_applecrashreport(self, platform: str, report: CachedAttachment):
233249 "storage_url" : storage_url ,
234250 },
235251 }
236- res = self ._process ("process_applecrashreport" , "symbolicate-any" , json = json )
252+
253+ def cb () -> dict [str , Any ]:
254+ json ["symbolicate" ]["storage_token" ] = session .mint_token ()
255+ return {"json" : json }
256+
257+ res = self ._process ("process_applecrashreport" , "symbolicate-any" , kwargs_cb = cb )
237258 return process_response (res )
238259
239260 data = {
0 commit comments