simple-module-background-tasks 0.0.42__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.42 → simple_module_background_tasks-0.0.43}/.gitignore +3 -0
  2. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/PKG-INFO +6 -6
  3. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/_signal_support.py +25 -9
  4. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/after_commit.py +13 -3
  5. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/celery_app.py +2 -1
  6. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/log_context.py +12 -15
  7. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/retry_service.py +4 -2
  8. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/signals.py +4 -2
  9. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/tasks.py +19 -3
  10. simple_module_background_tasks-0.0.43/background_tasks/tenant_celery.py +85 -0
  11. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/tenant_context.py +27 -21
  12. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/package.json +1 -1
  13. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/pyproject.toml +6 -6
  14. simple_module_background_tasks-0.0.43/tests/test_background_tasks_argument_json.py +131 -0
  15. simple_module_background_tasks-0.0.43/tests/test_background_tasks_custom_bases.py +109 -0
  16. simple_module_background_tasks-0.0.43/tests/test_background_tasks_eager_bindings.py +65 -0
  17. simple_module_background_tasks-0.0.43/tests/test_background_tasks_execution_bindings.py +110 -0
  18. simple_module_background_tasks-0.0.43/tests/test_background_tasks_publish_validation.py +73 -0
  19. simple_module_background_tasks-0.0.43/tests/test_background_tasks_result_json.py +80 -0
  20. simple_module_background_tasks-0.0.43/tests/test_background_tasks_retention_retries.py +87 -0
  21. simple_module_background_tasks-0.0.43/tests/test_background_tasks_savepoint_publish.py +54 -0
  22. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_log_context.py +2 -2
  23. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_worker_tenancy.py +2 -1
  24. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/LICENSE +0 -0
  25. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/README.md +0 -0
  26. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/__init__.py +0 -0
  27. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/_lifecycle.py +0 -0
  28. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/_signal_bus.py +0 -0
  29. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/config_guards.py +0 -0
  30. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/constants.py +0 -0
  31. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/contracts/__init__.py +0 -0
  32. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/contracts/events.py +0 -0
  33. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/contracts/logs.py +0 -0
  34. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/contracts/outbox.py +0 -0
  35. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/contracts/schemas.py +0 -0
  36. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/db_settings.py +0 -0
  37. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/deps.py +0 -0
  38. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/__init__.py +0 -0
  39. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/api_admin.py +0 -0
  40. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/api_status.py +0 -0
  41. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/logs_api.py +0 -0
  42. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/logs_views.py +0 -0
  43. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/outbox_api.py +0 -0
  44. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/outbox_views.py +0 -0
  45. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/endpoints/views.py +0 -0
  46. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/filters.py +0 -0
  47. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/health.py +0 -0
  48. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/invalidation.py +0 -0
  49. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/locales/de.json +0 -0
  50. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/locales/en.json +0 -0
  51. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/log_purge.py +0 -0
  52. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/log_service.py +0 -0
  53. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/log_sink.py +0 -0
  54. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/models.py +0 -0
  55. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/module.py +0 -0
  56. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_claim.py +0 -0
  57. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_clock.py +0 -0
  58. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_dispatch.py +0 -0
  59. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_guard.py +0 -0
  60. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_loop.py +0 -0
  61. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_service.py +0 -0
  62. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_support.py +0 -0
  63. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_sweep.py +0 -0
  64. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_transport.py +0 -0
  65. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/outbox_worker.py +0 -0
  66. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/Detail.tsx +0 -0
  67. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/Index.tsx +0 -0
  68. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/Logs.tsx +0 -0
  69. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/Outbox.tsx +0 -0
  70. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/Workers.tsx +0 -0
  71. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/api.generated.ts +0 -0
  72. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/api.ts +0 -0
  73. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/DetailFacts.tsx +0 -0
  74. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/ExecutionRow.tsx +0 -0
  75. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/ExecutionsTable.tsx +0 -0
  76. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/LogLevelSelect.tsx +0 -0
  77. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/LogTable.tsx +0 -0
  78. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/LogsPanel.tsx +0 -0
  79. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/OutboxTable.tsx +0 -0
  80. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/PayloadCards.tsx +0 -0
  81. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/ProgressCard.tsx +0 -0
  82. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/RetryAllDialog.tsx +0 -0
  83. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/RetryConfirmDialog.tsx +0 -0
  84. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/RoutesTable.tsx +0 -0
  85. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/StatusPill.tsx +0 -0
  86. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/StatusStrip.tsx +0 -0
  87. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/TaskFilters.tsx +0 -0
  88. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/TasksEmpty.tsx +0 -0
  89. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/TracebackCard.tsx +0 -0
  90. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/WorkerCard.tsx +0 -0
  91. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/WorkerEmptyStates.tsx +0 -0
  92. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/components/WorkerHealthBanner.tsx +0 -0
  93. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/constants.ts +0 -0
  94. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/logs.ts +0 -0
  95. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/outbox.ts +0 -0
  96. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/retry.ts +0 -0
  97. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/pages/worker-health.ts +0 -0
  98. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/py.typed +0 -0
  99. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/runner.py +0 -0
  100. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/service.py +0 -0
  101. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/services.py +0 -0
  102. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/settings.py +0 -0
  103. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/settings_celery.py +0 -0
  104. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/settings_env_checks.py +0 -0
  105. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/settings_logs.py +0 -0
  106. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/sync_db.py +0 -0
  107. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/task_heartbeat.py +0 -0
  108. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/task_resource.py +0 -0
  109. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/task_routing.py +0 -0
  110. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/tracking.py +0 -0
  111. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/worker_inspector.py +0 -0
  112. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/worker_settings.py +0 -0
  113. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/background_tasks/workers_state.py +0 -0
  114. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/conftest.py +0 -0
  115. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_admin_api.py +0 -0
  116. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_background_tasks_after_commit.py +0 -0
  117. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_background_tasks_delivery_context.py +0 -0
  118. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_background_tasks_heartbeat.py +0 -0
  119. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_background_tasks_resource_status.py +0 -0
  120. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_background_tasks_resource_transport.py +0 -0
  121. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_background_tasks_settings.py +0 -0
  122. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_background_tasks_tracking_modes.py +0 -0
  123. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_background_tasks_tz_columns.py +0 -0
  124. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_background_tasks_worker_tenancy.py +0 -0
  125. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_beat_schedule.py +0 -0
  126. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_config_guards.py +0 -0
  127. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_db_timeouts.py +0 -0
  128. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_index_has_executions.py +0 -0
  129. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_index_worker_presence.py +0 -0
  130. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_inprocess_sweep.py +0 -0
  131. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_invalidation.py +0 -0
  132. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_invalidation_degraded.py +0 -0
  133. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_invalidation_redis.py +0 -0
  134. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_list_item_payload.py +0 -0
  135. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_log_api.py +0 -0
  136. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_log_purge.py +0 -0
  137. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_log_sink.py +0 -0
  138. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_log_sink_loop.py +0 -0
  139. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_log_sink_nul.py +0 -0
  140. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_eager_platform.py +0 -0
  141. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_eager_serialization.py +0 -0
  142. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_fence_guard.py +0 -0
  143. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_guard_savepoint.py +0 -0
  144. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_loop_interrupt.py +0 -0
  145. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_publish_scope.py +0 -0
  146. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_retry_policy.py +0 -0
  147. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_swallowed_cancel.py +0 -0
  148. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_thread_loops.py +0 -0
  149. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_outbox_worker_chain.py +0 -0
  150. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_page_clamp.py +0 -0
  151. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_pagination_bounds.py +0 -0
  152. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_quiet_sweep_unrecorded.py +0 -0
  153. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_redis_health.py +0 -0
  154. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_redis_url.py +0 -0
  155. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_routes_override_api.py +0 -0
  156. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_runner_settings.py +0 -0
  157. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_service.py +0 -0
  158. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_settings_env.py +0 -0
  159. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_startup_log_masking.py +0 -0
  160. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_task_progress.py +0 -0
  161. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_task_progress_audit.py +0 -0
  162. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_task_routing.py +0 -0
  163. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_task_status_api.py +0 -0
  164. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_users_ordering.py +0 -0
  165. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_worker_audit.py +0 -0
  166. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_worker_audit_bookkeeping.py +0 -0
  167. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_bg_worker_settings.py +0 -0
  168. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_detail_props.py +0 -0
  169. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_execution_tenancy.py +0 -0
  170. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_index_filters.py +0 -0
  171. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_outbox_admin.py +0 -0
  172. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_outbox_concurrency.py +0 -0
  173. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_outbox_delivery.py +0 -0
  174. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_outbox_tenancy.py +0 -0
  175. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_outbox_worker_task.py +0 -0
  176. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_retry_failed_bulk.py +0 -0
  177. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_retry_failed_guards.py +0 -0
  178. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_retry_sweep_ordering.py +0 -0
  179. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_signal_tenant_stamp.py +0 -0
  180. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_signals.py +0 -0
  181. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_sweep_stuck.py +0 -0
  182. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_sync_db.py +0 -0
  183. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_sync_db_fork.py +0 -0
  184. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_tenant_context.py +0 -0
  185. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_worker_inspector.py +0 -0
  186. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_workers_endpoints.py +0 -0
  187. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests/test_workers_uptime.py +0 -0
  188. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests-js/background_tasks_DetailPage.test.tsx +0 -0
  189. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests-js/background_tasks_IndexPage.test.tsx +0 -0
  190. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests-js/background_tasks_LogsTab.test.tsx +0 -0
  191. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests-js/background_tasks_OutboxPage.test.tsx +0 -0
  192. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests-js/background_tasks_WorkerHealthBanner.test.tsx +0 -0
  193. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests-js/outbox.test.ts +0 -0
  194. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests-js/retry.test.ts +0 -0
  195. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests-js/stub-fetch.ts +0 -0
  196. {simple_module_background_tasks-0.0.42 → simple_module_background_tasks-0.0.43}/tests-js/task-formatters.test.ts +0 -0
  197. {simple_module_background_tasks-0.0.42 → 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.42
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.42
27
- Requires-Dist: simple-module-db==0.0.42
28
- Requires-Dist: simple-module-hosting==0.0.42
29
- Requires-Dist: simple-module-settings==0.0.42
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
@@ -7,6 +7,7 @@ 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
@@ -14,6 +15,7 @@ from datetime import UTC, datetime
14
15
  from typing import Any
15
16
 
16
17
  from celery import current_app
18
+ from kombu.utils.json import dumps
17
19
  from sqlalchemy import select
18
20
  from sqlalchemy.orm import Session
19
21
  from sqlmodel import col
@@ -34,12 +36,12 @@ def now_utc() -> datetime:
34
36
  def coerce_args_kwargs(args: Any, kwargs: Any) -> tuple[list[Any], dict[str, Any]]:
35
37
  """Normalise Celery args/kwargs payloads to JSON-ready shapes.
36
38
 
37
- Celery sometimes hands us tuples/frozensets that our JSON column can't
38
- 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.
39
41
  """
40
42
  safe_args: list[Any] = list(args) if args else []
41
43
  safe_kwargs: dict[str, Any] = dict(kwargs) if kwargs else {}
42
- return safe_args, safe_kwargs
44
+ return json.loads(dumps(safe_args)), json.loads(dumps(safe_kwargs))
43
45
 
44
46
 
45
47
  def upsert_by_celery_id(
@@ -97,12 +99,26 @@ def jsonable_result(result: Any) -> dict[str, Any] | None:
97
99
  """Wrap arbitrary task results in a JSON-storable shape."""
98
100
  if result is None:
99
101
  return None
100
- if isinstance(result, dict):
101
- return result
102
102
  try:
103
- 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)
104
111
  except Exception:
105
- 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}")
106
122
 
107
123
 
108
124
  def render_traceback(einfo: Any, exception: BaseException | None) -> str | None:
@@ -150,9 +166,9 @@ def apply_signal(
150
166
  if request is not None:
151
167
  metadata = {}
152
168
  if getattr(request, "args", None) is not None:
153
- metadata["args"] = list(request.args)
169
+ metadata["args"] = coerce_args_kwargs(request.args, None)[0]
154
170
  if getattr(request, "kwargs", None) is not None:
155
- metadata["kwargs"] = dict(request.kwargs)
171
+ metadata["kwargs"] = coerce_args_kwargs(None, request.kwargs)[1]
156
172
  delivery = getattr(request, "delivery_info", None) or {}
157
173
  if delivery.get("routing_key"):
158
174
  metadata["queue"] = delivery["routing_key"]
@@ -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*
@@ -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({})
@@ -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
@@ -192,8 +194,8 @@ class RetryCoordinator:
192
194
  tenant_id = row.tenant_id
193
195
  owner_user_id = row.owner_user_id
194
196
  options: dict[str, Any] = {
195
- "args": list(row.args or []),
196
- "kwargs": dict(row.kwargs or {}),
197
+ "args": loads(json.dumps(row.args or [])),
198
+ "kwargs": loads(json.dumps(row.kwargs or {})),
197
199
  "queue": row.queue,
198
200
  "task_id": task_id,
199
201
  }
@@ -22,6 +22,7 @@ from __future__ import annotations
22
22
  from typing import Any
23
23
 
24
24
  from celery import signals
25
+ from simple_module_db import current_tenant_id
25
26
 
26
27
  from background_tasks._signal_bus import bind_event_bus, publish_from_signal, unbind_event_bus
27
28
  from background_tasks._signal_support import (
@@ -42,13 +43,13 @@ from background_tasks.log_context import signal_task_finished, signal_task_start
42
43
  from background_tasks.models import TaskExecution
43
44
  from background_tasks.task_heartbeat import forget_heartbeat
44
45
  from background_tasks.tenant_context import (
46
+ TENANT_HEADER,
45
47
  message_tenant,
46
48
  published_owner,
47
49
  published_tenant,
48
50
  release_tenant,
49
51
  restore_tenant,
50
52
  stamp_owner,
51
- stamp_tenant,
52
53
  )
53
54
 
54
55
  # ── Enqueue ─────────────────────────────────────────────────────
@@ -63,7 +64,8 @@ def on_task_publish(
63
64
  **_kwargs: Any,
64
65
  ) -> None:
65
66
  """Record a row the moment a task is pushed onto the broker."""
66
- stamp_tenant(headers)
67
+ if headers is not None and current_tenant_id.get() is not None:
68
+ headers.setdefault(TENANT_HEADER, current_tenant_id.get())
67
69
  stamp_owner(headers)
68
70
  task_id = (headers or {}).get("id")
69
71
  task_name = sender or (headers or {}).get("task") or "unknown"
@@ -20,7 +20,8 @@ from datetime import UTC, datetime, timedelta
20
20
  from typing import Any
21
21
 
22
22
  from celery import Task, shared_task
23
- from sqlalchemy import ColumnElement, and_, delete, or_, update
23
+ from sqlalchemy import ColumnElement, and_, delete, or_, select, update
24
+ from sqlalchemy.orm import aliased
24
25
  from sqlmodel import col
25
26
 
26
27
  from background_tasks.constants import (
@@ -143,11 +144,26 @@ def purge_old_executions() -> int:
143
144
  log_cutoff = now - timedelta(days=runner.log_retention_days)
144
145
 
145
146
  with sync_session() as session:
146
- result = session.execute(
147
- delete(TaskExecution)
147
+ expired = (
148
+ select(TaskExecution.id)
148
149
  .where(TaskExecution.status.in_(list(TERMINAL_STATUSES)))
149
150
  .where(TaskExecution.finished_at < cutoff)
150
151
  )
152
+ # Surviving retries keep their history, but cannot reference purged rows.
153
+ session.execute(
154
+ update(TaskExecution)
155
+ .where(TaskExecution.retried_from_id.in_(expired))
156
+ .values(retried_from_id=None)
157
+ )
158
+ # A retry made between the two statements keeps its parent until the
159
+ # next run instead of failing the FK and rolling back the whole purge.
160
+ retry = aliased(TaskExecution)
161
+ referenced = select(retry.retried_from_id).where(retry.retried_from_id.is_not(None))
162
+ result = session.execute(
163
+ delete(TaskExecution)
164
+ .where(TaskExecution.id.in_(expired))
165
+ .where(TaskExecution.id.not_in(referenced))
166
+ )
151
167
  count = result.rowcount or 0
152
168
  delivered = session.execute(
153
169
  delete(OutboxMessage)
@@ -0,0 +1,85 @@
1
+ """Celery app and task bases that stamp and validate tenant authority on publish."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from celery import Celery, Task
8
+
9
+ from background_tasks.tenant_context import stamp_owner, stamp_tenant
10
+
11
+
12
+ class TenantPublishMixin:
13
+ """Stamp and validate authority on ``apply_async``, eager runs included.
14
+
15
+ An eager ``apply_async`` runs the body in-process without ``send_task`` or
16
+ the publish signal, so this is the only place its headers get the caller's
17
+ tenant and owner (and a mismatching tenant header is refused).
18
+ """
19
+
20
+ def apply_async(
21
+ self,
22
+ args: Any = None,
23
+ kwargs: Any = None,
24
+ task_id: Any = None,
25
+ producer: Any = None,
26
+ link: Any = None,
27
+ link_error: Any = None,
28
+ shadow: Any = None,
29
+ **options: Any,
30
+ ) -> Any:
31
+ # Explicit headers replace the task's default ones in Celery, so merge
32
+ # them here or a task-level default header would be lost.
33
+ defaults = self._get_exec_options().get("headers") or {}
34
+ headers = {**defaults, **(options.get("headers") or {})}
35
+ stamp_tenant(headers)
36
+ if self.app.conf.task_always_eager:
37
+ stamp_owner(headers)
38
+ options["headers"] = headers
39
+ return super().apply_async(
40
+ args, kwargs, task_id, producer, link, link_error, shadow, **options
41
+ )
42
+
43
+
44
+ class TenantTask(TenantPublishMixin, Task):
45
+ """Default task base with tenant-aware publication."""
46
+
47
+
48
+ class TenantCelery(Celery):
49
+ """Validate publish authority before Celery's exception-swallowing signals."""
50
+
51
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
52
+ kwargs.setdefault("task_cls", TenantTask)
53
+ super().__init__(*args, **kwargs)
54
+
55
+ def _task_from_fun( # ty: ignore[invalid-method-override]
56
+ self,
57
+ fun: Any,
58
+ name: Any = None,
59
+ base: Any = None,
60
+ bind: bool = False,
61
+ **options: Any,
62
+ ) -> Any:
63
+ # ``@app.task(base=Custom)`` replaces ``task_cls``; keep the tenant
64
+ # publish checks by composing them in front of the custom base.
65
+ base = base or self.Task
66
+ if not issubclass(base, TenantPublishMixin):
67
+ label = base.__name__
68
+ try:
69
+ base = type(
70
+ label,
71
+ (TenantPublishMixin, base),
72
+ {"__module__": base.__module__, "__qualname__": base.__qualname__},
73
+ )
74
+ except TypeError as exc:
75
+ raise TypeError(
76
+ f"Cannot compose tenant publish validation with task base {label}"
77
+ ) from exc
78
+ # Forward the rest untouched: the pydantic_* options only exist in Celery >= 5.5.
79
+ return super()._task_from_fun(fun, name=name, base=base, bind=bind, **options)
80
+
81
+ def send_task(self, name: str, *args: Any, **kwargs: Any) -> Any:
82
+ headers = dict(kwargs.get("headers") or {})
83
+ stamp_tenant(headers)
84
+ kwargs["headers"] = headers
85
+ return super().send_task(name, *args, **kwargs)
@@ -26,8 +26,9 @@ TENANT_HEADER = "sm_tenant_id"
26
26
  OWNER_HEADER = "sm_owner_id"
27
27
 
28
28
  _log = logging.getLogger(__name__)
29
- _tokens: dict[str, Token[str | None]] = {}
30
- _owner_tokens: dict[str, Token[str | None]] = {}
29
+ _tokens: ContextVar[tuple[tuple[str, Token[str | None], Token[str | None]], ...]] = ContextVar(
30
+ "sm_task_binding_tokens", default=()
31
+ )
31
32
  # The owner of the task body running on this context, so tasks it enqueues
32
33
  # carry the same owner. Kept apart from ``current_user_id`` on purpose: that
33
34
  # one also stamps ``created_by`` on audited rows.
@@ -168,31 +169,36 @@ def restore_tenant(*, task_id: str | None, task: Any) -> None:
168
169
  """Enter the message's tenant for the task body (prerun)."""
169
170
  if not task_id:
170
171
  return
171
- owner = message_owner(task=task)
172
- if owner is not None:
173
- _owner_tokens[task_id] = _task_owner.set(owner)
174
- tenant_id = _tenant_of(task) or _default_tenant
175
- if tenant_id is not None:
176
- _tokens[task_id] = current_tenant_id.set(tenant_id)
172
+ # Always set both, so a headerless worker task never inherits the previous
173
+ # binding. An in-process run (``apply()``, eager mode) is its caller's own
174
+ # context, so without headers it keeps the caller's tenant and owner.
175
+ eager = bool(getattr(getattr(task, "request", None), "is_eager", False))
176
+ tenant = _tenant_of(task) or (current_tenant_id.get() if eager else _default_tenant)
177
+ owner = message_owner(task=task) or (_task_owner.get() if eager else "") # "": no owner
178
+ owner_token = _task_owner.set(owner)
179
+ tenant_token = current_tenant_id.set(tenant)
180
+ _tokens.set((*_tokens.get(), (task_id, tenant_token, owner_token)))
177
181
 
178
182
 
179
183
  def release_tenant(*, task_id: str | None) -> None:
180
- """Leave the tenant entered by :func:`restore_tenant` (postrun)."""
181
- owner_token = _owner_tokens.pop(task_id, None) if task_id else None
182
- if owner_token is not None:
183
- try:
184
- _task_owner.reset(owner_token)
185
- except ValueError:
186
- _task_owner.set(None)
187
- token = _tokens.pop(task_id, None) if task_id else None
188
- if token is None:
184
+ """Leave the binding :func:`restore_tenant` entered for *task_id* (postrun)."""
185
+ stack = _tokens.get()
186
+ ids = [entry[0] for entry in stack]
187
+ if task_id not in ids:
189
188
  return
189
+ depth = len(ids) - 1 - ids[::-1].index(task_id)
190
+ if depth != len(stack) - 1:
191
+ # A prerun without its postrun: unwind it too rather than strand it.
192
+ _log.warning("Unwinding %d unfinished task binding(s)", len(stack) - 1 - depth)
193
+ _, tenant_token, owner_token = stack[depth]
194
+ _tokens.set(stack[:depth])
190
195
  try:
191
- current_tenant_id.reset(token)
196
+ _task_owner.reset(owner_token)
197
+ current_tenant_id.reset(tenant_token)
192
198
  except ValueError:
193
- # Token from another context (exotic pool patching): fall back to
194
- # clearing, so the next task on this worker never inherits a tenant.
195
- _log.debug("Tenant reset skipped for task_id=%s; clearing", task_id)
199
+ # Token from another context (exotic pool patching): clear instead, so
200
+ # the next task on this worker never inherits a tenant or owner.
201
+ _task_owner.set(None)
196
202
  current_tenant_id.set(None)
197
203
 
198
204
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simple-module-py/background-tasks",
3
- "version": "0.0.42",
3
+ "version": "0.0.43",
4
4
  "private": true,
5
5
  "description": "Frontend assets for the BackgroundTasks module",
6
6
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "simple_module_background_tasks"
3
- version = "0.0.42"
3
+ version = "0.0.43"
4
4
  description = "Celery + Redis task queue with admin UI for monitoring and retrying failed/stuck tasks"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -21,12 +21,12 @@ classifiers = [
21
21
  "Typing :: Typed",
22
22
  ]
23
23
  dependencies = [
24
- "simple_module_core==0.0.42",
25
- "simple_module_db==0.0.42",
26
- "simple_module_hosting==0.0.42",
27
- "simple_module_settings==0.0.42",
24
+ "simple_module_core==0.0.43",
25
+ "simple_module_db==0.0.43",
26
+ "simple_module_hosting==0.0.43",
27
+ "simple_module_settings==0.0.43",
28
28
  "celery[redis]>=5.4,<6",
29
- "redis>=5,<7",
29
+ "redis>=5,<9",
30
30
  ]
31
31
 
32
32
  [project.entry-points.simple_module]
@@ -0,0 +1,131 @@
1
+ """Typed Celery arguments survive tracking and history retries (#754)."""
2
+
3
+ from datetime import UTC, datetime
4
+ from decimal import Decimal
5
+ from uuid import UUID
6
+
7
+ import pytest
8
+ from background_tasks import sync_db
9
+ from background_tasks.constants import TaskStatus
10
+ from background_tasks.models import TaskExecution
11
+ from background_tasks.retry_service import RetryCoordinator
12
+ from background_tasks.signals import on_task_publish, on_task_success
13
+ from celery import Celery
14
+ from simple_module_core.events import EventBus
15
+ from sqlalchemy import select
16
+
17
+ VALUES = [datetime(2026, 1, 1, tzinfo=UTC), UUID(int=1), Decimal("1.25")]
18
+
19
+
20
+ @pytest.fixture
21
+ def celery_app():
22
+ with Celery(
23
+ "arguments", broker="memory://", backend="cache+memory://", set_as_current=False
24
+ ) as app:
25
+ app.conf.update(
26
+ task_always_eager=True, task_eager_propagates=True, sm_execution_tracking="full"
27
+ )
28
+ yield app
29
+
30
+
31
+ def test_typed_arguments_track_actual_success(sync_sqlite, celery_app):
32
+ @celery_app.task(name="arguments.job")
33
+ def job(*args, **kwargs):
34
+ assert list(args) == VALUES
35
+ assert kwargs == {"values": VALUES}
36
+ return True
37
+
38
+ result = job.apply_async(args=VALUES, kwargs={"values": VALUES})
39
+ assert result.successful()
40
+ with sync_db.sync_session() as session:
41
+ row = session.execute(select(TaskExecution)).scalar_one()
42
+ assert row.status == TaskStatus.SUCCESS
43
+ assert row.args[0] == {"__type__": "datetime", "__value__": "2026-01-01T00:00:00+00:00"}
44
+ assert row.kwargs["values"] == row.args
45
+
46
+
47
+ @pytest.mark.parametrize("path", ["publish", "request"])
48
+ def test_each_metadata_path_persists_typed_arguments(sync_sqlite, celery_app, path):
49
+ @celery_app.task(name="arguments.metadata")
50
+ def job():
51
+ pass
52
+
53
+ if path == "publish":
54
+ # Publish signals use the current app rather than a task instance.
55
+ from celery import current_app
56
+
57
+ previous = current_app._get_current_object()
58
+ celery_app.set_current()
59
+ try:
60
+ on_task_publish(
61
+ sender=job.name, headers={"id": "typed"}, body=(VALUES, {"values": VALUES}, {})
62
+ )
63
+ finally:
64
+ previous.set_current()
65
+ else:
66
+ job.push_request(id="typed", args=VALUES, kwargs={"values": VALUES})
67
+ try:
68
+ on_task_success(sender=job, result=True)
69
+ finally:
70
+ job.pop_request()
71
+ with sync_db.sync_session() as session:
72
+ row = session.execute(select(TaskExecution)).scalar_one()
73
+ assert row.args[0]["__type__"] == "datetime"
74
+ assert row.kwargs["values"] == row.args
75
+
76
+
77
+ def test_history_retry_decodes_typed_arguments(sync_sqlite, celery_app, monkeypatch):
78
+ @celery_app.task(name="arguments.retry")
79
+ def job(value, *, amount, identity):
80
+ assert isinstance(value, datetime)
81
+ assert value == VALUES[0]
82
+ assert isinstance(amount, Decimal)
83
+ assert amount == VALUES[2]
84
+ assert isinstance(identity, UUID)
85
+ assert identity == VALUES[1]
86
+ return True
87
+
88
+ celery_app.conf.task_always_eager = False
89
+ send_task = celery_app.send_task
90
+
91
+ def send(name, **options):
92
+ assert isinstance(options["args"][0], datetime)
93
+ assert isinstance(options["kwargs"]["amount"], Decimal)
94
+ return send_task(name, **options)
95
+
96
+ monkeypatch.setattr(celery_app, "send_task", send)
97
+ row = TaskExecution(
98
+ task_name=job.name,
99
+ args=[
100
+ {
101
+ "__type__": "datetime",
102
+ "__value__": "2026-01-01T00:00:00+00:00",
103
+ }
104
+ ],
105
+ status=TaskStatus.FAILED,
106
+ kwargs={
107
+ "amount": {"__type__": "decimal", "__value__": "1.25"},
108
+ "identity": {
109
+ "__type__": "uuid",
110
+ "__value__": {"hex": "00000000000000000000000000000001"},
111
+ },
112
+ },
113
+ )
114
+ with sync_db.sync_session() as session:
115
+ session.add(row)
116
+ with sync_db.sync_session() as session:
117
+ row = session.execute(select(TaskExecution)).scalar_one()
118
+ coordinator = RetryCoordinator(None, celery_app, EventBus())
119
+ publish = coordinator._publisher(row, "retry-id")
120
+ publish()
121
+ # send_task publishes to the broker even in eager mode; execute the payload locally.
122
+ with celery_app.connection_for_read() as connection:
123
+ queue = connection.SimpleQueue(row.queue)
124
+ try:
125
+ message = queue.get(block=False)
126
+ args, kwargs, _ = message.payload
127
+ assert job.apply(args=args, kwargs=kwargs, throw=True).successful()
128
+ message.ack()
129
+ finally:
130
+ queue.clear()
131
+ queue.close()