MCPcopy Create free account
hub / github.com/plotly/dash / job_fn

Function job_fn

dash/background_callback/managers/celery_manager.py:145–258  ·  view source on GitHub ↗
(
        result_key, progress_key, user_callback_args, context=None
    )

Source from the content-addressed store, hash-verified

143
144 @celery_app.task(name=f"background_callback_{key}")
145 def job_fn(
146 result_key, progress_key, user_callback_args, context=None
147 ): # pylint: disable=too-many-statements
148 def _set_progress(progress_value):
149 if not isinstance(progress_value, (list, tuple)):
150 progress_value = [progress_value]
151
152 cache.set(progress_key, json.dumps(progress_value, cls=PlotlyJSONEncoder))
153
154 maybe_progress = [_set_progress] if progress else []
155
156 def _set_props(_id, props):
157 cache.set(
158 f"{result_key}-set_props",
159 json.dumps({_id: props}, cls=PlotlyJSONEncoder),
160 )
161
162 ctx = copy_context()
163
164 def run():
165 c = AttributeDict(**context) # type: ignore[reportCallIssue]
166 c.ignore_register_page = False
167 c.updated_props = ProxySetProps(_set_props)
168 context_value.set(c)
169 errored = False
170 user_callback_output = None # to help type checking
171 try:
172 if isinstance(user_callback_args, dict):
173 user_callback_output = fn(*maybe_progress, **user_callback_args)
174 elif isinstance(user_callback_args, (list, tuple)):
175 user_callback_output = fn(*maybe_progress, *user_callback_args)
176 else:
177 user_callback_output = fn(*maybe_progress, user_callback_args)
178 except PreventUpdate:
179 # Put NoUpdate dict directly to avoid circular imports.
180 errored = True
181 cache.set(
182 result_key,
183 json.dumps(
184 {"_dash_no_update": "_dash_no_update"}, cls=PlotlyJSONEncoder
185 ),
186 )
187 except Exception as err: # pylint: disable=broad-except
188 errored = True
189 cache.set(
190 result_key,
191 json.dumps(
192 {
193 "background_callback_error": {
194 "msg": str(err),
195 "tb": traceback.format_exc(),
196 }
197 },
198 ),
199 )
200
201 if not errored:
202 cache.set(

Callers

nothing calls this directly

Calls 2

funcFunction · 0.85
runMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…