MCPcopy
hub / github.com/celery/celery / mark_as_failure

Method mark_as_failure

celery/backends/base.py:188–242  ·  view source on GitHub ↗

Mark task as executed with failure.

(self, task_id, exc,
                        traceback=None, request=None,
                        store_result=True, call_errbacks=True,
                        state=states.FAILURE)

Source from the content-addressed store, hash-verified

186 self.on_chord_part_return(request, state, result)
187
188 def mark_as_failure(self, task_id, exc,
189 traceback=None, request=None,
190 store_result=True, call_errbacks=True,
191 state=states.FAILURE):
192 """Mark task as executed with failure."""
193 if store_result:
194 self.store_result(task_id, exc, state,
195 traceback=traceback, request=request)
196 if request:
197 # This task may be part of a chord
198 if request.chord:
199 self.on_chord_part_return(request, state, exc)
200 # It might also have chained tasks which need to be propagated to,
201 # this is most likely to be exclusive with being a direct part of a
202 # chord but we'll handle both cases separately.
203 #
204 # The `chain_data` try block here is a bit tortured since we might
205 # have non-iterable objects here in tests and it's easier this way.
206 try:
207 chain_data = iter(request.chain)
208 except (AttributeError, TypeError):
209 chain_data = tuple()
210 for chain_elem in chain_data:
211 # Reconstruct a `Context` object for the chained task which has
212 # enough information to for backends to work with
213 chain_elem_ctx = Context(chain_elem)
214 chain_elem_ctx.update(chain_elem_ctx.options)
215 chain_elem_ctx.id = chain_elem_ctx.options.get('task_id')
216 chain_elem_ctx.group = chain_elem_ctx.options.get('group_id')
217 # If the state should be propagated, we'll do so for all
218 # elements of the chain. This is only truly important so
219 # that the last chain element which controls completion of
220 # the chain itself is marked as completed to avoid stalls.
221 #
222 # Some chained elements may be complex signatures and have no
223 # task ID of their own, so we skip them hoping that not
224 # descending through them is OK. If the last chain element is
225 # complex, we assume it must have been uplifted to a chord by
226 # the canvas code and therefore the condition below will ensure
227 # that we mark something as being complete as avoid stalling.
228 if (
229 store_result and state in states.PROPAGATE_STATES and
230 chain_elem_ctx.task_id is not None
231 ):
232 self.store_result(
233 chain_elem_ctx.task_id, exc, state,
234 traceback=traceback, request=chain_elem_ctx,
235 )
236 # If the chain element is a member of a chord, we also need
237 # to call `on_chord_part_return()` as well to avoid stalls.
238 if 'chord' in chain_elem_ctx.options:
239 self.on_chord_part_return(chain_elem_ctx, state, exc)
240 # And finally we'll fire any errbacks
241 if call_errbacks and request.errbacks:
242 self._call_task_errbacks(request, exc, traceback)
243
244 def _call_task_errbacks(self, request, exc, traceback):
245 old_signature = []

Calls 6

store_resultMethod · 0.95
on_chord_part_returnMethod · 0.95
updateMethod · 0.95
_call_task_errbacksMethod · 0.95
ContextClass · 0.90
getMethod · 0.45