Return a function that traces task execution. Catches all exceptions and updates result backend with the state and result. If the call was successful, it saves the result to the task result backend, and sets the task status to `"SUCCESS"`. If the call raises :exc:`~@Retry`, it
(name, task, loader=None, hostname=None, store_errors=True,
Info=TraceInfo, eager=False, propagate=False, app=None,
monotonic=time.monotonic, trace_ok_t=trace_ok_t,
IGNORE_STATES=IGNORE_STATES)
| 342 | |
| 343 | |
| 344 | def build_tracer(name, task, loader=None, hostname=None, store_errors=True, |
| 345 | Info=TraceInfo, eager=False, propagate=False, app=None, |
| 346 | monotonic=time.monotonic, trace_ok_t=trace_ok_t, |
| 347 | IGNORE_STATES=IGNORE_STATES): |
| 348 | """Return a function that traces task execution. |
| 349 | |
| 350 | Catches all exceptions and updates result backend with the |
| 351 | state and result. |
| 352 | |
| 353 | If the call was successful, it saves the result to the task result |
| 354 | backend, and sets the task status to `"SUCCESS"`. |
| 355 | |
| 356 | If the call raises :exc:`~@Retry`, it extracts |
| 357 | the original exception, uses that as the result and sets the task state |
| 358 | to `"RETRY"`. |
| 359 | |
| 360 | If the call results in an exception, it saves the exception as the task |
| 361 | result, and sets the task state to `"FAILURE"`. |
| 362 | |
| 363 | Return a function that takes the following arguments: |
| 364 | |
| 365 | :param uuid: The id of the task. |
| 366 | :param args: List of positional args to pass on to the function. |
| 367 | :param kwargs: Keyword arguments mapping to pass on to the function. |
| 368 | :keyword request: Request dict. |
| 369 | |
| 370 | """ |
| 371 | |
| 372 | # pylint: disable=too-many-statements |
| 373 | |
| 374 | # If the task doesn't define a custom __call__ method |
| 375 | # we optimize it away by simply calling the run method directly, |
| 376 | # saving the extra method call and a line less in the stack trace. |
| 377 | fun = task if task_has_custom(task, '__call__') else task.run |
| 378 | |
| 379 | loader = loader or app.loader |
| 380 | deduplicate_successful_tasks = ((app.conf.task_acks_late or task.acks_late) |
| 381 | and app.conf.worker_deduplicate_successful_tasks |
| 382 | and app.backend.persistent) |
| 383 | |
| 384 | hostname = hostname or gethostname() |
| 385 | inherit_parent_priority = app.conf.task_inherit_parent_priority |
| 386 | |
| 387 | loader_task_init = loader.on_task_init |
| 388 | loader_cleanup = loader.on_process_cleanup |
| 389 | |
| 390 | task_before_start = None |
| 391 | task_on_success = None |
| 392 | task_after_return = None |
| 393 | if task_has_custom(task, 'before_start'): |
| 394 | task_before_start = task.before_start |
| 395 | if task_has_custom(task, 'on_success'): |
| 396 | task_on_success = task.on_success |
| 397 | if task_has_custom(task, 'after_return'): |
| 398 | task_after_return = task.after_return |
| 399 | |
| 400 | pid = os.getpid() |
| 401 |