simple-module-background-tasks 0.0.41__tar.gz → 0.0.43__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/.gitignore +3 -0
  2. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/PKG-INFO +6 -6
  3. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/__init__.py +6 -0
  4. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/_signal_support.py +52 -19
  5. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/after_commit.py +13 -3
  6. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/celery_app.py +4 -1
  7. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/constants.py +6 -0
  8. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/api_status.py +26 -10
  9. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/log_context.py +12 -15
  10. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/models.py +11 -1
  11. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_dispatch.py +6 -2
  12. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/retry_service.py +16 -3
  13. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/settings.py +28 -0
  14. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/signals.py +26 -15
  15. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/sync_db.py +15 -0
  16. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/task_heartbeat.py +2 -1
  17. simple_module_background_tasks-0.0.43/background_tasks/task_resource.py +55 -0
  18. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/tasks.py +21 -4
  19. simple_module_background_tasks-0.0.43/background_tasks/tenant_celery.py +85 -0
  20. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/tenant_context.py +32 -24
  21. simple_module_background_tasks-0.0.43/background_tasks/tracking.py +55 -0
  22. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/package.json +5 -5
  23. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/pyproject.toml +6 -6
  24. simple_module_background_tasks-0.0.43/tests/test_background_tasks_argument_json.py +131 -0
  25. simple_module_background_tasks-0.0.43/tests/test_background_tasks_custom_bases.py +109 -0
  26. simple_module_background_tasks-0.0.43/tests/test_background_tasks_delivery_context.py +72 -0
  27. simple_module_background_tasks-0.0.43/tests/test_background_tasks_eager_bindings.py +65 -0
  28. simple_module_background_tasks-0.0.43/tests/test_background_tasks_execution_bindings.py +110 -0
  29. simple_module_background_tasks-0.0.43/tests/test_background_tasks_publish_validation.py +73 -0
  30. simple_module_background_tasks-0.0.43/tests/test_background_tasks_resource_status.py +145 -0
  31. simple_module_background_tasks-0.0.43/tests/test_background_tasks_resource_transport.py +129 -0
  32. simple_module_background_tasks-0.0.43/tests/test_background_tasks_result_json.py +80 -0
  33. simple_module_background_tasks-0.0.43/tests/test_background_tasks_retention_retries.py +87 -0
  34. simple_module_background_tasks-0.0.43/tests/test_background_tasks_savepoint_publish.py +54 -0
  35. simple_module_background_tasks-0.0.43/tests/test_background_tasks_tracking_modes.py +245 -0
  36. simple_module_background_tasks-0.0.43/tests/test_background_tasks_worker_tenancy.py +35 -0
  37. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_service.py +1 -0
  38. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_log_context.py +2 -2
  39. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_worker_tenancy.py +2 -1
  40. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/LICENSE +0 -0
  41. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/README.md +0 -0
  42. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/_lifecycle.py +0 -0
  43. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/_signal_bus.py +0 -0
  44. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/config_guards.py +0 -0
  45. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/contracts/__init__.py +0 -0
  46. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/contracts/events.py +0 -0
  47. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/contracts/logs.py +0 -0
  48. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/contracts/outbox.py +0 -0
  49. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/contracts/schemas.py +0 -0
  50. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/db_settings.py +0 -0
  51. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/deps.py +0 -0
  52. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/__init__.py +0 -0
  53. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/api_admin.py +0 -0
  54. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/logs_api.py +0 -0
  55. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/logs_views.py +0 -0
  56. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/outbox_api.py +0 -0
  57. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/outbox_views.py +0 -0
  58. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/views.py +0 -0
  59. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/filters.py +0 -0
  60. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/health.py +0 -0
  61. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/invalidation.py +0 -0
  62. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/locales/de.json +0 -0
  63. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/locales/en.json +0 -0
  64. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/log_purge.py +0 -0
  65. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/log_service.py +0 -0
  66. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/log_sink.py +0 -0
  67. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/module.py +0 -0
  68. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_claim.py +0 -0
  69. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_clock.py +0 -0
  70. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_guard.py +0 -0
  71. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_loop.py +0 -0
  72. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_service.py +0 -0
  73. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_support.py +0 -0
  74. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_sweep.py +0 -0
  75. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_transport.py +0 -0
  76. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_worker.py +0 -0
  77. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/Detail.tsx +0 -0
  78. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/Index.tsx +0 -0
  79. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/Logs.tsx +0 -0
  80. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/Outbox.tsx +0 -0
  81. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/Workers.tsx +0 -0
  82. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/api.generated.ts +0 -0
  83. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/api.ts +0 -0
  84. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/DetailFacts.tsx +0 -0
  85. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/ExecutionRow.tsx +0 -0
  86. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/ExecutionsTable.tsx +0 -0
  87. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/LogLevelSelect.tsx +0 -0
  88. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/LogTable.tsx +0 -0
  89. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/LogsPanel.tsx +0 -0
  90. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/OutboxTable.tsx +0 -0
  91. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/PayloadCards.tsx +0 -0
  92. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/ProgressCard.tsx +0 -0
  93. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/RetryAllDialog.tsx +0 -0
  94. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/RetryConfirmDialog.tsx +0 -0
  95. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/RoutesTable.tsx +0 -0
  96. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/StatusPill.tsx +0 -0
  97. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/StatusStrip.tsx +0 -0
  98. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/TaskFilters.tsx +0 -0
  99. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/TasksEmpty.tsx +0 -0
  100. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/TracebackCard.tsx +0 -0
  101. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/WorkerCard.tsx +0 -0
  102. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/WorkerEmptyStates.tsx +0 -0
  103. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/WorkerHealthBanner.tsx +0 -0
  104. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/constants.ts +0 -0
  105. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/logs.ts +0 -0
  106. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/outbox.ts +0 -0
  107. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/retry.ts +0 -0
  108. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/pages/worker-health.ts +0 -0
  109. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/py.typed +0 -0
  110. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/runner.py +0 -0
  111. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/service.py +0 -0
  112. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/services.py +0 -0
  113. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/settings_celery.py +0 -0
  114. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/settings_env_checks.py +0 -0
  115. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/settings_logs.py +0 -0
  116. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/task_routing.py +0 -0
  117. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/worker_inspector.py +0 -0
  118. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/worker_settings.py +0 -0
  119. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/background_tasks/workers_state.py +0 -0
  120. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/conftest.py +0 -0
  121. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_admin_api.py +0 -0
  122. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_background_tasks_after_commit.py +0 -0
  123. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_background_tasks_heartbeat.py +0 -0
  124. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_background_tasks_settings.py +0 -0
  125. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_background_tasks_tz_columns.py +0 -0
  126. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_beat_schedule.py +0 -0
  127. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_config_guards.py +0 -0
  128. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_db_timeouts.py +0 -0
  129. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_index_has_executions.py +0 -0
  130. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_index_worker_presence.py +0 -0
  131. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_inprocess_sweep.py +0 -0
  132. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_invalidation.py +0 -0
  133. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_invalidation_degraded.py +0 -0
  134. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_invalidation_redis.py +0 -0
  135. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_list_item_payload.py +0 -0
  136. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_log_api.py +0 -0
  137. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_log_purge.py +0 -0
  138. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_log_sink.py +0 -0
  139. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_log_sink_loop.py +0 -0
  140. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_log_sink_nul.py +0 -0
  141. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_eager_platform.py +0 -0
  142. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_eager_serialization.py +0 -0
  143. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_fence_guard.py +0 -0
  144. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_guard_savepoint.py +0 -0
  145. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_loop_interrupt.py +0 -0
  146. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_publish_scope.py +0 -0
  147. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_retry_policy.py +0 -0
  148. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_swallowed_cancel.py +0 -0
  149. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_thread_loops.py +0 -0
  150. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_worker_chain.py +0 -0
  151. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_page_clamp.py +0 -0
  152. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_pagination_bounds.py +0 -0
  153. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_quiet_sweep_unrecorded.py +0 -0
  154. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_redis_health.py +0 -0
  155. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_redis_url.py +0 -0
  156. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_routes_override_api.py +0 -0
  157. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_runner_settings.py +0 -0
  158. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_settings_env.py +0 -0
  159. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_startup_log_masking.py +0 -0
  160. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_task_progress.py +0 -0
  161. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_task_progress_audit.py +0 -0
  162. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_task_routing.py +0 -0
  163. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_task_status_api.py +0 -0
  164. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_users_ordering.py +0 -0
  165. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_worker_audit.py +0 -0
  166. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_worker_audit_bookkeeping.py +0 -0
  167. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_bg_worker_settings.py +0 -0
  168. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_detail_props.py +0 -0
  169. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_execution_tenancy.py +0 -0
  170. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_index_filters.py +0 -0
  171. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_outbox_admin.py +0 -0
  172. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_outbox_concurrency.py +0 -0
  173. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_outbox_delivery.py +0 -0
  174. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_outbox_tenancy.py +0 -0
  175. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_outbox_worker_task.py +0 -0
  176. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_retry_failed_bulk.py +0 -0
  177. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_retry_failed_guards.py +0 -0
  178. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_retry_sweep_ordering.py +0 -0
  179. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_signal_tenant_stamp.py +0 -0
  180. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_signals.py +0 -0
  181. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_sweep_stuck.py +0 -0
  182. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_sync_db.py +0 -0
  183. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_sync_db_fork.py +0 -0
  184. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_tenant_context.py +0 -0
  185. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_worker_inspector.py +0 -0
  186. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_workers_endpoints.py +0 -0
  187. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests/test_workers_uptime.py +0 -0
  188. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests-js/background_tasks_DetailPage.test.tsx +0 -0
  189. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests-js/background_tasks_IndexPage.test.tsx +0 -0
  190. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests-js/background_tasks_LogsTab.test.tsx +0 -0
  191. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests-js/background_tasks_OutboxPage.test.tsx +0 -0
  192. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests-js/background_tasks_WorkerHealthBanner.test.tsx +0 -0
  193. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests-js/outbox.test.ts +0 -0
  194. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests-js/retry.test.ts +0 -0
  195. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests-js/stub-fetch.ts +0 -0
  196. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tests-js/task-formatters.test.ts +0 -0
  197. {simple_module_background_tasks-0.0.41 → simple_module_background_tasks-0.0.43}/tsconfig.json +0 -0
@@ -22,6 +22,9 @@ node_modules/
22
22
 
23
23
  # Database
24
24
  *.db
25
+ *.db-wal
26
+ *.db-shm
27
+ *.db-journal
25
28
  *.sqlite3
26
29
 
27
30
  # Module-managed runtime state (e.g. uploaded dataset files,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: simple_module_background_tasks
3
- Version: 0.0.41
3
+ Version: 0.0.43
4
4
  Summary: Celery + Redis task queue with admin UI for monitoring and retrying failed/stuck tasks
5
5
  Project-URL: Homepage, https://github.com/antosubash/simple_module_python
6
6
  Project-URL: Repository, https://github.com/antosubash/simple_module_python
@@ -22,11 +22,11 @@ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
22
22
  Classifier: Typing :: Typed
23
23
  Requires-Python: >=3.12
24
24
  Requires-Dist: celery[redis]<6,>=5.4
25
- Requires-Dist: redis<7,>=5
26
- Requires-Dist: simple-module-core==0.0.41
27
- Requires-Dist: simple-module-db==0.0.41
28
- Requires-Dist: simple-module-hosting==0.0.41
29
- Requires-Dist: simple-module-settings==0.0.41
25
+ Requires-Dist: redis<9,>=5
26
+ Requires-Dist: simple-module-core==0.0.43
27
+ Requires-Dist: simple-module-db==0.0.43
28
+ Requires-Dist: simple-module-hosting==0.0.43
29
+ Requires-Dist: simple-module-settings==0.0.43
30
30
  Description-Content-Type: text/markdown
31
31
 
32
32
  # simple_module_background_tasks
@@ -3,11 +3,14 @@
3
3
  from typing import TYPE_CHECKING, Any
4
4
 
5
5
  from background_tasks.after_commit import enqueue_after_commit
6
+ from background_tasks.constants import SM_TRACKING_HEADER
6
7
  from background_tasks.log_context import (
7
8
  bind_task_context,
8
9
  get_log_context,
9
10
  install_log_filter,
10
11
  )
12
+ from background_tasks.task_resource import with_task_resource
13
+ from background_tasks.tracking import TrackingMode
11
14
 
12
15
  if TYPE_CHECKING:
13
16
  from background_tasks.task_heartbeat import heartbeat
@@ -30,10 +33,13 @@ def __getattr__(name: str) -> Any:
30
33
 
31
34
 
32
35
  __all__ = [
36
+ "SM_TRACKING_HEADER",
37
+ "TrackingMode",
33
38
  "bind_task_context",
34
39
  "enqueue_after_commit",
35
40
  "get_log_context",
36
41
  "heartbeat",
37
42
  "install_log_filter",
38
43
  "settings_for",
44
+ "with_task_resource",
39
45
  ]
@@ -7,19 +7,24 @@ These helpers are intentionally side-effect-free except for the DB write in
7
7
 
8
8
  from __future__ import annotations
9
9
 
10
+ import json
10
11
  import logging
11
12
  import traceback as tb_mod
12
13
  from collections.abc import Callable
13
14
  from datetime import UTC, datetime
14
15
  from typing import Any
15
16
 
17
+ from celery import current_app
18
+ from kombu.utils.json import dumps
16
19
  from sqlalchemy import select
17
20
  from sqlalchemy.orm import Session
18
21
  from sqlmodel import col
19
22
 
20
- from background_tasks.constants import INTERNAL_TASK_SWEEP_OUTBOX, TaskStatus
21
23
  from background_tasks.models import TaskExecution
22
24
  from background_tasks.sync_db import sync_session
25
+ from background_tasks.task_resource import message_resource
26
+ from background_tasks.tenant_context import message_owner
27
+ from background_tasks.tracking import records_signal, tracking_mode
23
28
 
24
29
  logger = logging.getLogger(__name__)
25
30
 
@@ -31,12 +36,12 @@ def now_utc() -> datetime:
31
36
  def coerce_args_kwargs(args: Any, kwargs: Any) -> tuple[list[Any], dict[str, Any]]:
32
37
  """Normalise Celery args/kwargs payloads to JSON-ready shapes.
33
38
 
34
- Celery sometimes hands us tuples/frozensets that our JSON column can't
35
- store; also tolerates ``None`` so a partial payload won't wedge the row.
39
+ Keep Kombu type envelopes in SQL JSON columns; retry decodes them.
40
+ Tolerate ``None`` so a partial payload does not wedge the row.
36
41
  """
37
42
  safe_args: list[Any] = list(args) if args else []
38
43
  safe_kwargs: dict[str, Any] = dict(kwargs) if kwargs else {}
39
- return safe_args, safe_kwargs
44
+ return json.loads(dumps(safe_args)), json.loads(dumps(safe_kwargs))
40
45
 
41
46
 
42
47
  def upsert_by_celery_id(
@@ -94,12 +99,26 @@ def jsonable_result(result: Any) -> dict[str, Any] | None:
94
99
  """Wrap arbitrary task results in a JSON-storable shape."""
95
100
  if result is None:
96
101
  return None
97
- if isinstance(result, dict):
98
- return result
99
102
  try:
100
- return {"value": result}
103
+ # Plain json.loads keeps Kombu's type envelopes JSON-safe for the DB.
104
+ # NaN/Infinity encode fine but Postgres' json type rejects them, which
105
+ # would roll the success write back like the datetime case did.
106
+ text = dumps(result if isinstance(result, dict) else {"value": result})
107
+ if "\\u0000" in text:
108
+ # PostgreSQL's json/jsonb types reject NUL escapes in strings.
109
+ raise ValueError("NUL character in result")
110
+ return json.loads(text, parse_constant=_reject_constant)
101
111
  except Exception:
102
- return {"value": repr(result)}
112
+ # Result tracking must never undo a task's success (RecursionError,
113
+ # a failing ``__json__`` hook, ... included).
114
+ try:
115
+ return {"value": repr(result)}
116
+ except Exception:
117
+ return {"value": f"<unrepresentable {type(result).__name__}>"}
118
+
119
+
120
+ def _reject_constant(name: str) -> Any:
121
+ raise ValueError(f"non-finite JSON constant {name}")
103
122
 
104
123
 
105
124
  def render_traceback(einfo: Any, exception: BaseException | None) -> str | None:
@@ -112,13 +131,6 @@ def render_traceback(einfo: Any, exception: BaseException | None) -> str | None:
112
131
  return None
113
132
 
114
133
 
115
- # Beat ticks that fire every few seconds and are a no-op almost every time;
116
- # recording each run buried real work (QA, GH #459). Only a run that went wrong
117
- # is worth a row.
118
- _UNRECORDED_WHEN_QUIET = frozenset({INTERNAL_TASK_SWEEP_OUTBOX})
119
- _QUIET_STATUSES = frozenset({None, TaskStatus.PENDING, TaskStatus.RUNNING, TaskStatus.SUCCESS})
120
-
121
-
122
134
  def apply_signal(
123
135
  handler: str,
124
136
  *,
@@ -127,6 +139,9 @@ def apply_signal(
127
139
  after: Callable[[TaskExecution], None] | None = None,
128
140
  tenant_id: str | None = None,
129
141
  owner_user_id: str | None = None,
142
+ task: Any = None,
143
+ request: Any = None,
144
+ headers: dict | None = None,
130
145
  ) -> TaskExecution | None:
131
146
  """Open a sync session, upsert by celery_task_id, log on failure.
132
147
 
@@ -136,12 +151,30 @@ def apply_signal(
136
151
  ``tenant_id`` and ``owner_user_id`` (the message's) are written only when
137
152
  known, so a signal whose message carries neither never blanks a row already
138
153
  stamped.
154
+
155
+ The task's tracking mode (:mod:`.tracking`) decides first whether this
156
+ signal is recorded at all. When it is, the row also takes args, kwargs,
157
+ queue, owner and resource from the message when ``defaults`` lack them, so
158
+ a worker can create the row itself when the publisher never did.
139
159
  """
140
- if (
141
- defaults.get("task_name") in _UNRECORDED_WHEN_QUIET
142
- and defaults.get("status") in _QUIET_STATUSES
143
- ):
160
+ name = defaults.get("task_name", "")
161
+ mode = tracking_mode(task=task, request=request, headers=headers, name=name)
162
+ app = getattr(task, "app", None) or current_app
163
+ if not records_signal(mode, handler, defaults.get("status"), app=app):
144
164
  return None
165
+ request = request if request is not None else getattr(task, "request", None)
166
+ if request is not None:
167
+ metadata = {}
168
+ if getattr(request, "args", None) is not None:
169
+ metadata["args"] = coerce_args_kwargs(request.args, None)[0]
170
+ if getattr(request, "kwargs", None) is not None:
171
+ metadata["kwargs"] = coerce_args_kwargs(None, request.kwargs)[1]
172
+ delivery = getattr(request, "delivery_info", None) or {}
173
+ if delivery.get("routing_key"):
174
+ metadata["queue"] = delivery["routing_key"]
175
+ defaults = {**metadata, **defaults}
176
+ owner_user_id = owner_user_id or message_owner(request=request)
177
+ defaults = {**message_resource(headers=headers, request=request), **defaults}
145
178
  if tenant_id:
146
179
  defaults = {**defaults, "tenant_id": tenant_id}
147
180
  if owner_user_id:
@@ -15,7 +15,7 @@ Two delivery paths, picked per session:
15
15
  - **Any other session** — a worker's sync session, a CLI script's own
16
16
  ``async with session.begin()`` — has nobody to run ``on_commit`` callbacks,
17
17
  so the publish hangs off SQLAlchemy's ``after_commit`` event instead and is
18
- dropped when the outermost transaction ends without committing.
18
+ dropped when its savepoint or the outermost transaction rolls back.
19
19
 
20
20
  The broker id is reserved up front and returned, so the caller can write it
21
21
  onto its own row in the same transaction: the row names the task before the
@@ -31,6 +31,7 @@ from collections.abc import Callable, Sequence
31
31
  from typing import Any
32
32
 
33
33
  from simple_module_db import RequestSession, bind_current_tenant, mark_written
34
+ from simple_module_db.callbacks import open_savepoints
34
35
  from simple_module_db.transaction import SESSION_START_KEY
35
36
  from sqlalchemy import event
36
37
  from sqlalchemy.ext.asyncio import AsyncSession
@@ -108,7 +109,8 @@ def after_commit(
108
109
  db.on_commit(lambda: _run_all(batch))
109
110
  return
110
111
  sync = db.sync_session if isinstance(db, AsyncSession) else db
111
- sync.info.setdefault(_PENDING_KEY, []).extend(batch)
112
+ savepoints = open_savepoints(sync)
113
+ sync.info.setdefault(_PENDING_KEY, []).extend((savepoints, publish) for publish in batch)
112
114
  _hook(sync)
113
115
 
114
116
 
@@ -127,7 +129,14 @@ def _hook(session: Session) -> None:
127
129
  session.info[_HOOKED_KEY] = True
128
130
 
129
131
  def on_commit(sess: Session) -> None:
130
- _run_all(sess.info.pop(_PENDING_KEY, []))
132
+ if not sess.in_nested_transaction():
133
+ _run_all([publish for _, publish in sess.info.pop(_PENDING_KEY, [])])
134
+
135
+ def on_rollback(sess: Session, transaction: SessionTransaction) -> None:
136
+ if transaction.nested and _PENDING_KEY in sess.info:
137
+ sess.info[_PENDING_KEY] = [
138
+ entry for entry in sess.info[_PENDING_KEY] if transaction not in entry[0]
139
+ ]
131
140
 
132
141
  def on_end(sess: Session, transaction: SessionTransaction) -> None:
133
142
  # ``after_commit`` already took the batch on the commit path; anything
@@ -136,6 +145,7 @@ def _hook(session: Session) -> None:
136
145
  sess.info.pop(_PENDING_KEY, None)
137
146
 
138
147
  event.listen(session, "after_commit", on_commit)
148
+ event.listen(session, "after_soft_rollback", on_rollback)
139
149
  event.listen(session, "after_transaction_end", on_end)
140
150
 
141
151
 
@@ -35,6 +35,7 @@ from background_tasks.constants import (
35
35
  )
36
36
  from background_tasks.settings import BackgroundTasksSettings
37
37
  from background_tasks.task_routing import load_task_configs, merge_routes, select_packages
38
+ from background_tasks.tenant_celery import TenantCelery
38
39
 
39
40
  logger = logging.getLogger(__name__)
40
41
 
@@ -126,7 +127,7 @@ def describe_routes(settings: BackgroundTasksSettings) -> list[dict[str, str]]:
126
127
 
127
128
  def build_celery(settings: BackgroundTasksSettings) -> Celery:
128
129
  """Construct a Celery app wired to the project's Redis broker."""
129
- celery = Celery(MODULE_NAME)
130
+ celery = TenantCelery(MODULE_NAME)
130
131
 
131
132
  all_packages = _discover_task_packages()
132
133
  # Routes and beat entries come from the light ``task_config`` of *every*
@@ -174,6 +175,8 @@ def build_celery(settings: BackgroundTasksSettings) -> Celery:
174
175
  beat_schedule[name] = entry
175
176
 
176
177
  celery.conf.update(
178
+ sm_execution_tracking=settings.execution_tracking,
179
+ sm_track_publish=settings.track_publish,
177
180
  broker_url=settings.broker_url,
178
181
  result_backend=settings.result_backend,
179
182
  task_default_queue=settings.task_default_queue,
@@ -199,3 +199,9 @@ DEFAULT_LOG_RETENTION_DAYS = 7
199
199
  LOG_PER_PAGE = 50
200
200
  # Level names the admin filter offers, lowest first.
201
201
  LOG_LEVEL_NAMES = ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL")
202
+
203
+ # Message metadata shared by publishers and workers.
204
+ SM_TRACKING_HEADER = "sm_tracking"
205
+ SM_RESOURCE_TYPE_HEADER = "sm_resource_type"
206
+ SM_RESOURCE_ID_HEADER = "sm_resource_id"
207
+ RESOURCE_REF_MAX_LENGTH = 255
@@ -1,8 +1,8 @@
1
- """Owner-scoped task status (#536).
1
+ """Owner- and resource-scoped task status (#536, #709).
2
2
 
3
3
  Mounted apart from the admin router because it carries no ``PERM_VIEW`` gate:
4
- the person who started a job may follow it without being a task operator. It
5
- is marked ``Authenticated()`` (SM031); the ownership check lives in the
4
+ owners and resource viewers may follow a job without being task operators. It
5
+ is marked ``Authenticated()`` (SM031); the visibility check lives in the
6
6
  handler, and every refusal is a 404 so the route does not reveal which task
7
7
  ids exist.
8
8
  """
@@ -13,9 +13,12 @@ import re
13
13
 
14
14
  from fastapi import APIRouter, Depends, HTTPException, Request
15
15
  from simple_module_core.permissions import grants
16
+ from simple_module_core.resources import ACTION_VIEW
16
17
  from simple_module_db import RequestSession, current_tenant_id
17
18
  from simple_module_db.deps import get_db
19
+ from simple_module_db.resource_policy import load_authorized
18
20
  from simple_module_hosting.permissions import ensure_resolved_permissions
21
+ from simple_module_hosting.resource_deps import resource_principal
19
22
  from simple_module_hosting.token_guard import Authenticated
20
23
  from sqlalchemy import select
21
24
  from sqlmodel import col
@@ -30,15 +33,28 @@ _TYPE_NAME = re.compile(r"[A-Za-z_][A-Za-z0-9_.]{0,254}")
30
33
  _NOT_FOUND = "Task not found"
31
34
 
32
35
 
33
- async def _visible(request: Request, row: TaskExecution, user_id: str) -> bool:
36
+ async def _visible(request: Request, row: TaskExecution, user_id: str, db: RequestSession) -> bool:
34
37
  if grants(await ensure_resolved_permissions(request), PERM_VIEW):
35
38
  return True
36
- if not row.owner_user_id or row.owner_user_id != user_id:
37
- return False
38
- if not bool(getattr(request.app.state.sm.settings, "multi_tenant", False)):
39
+ if bool(getattr(request.app.state.sm.settings, "multi_tenant", False)):
40
+ tenant_id = current_tenant_id.get()
41
+ if tenant_id is None or row.tenant_id != tenant_id:
42
+ return False
43
+ if row.owner_user_id and row.owner_user_id == user_id:
39
44
  return True
40
- tenant_id = current_tenant_id.get()
41
- return tenant_id is not None and row.tenant_id == tenant_id
45
+ if not row.resource_type or not row.resource_id:
46
+ return False
47
+ resource = request.app.state.sm.resource_types.get(row.resource_type)
48
+ if resource is None:
49
+ return False
50
+ try:
51
+ stmt = resource.select_by_id(row.resource_id)
52
+ except ValueError:
53
+ return False
54
+ obj, allowed = await load_authorized(
55
+ db, resource.policy, await resource_principal(request), ACTION_VIEW, stmt
56
+ )
57
+ return obj is not None and allowed
42
58
 
43
59
 
44
60
  @router.get(
@@ -62,7 +78,7 @@ async def get_task_status(
62
78
  .limit(1)
63
79
  )
64
80
  ).scalar_one_or_none()
65
- if row is None or not await _visible(request, row, str(user.id)):
81
+ if row is None or not await _visible(request, row, str(user.id), db):
66
82
  raise HTTPException(status_code=404, detail=_NOT_FOUND)
67
83
  error = row.exception_type
68
84
  if error and not _TYPE_NAME.fullmatch(error):
@@ -32,12 +32,10 @@ _RESERVED_RECORD_KEYS: frozenset[str] = frozenset(logging.makeLogRecord({}).__di
32
32
  "asctime",
33
33
  }
34
34
 
35
- # Pairs ``task_prerun`` → ``task_postrun`` across signal calls. Keyed by
36
- # Celery task UUID so threaded / gevent pools — which can interleave
37
- # prerun/postrun pairs within one process — stay isolated.
38
- _signal_tokens: dict[str, Token[Mapping[str, Any]]] = {}
39
-
40
- _log = logging.getLogger(__name__)
35
+ # Immutable stacks keep overlapping UUIDs and nested eager executions isolated.
36
+ _signal_tokens: ContextVar[tuple[tuple[str, Token[Mapping[str, Any]]], ...]] = ContextVar(
37
+ "sm_log_signal_tokens", default=()
38
+ )
41
39
 
42
40
 
43
41
  def get_log_context() -> dict[str, Any]:
@@ -104,20 +102,19 @@ def signal_task_started(*, task_id: str | None, task_name: str | None) -> None:
104
102
  if not task_id:
105
103
  return
106
104
  merged = {**current_log_context.get(), "task_id": task_id, "task_name": task_name}
107
- _signal_tokens[task_id] = current_log_context.set(merged)
105
+ _signal_tokens.set((*_signal_tokens.get(), (task_id, current_log_context.set(merged))))
108
106
 
109
107
 
110
108
  def signal_task_finished(*, task_id: str | None) -> None:
111
109
  """Reset the binding from :func:`signal_task_started`."""
112
- if not task_id:
113
- return
114
- token = _signal_tokens.pop(task_id, None)
115
- if token is None:
110
+ stack = _signal_tokens.get()
111
+ ids = [entry[0] for entry in stack]
112
+ if task_id not in ids:
116
113
  return
114
+ depth = len(ids) - 1 - ids[::-1].index(task_id)
115
+ _, token = stack[depth]
116
+ _signal_tokens.set(stack[:depth])
117
117
  try:
118
118
  current_log_context.reset(token)
119
119
  except ValueError:
120
- # Token belongs to a different context — possible under exotic
121
- # eventlet patching. The var falls back when the task's context
122
- # exits, so the leak is bounded.
123
- _log.debug("Log-context reset skipped for task_id=%s", task_id)
120
+ current_log_context.set({})
@@ -9,7 +9,7 @@ from typing import Any, ClassVar
9
9
  from simple_module_db.base import create_module_base
10
10
  from simple_module_db.mixins import AuditMixin
11
11
  from simple_module_db.types import AwareDateTime
12
- from sqlalchemy import JSON, Column, Index, String
12
+ from sqlalchemy import JSON, CheckConstraint, Column, Index, String
13
13
  from sqlmodel import Field
14
14
 
15
15
  from background_tasks.constants import (
@@ -22,6 +22,7 @@ from background_tasks.constants import (
22
22
  OWNER_ID_MAX_LENGTH,
23
23
  PROGRESS_MESSAGE_MAX_LENGTH,
24
24
  PROGRESS_PHASE_MAX_LENGTH,
25
+ RESOURCE_REF_MAX_LENGTH,
25
26
  TABLE_LOG_RECORD,
26
27
  TABLE_OUTBOX,
27
28
  TABLE_TASK_EXECUTION,
@@ -86,6 +87,11 @@ class TaskExecution(Base, AuditMixin, table=True): # ty: ignore[unsupported-bas
86
87
  # publishes. It scopes who may read the task's status (#536).
87
88
  owner_user_id: str | None = Field(default=None, index=True, max_length=OWNER_ID_MAX_LENGTH)
88
89
 
90
+ # Optional resource this task is about (#709); lets viewers of that resource
91
+ # read the task's status. Both set or both null (check constraint below).
92
+ resource_type: str | None = Field(default=None, max_length=RESOURCE_REF_MAX_LENGTH)
93
+ resource_id: str | None = Field(default=None, max_length=RESOURCE_REF_MAX_LENGTH)
94
+
89
95
  # Progress the task body reports through ``heartbeat(progress=...)``.
90
96
  progress_current: int | None = None
91
97
  progress_total: int | None = None
@@ -118,6 +124,10 @@ class TaskExecution(Base, AuditMixin, table=True): # ty: ignore[unsupported-bas
118
124
  heartbeat_at: datetime | None = None
119
125
 
120
126
  __table_args__ = (
127
+ CheckConstraint(
128
+ "(resource_type IS NULL) = (resource_id IS NULL)",
129
+ name="task_resource_pair",
130
+ ),
121
131
  Index(
122
132
  "ix_background_tasks_task_execution_status_queued",
123
133
  "status",
@@ -41,7 +41,7 @@ from collections.abc import Sequence
41
41
  from datetime import datetime, timedelta
42
42
  from typing import Any
43
43
 
44
- from simple_module_core.durable_events import DurableContext, deserialize_event
44
+ from simple_module_core.durable_events import IN_DELIVERY, DurableContext, deserialize_event
45
45
  from simple_module_core.events import EventBus
46
46
  from simple_module_db import is_valid_tenant_id
47
47
  from simple_module_db.callbacks import discard_on_commit_callbacks, run_on_commit_callbacks
@@ -166,7 +166,11 @@ async def deliver_one(
166
166
  async with deadline:
167
167
  with handler_guard(session):
168
168
  ctx = DurableContext(db=session, attempt=row.attempts)
169
- await sub.handler(event, ctx)
169
+ token = IN_DELIVERY.set(True)
170
+ try:
171
+ await sub.handler(event, ctx)
172
+ finally:
173
+ IN_DELIVERY.reset(token)
170
174
  except TimeoutError as exc:
171
175
  if not deadline.expired():
172
176
  raise # the handler's own timeout, not ours
@@ -8,11 +8,13 @@ must not happen twice. The read paths have none of those questions.
8
8
 
9
9
  from __future__ import annotations
10
10
 
11
+ import json
11
12
  import logging
12
13
  import uuid
13
14
  from collections.abc import Callable, Sequence
14
15
  from typing import TYPE_CHECKING, Any
15
16
 
17
+ from kombu.utils.json import loads
16
18
  from simple_module_core.events import EventBus
17
19
  from simple_module_db import RequestSession, all_tenants, tenant_context
18
20
  from sqlalchemy import Select, func, select, update
@@ -20,13 +22,15 @@ from sqlmodel import col
20
22
 
21
23
  from background_tasks._signal_support import now_utc
22
24
  from background_tasks.after_commit import after_commit
23
- from background_tasks.constants import RETRY_ALL_BATCH, TaskStatus
25
+ from background_tasks.constants import RETRY_ALL_BATCH, SM_TRACKING_HEADER, TaskStatus
24
26
  from background_tasks.contracts.events import TaskRetried
25
27
  from background_tasks.contracts.schemas import RetryFailedResult
26
28
  from background_tasks.filters import Conditions, bulk_retry_conditions
27
29
  from background_tasks.models import TaskExecution
28
30
  from background_tasks.sync_db import sync_session
31
+ from background_tasks.task_resource import resource_headers
29
32
  from background_tasks.tenant_context import publish_as_owner
33
+ from background_tasks.tracking import TrackingMode
30
34
 
31
35
  if TYPE_CHECKING:
32
36
  from celery import Celery
@@ -190,12 +194,19 @@ class RetryCoordinator:
190
194
  tenant_id = row.tenant_id
191
195
  owner_user_id = row.owner_user_id
192
196
  options: dict[str, Any] = {
193
- "args": list(row.args or []),
194
- "kwargs": dict(row.kwargs or {}),
197
+ "args": loads(json.dumps(row.args or [])),
198
+ "kwargs": loads(json.dumps(row.kwargs or {})),
195
199
  "queue": row.queue,
196
200
  "task_id": task_id,
197
201
  }
198
202
 
203
+ # The retry already reserved a ``pending`` row; a reduced tracking
204
+ # mode would never move it on, so an operator's retry is tracked fully.
205
+ headers: dict[str, str] = {SM_TRACKING_HEADER: TrackingMode.FULL.value}
206
+ if row.resource_type and row.resource_id:
207
+ headers.update(resource_headers(row.resource_type, row.resource_id))
208
+ options["headers"] = headers
209
+
199
210
  def publish() -> str:
200
211
  try:
201
212
  return _send()
@@ -233,6 +244,8 @@ class RetryCoordinator:
233
244
  queue=row.queue,
234
245
  tenant_id=row.tenant_id,
235
246
  owner_user_id=row.owner_user_id,
247
+ resource_type=row.resource_type,
248
+ resource_id=row.resource_id,
236
249
  args=list(row.args or []),
237
250
  kwargs=dict(row.kwargs or {}),
238
251
  retried_from_id=row.id,
@@ -53,6 +53,7 @@ from background_tasks.settings_env_checks import (
53
53
  forbid_localhost_broker_in_production,
54
54
  warn_on_legacy_redis_vars,
55
55
  )
56
+ from background_tasks.tracking import TrackingMode
56
57
 
57
58
  __all__ = ["DEFAULT_RETENTION_DAYS", "ENV_PREFIX", "BackgroundTasksSettings"]
58
59
 
@@ -62,6 +63,33 @@ logger = logging.getLogger(__name__)
62
63
  class BackgroundTasksSettings(CelerySettingsFields):
63
64
  """Configuration for the Celery + Redis task runner."""
64
65
 
66
+ execution_tracking: TrackingMode = Field(
67
+ default=TrackingMode.FULL, json_schema_extra=_CELERY_RESTART
68
+ )
69
+ track_publish: bool = Field(default=True, json_schema_extra=_CELERY_RESTART)
70
+
71
+ @classmethod
72
+ def settings_customise_sources(
73
+ cls, settings_cls, init_settings, env_settings, dotenv_settings, file_secret_settings
74
+ ):
75
+ # Tracking controls are DB-backed; preserve env wiring for older fields.
76
+ def db_only(source):
77
+ def read():
78
+ return {
79
+ k: v
80
+ for k, v in source().items()
81
+ if k not in {"execution_tracking", "track_publish"}
82
+ }
83
+
84
+ return read
85
+
86
+ return (
87
+ init_settings,
88
+ db_only(env_settings),
89
+ db_only(dotenv_settings),
90
+ db_only(file_secret_settings),
91
+ )
92
+
65
93
  # ── Durable event outbox (GH #459) ──────────────────────
66
94
  outbox_mode: Literal["celery", "inprocess"] = Field(
67
95
  default="celery", json_schema_extra=_CELERY_RESTART