simple-module-background-tasks 0.0.50__tar.gz → 0.0.51__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 (217) hide show
  1. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/PKG-INFO +5 -5
  2. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/db_settings.py +6 -4
  3. simple_module_background_tasks-0.0.51/background_tasks/executions/after_commit.py +291 -0
  4. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/pyproject.toml +5 -5
  5. simple_module_background_tasks-0.0.51/tests/executions/service/test_background_tasks_after_commit_bounded.py +115 -0
  6. simple_module_background_tasks-0.0.50/background_tasks/executions/after_commit.py +0 -152
  7. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/.gitignore +0 -0
  8. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/LICENSE +0 -0
  9. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/README.md +0 -0
  10. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/__init__.py +0 -0
  11. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/contracts/__init__.py +0 -0
  12. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/contracts/events.py +0 -0
  13. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/contracts/logs.py +0 -0
  14. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/contracts/outbox.py +0 -0
  15. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/contracts/schemas.py +0 -0
  16. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/__init__.py +0 -0
  17. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/_lifecycle.py +0 -0
  18. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/config_guards.py +0 -0
  19. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/constants.py +0 -0
  20. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/health.py +0 -0
  21. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/invalidation.py +0 -0
  22. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/invalidation_channel.py +0 -0
  23. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/services.py +0 -0
  24. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/settings.py +0 -0
  25. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/settings_celery.py +0 -0
  26. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/settings_env_checks.py +0 -0
  27. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/settings_logs.py +0 -0
  28. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/sync_db.py +0 -0
  29. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/core/tracking.py +0 -0
  30. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/executions/__init__.py +0 -0
  31. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/executions/filters.py +0 -0
  32. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/executions/retry_service.py +0 -0
  33. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/executions/service.py +0 -0
  34. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/executions/tenant_context.py +0 -0
  35. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/locales/de.json +0 -0
  36. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/locales/en.json +0 -0
  37. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/logs/__init__.py +0 -0
  38. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/logs/purge.py +0 -0
  39. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/logs/service.py +0 -0
  40. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/logs/sink.py +0 -0
  41. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/models.py +0 -0
  42. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/module.py +0 -0
  43. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/outbox/__init__.py +0 -0
  44. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/outbox/claim.py +0 -0
  45. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/outbox/clock.py +0 -0
  46. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/outbox/dispatch.py +0 -0
  47. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/outbox/guard.py +0 -0
  48. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/outbox/loop.py +0 -0
  49. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/outbox/service.py +0 -0
  50. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/outbox/support.py +0 -0
  51. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/outbox/sweep.py +0 -0
  52. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/outbox/transport.py +0 -0
  53. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/outbox/worker.py +0 -0
  54. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/pages/Detail.tsx +0 -0
  55. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/pages/Index.tsx +0 -0
  56. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/pages/Logs.tsx +0 -0
  57. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/pages/Outbox.tsx +0 -0
  58. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/pages/Workers.tsx +0 -0
  59. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/pages/api.generated.ts +0 -0
  60. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/pages/i18n.generated.ts +0 -0
  61. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/py.typed +0 -0
  62. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/tasks.py +0 -0
  63. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/DetailFacts.tsx +0 -0
  64. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/ExecutionRow.tsx +0 -0
  65. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/ExecutionsTable.tsx +0 -0
  66. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/LogLevelSelect.tsx +0 -0
  67. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/LogTable.tsx +0 -0
  68. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/LogsPanel.tsx +0 -0
  69. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/OutboxTable.tsx +0 -0
  70. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/PayloadCards.tsx +0 -0
  71. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/ProgressCard.tsx +0 -0
  72. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/RetryAllDialog.tsx +0 -0
  73. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/RetryConfirmDialog.tsx +0 -0
  74. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/RoutesTable.tsx +0 -0
  75. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/StatusPill.tsx +0 -0
  76. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/StatusStrip.tsx +0 -0
  77. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/TaskFilters.tsx +0 -0
  78. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/TasksEmpty.tsx +0 -0
  79. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/TracebackCard.tsx +0 -0
  80. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/WorkerCard.tsx +0 -0
  81. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/WorkerEmptyStates.tsx +0 -0
  82. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/components/WorkerHealthBanner.tsx +0 -0
  83. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/utils/constants.ts +0 -0
  84. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/utils/logs.ts +0 -0
  85. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/utils/outbox.ts +0 -0
  86. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/utils/retry.ts +0 -0
  87. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/ui/utils/worker-health.ts +0 -0
  88. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/web/__init__.py +0 -0
  89. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/web/deps.py +0 -0
  90. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/web/endpoints/__init__.py +0 -0
  91. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/web/endpoints/api_admin.py +0 -0
  92. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/web/endpoints/api_status.py +0 -0
  93. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/web/endpoints/logs_api.py +0 -0
  94. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/web/endpoints/logs_views.py +0 -0
  95. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/web/endpoints/outbox_api.py +0 -0
  96. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/web/endpoints/outbox_views.py +0 -0
  97. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/web/endpoints/views.py +0 -0
  98. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/__init__.py +0 -0
  99. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/_signal_bus.py +0 -0
  100. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/_signal_support.py +0 -0
  101. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/celery_app.py +0 -0
  102. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/fleet_state.py +0 -0
  103. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/inspector.py +0 -0
  104. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/log_context.py +0 -0
  105. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/principals.py +0 -0
  106. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/runner.py +0 -0
  107. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/settings.py +0 -0
  108. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/signals.py +0 -0
  109. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/task_heartbeat.py +0 -0
  110. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/task_resource.py +0 -0
  111. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/task_routing.py +0 -0
  112. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/background_tasks/worker/tenant_celery.py +0 -0
  113. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/package.json +0 -0
  114. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/conftest.py +0 -0
  115. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/health/test_background_tasks_redis_health.py +0 -0
  116. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/invalidation/test_background_tasks_invalidation.py +0 -0
  117. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/invalidation/test_background_tasks_invalidation_degraded.py +0 -0
  118. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/invalidation/test_background_tasks_invalidation_redis.py +0 -0
  119. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/invalidation/test_background_tasks_invalidation_warmup.py +0 -0
  120. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/invalidation/test_installation_channel.py +0 -0
  121. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/invalidation/test_invalidation_bridge.py +0 -0
  122. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/settings/test_background_tasks_beat_schedule.py +0 -0
  123. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/settings/test_background_tasks_config_guards.py +0 -0
  124. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/settings/test_background_tasks_db_timeouts.py +0 -0
  125. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/settings/test_background_tasks_redis_url.py +0 -0
  126. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/settings/test_background_tasks_settings.py +0 -0
  127. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/settings/test_background_tasks_settings_env.py +0 -0
  128. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/settings/test_background_tasks_startup_log_masking.py +0 -0
  129. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/sync_db/test_background_tasks_sync_db.py +0 -0
  130. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/core/sync_db/test_background_tasks_sync_db_fork.py +0 -0
  131. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/retry/test_background_tasks_retry_failed_bulk.py +0 -0
  132. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/retry/test_background_tasks_retry_failed_guards.py +0 -0
  133. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/retry/test_background_tasks_retry_sweep_ordering.py +0 -0
  134. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/service/test_background_tasks_after_commit.py +0 -0
  135. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/service/test_background_tasks_eager_bindings.py +0 -0
  136. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/service/test_background_tasks_index_has_executions.py +0 -0
  137. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/service/test_background_tasks_list_item_payload.py +0 -0
  138. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/service/test_background_tasks_newest_first_status.py +0 -0
  139. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/service/test_background_tasks_order_index.py +0 -0
  140. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/service/test_background_tasks_publish_validation.py +0 -0
  141. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/service/test_background_tasks_read_projection.py +0 -0
  142. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/service/test_background_tasks_retention_retries.py +0 -0
  143. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/service/test_background_tasks_savepoint_publish.py +0 -0
  144. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/service/test_background_tasks_service.py +0 -0
  145. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/executions/service/test_background_tasks_tz_columns.py +0 -0
  146. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/logs/purge/test_background_tasks_log_purge.py +0 -0
  147. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/logs/sink/test_background_tasks_log_context.py +0 -0
  148. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/logs/sink/test_background_tasks_log_sink.py +0 -0
  149. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/logs/sink/test_background_tasks_log_sink_loop.py +0 -0
  150. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/logs/sink/test_background_tasks_log_sink_nul.py +0 -0
  151. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/admin/test_background_tasks_outbox_admin.py +0 -0
  152. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/admin/test_background_tasks_outbox_tenancy.py +0 -0
  153. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/delivery/test_background_tasks_delivery_context.py +0 -0
  154. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/delivery/test_background_tasks_inprocess_sweep.py +0 -0
  155. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/delivery/test_background_tasks_outbox_concurrency.py +0 -0
  156. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/delivery/test_background_tasks_outbox_delivery.py +0 -0
  157. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/delivery/test_background_tasks_outbox_eager_platform.py +0 -0
  158. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/delivery/test_background_tasks_outbox_eager_serialization.py +0 -0
  159. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/delivery/test_background_tasks_outbox_fence_guard.py +0 -0
  160. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/delivery/test_background_tasks_outbox_guard_savepoint.py +0 -0
  161. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/delivery/test_background_tasks_outbox_publish_scope.py +0 -0
  162. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/delivery/test_background_tasks_outbox_retry_policy.py +0 -0
  163. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/delivery/test_background_tasks_outbox_swallowed_cancel.py +0 -0
  164. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/delivery/test_background_tasks_outbox_worker_chain.py +0 -0
  165. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/delivery/test_background_tasks_outbox_worker_task.py +0 -0
  166. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/loop/test_background_tasks_outbox_loop_interrupt.py +0 -0
  167. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/outbox/loop/test_background_tasks_outbox_thread_loops.py +0 -0
  168. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/web/api/test_background_tasks_admin_api.py +0 -0
  169. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/web/api/test_background_tasks_detail_props.py +0 -0
  170. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/web/api/test_background_tasks_index_filters.py +0 -0
  171. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/web/api/test_background_tasks_log_api.py +0 -0
  172. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/web/api/test_background_tasks_page_clamp.py +0 -0
  173. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/web/api/test_background_tasks_pagination_bounds.py +0 -0
  174. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/web/api/test_background_tasks_task_status_api.py +0 -0
  175. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/web/api/test_background_tasks_users_ordering.py +0 -0
  176. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/inspector/test_background_tasks_index_worker_presence.py +0 -0
  177. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/inspector/test_background_tasks_worker_inspector.py +0 -0
  178. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/inspector/test_background_tasks_workers_endpoints.py +0 -0
  179. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/inspector/test_background_tasks_workers_uptime.py +0 -0
  180. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/runner/test_background_tasks_database_provider.py +0 -0
  181. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/runner/test_background_tasks_principal_config.py +0 -0
  182. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/runner/test_background_tasks_principals.py +0 -0
  183. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/runner/test_background_tasks_routes_override_api.py +0 -0
  184. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/runner/test_background_tasks_runner_settings.py +0 -0
  185. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/runner/test_background_tasks_task_routing.py +0 -0
  186. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/runner/test_background_tasks_worker_settings.py +0 -0
  187. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/runner/test_runner_invalidation_identity.py +0 -0
  188. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_argument_json.py +0 -0
  189. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_execution_bindings.py +0 -0
  190. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_heartbeat.py +0 -0
  191. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_quiet_sweep_unrecorded.py +0 -0
  192. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_resource_status.py +0 -0
  193. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_resource_transport.py +0 -0
  194. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_result_json.py +0 -0
  195. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_signal_tenant_stamp.py +0 -0
  196. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_signals.py +0 -0
  197. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_sweep_stuck.py +0 -0
  198. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_task_progress.py +0 -0
  199. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_task_progress_audit.py +0 -0
  200. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_tracking_modes.py +0 -0
  201. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_worker_audit.py +0 -0
  202. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/signals/test_background_tasks_worker_audit_bookkeeping.py +0 -0
  203. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/tenancy/test_background_tasks_custom_bases.py +0 -0
  204. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/tenancy/test_background_tasks_execution_tenancy.py +0 -0
  205. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/tenancy/test_background_tasks_tenant_context.py +0 -0
  206. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/tenancy/test_background_tasks_worker_tenancy.py +0 -0
  207. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests/worker/tenancy/test_background_tasks_worker_tenancy_context.py +0 -0
  208. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests-js/background_tasks_DetailPage.test.tsx +0 -0
  209. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests-js/background_tasks_IndexPage.test.tsx +0 -0
  210. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests-js/background_tasks_LogsTab.test.tsx +0 -0
  211. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests-js/background_tasks_OutboxPage.test.tsx +0 -0
  212. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests-js/background_tasks_WorkerHealthBanner.test.tsx +0 -0
  213. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests-js/background_tasks_WorkersPage.test.tsx +0 -0
  214. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests-js/outbox.test.ts +0 -0
  215. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests-js/retry.test.ts +0 -0
  216. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests-js/stub-fetch.ts +0 -0
  217. {simple_module_background_tasks-0.0.50 → simple_module_background_tasks-0.0.51}/tests-js/task-formatters.test.ts +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: simple_module_background_tasks
3
- Version: 0.0.50
3
+ Version: 0.0.51
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
@@ -23,10 +23,10 @@ Classifier: Typing :: Typed
23
23
  Requires-Python: >=3.12
24
24
  Requires-Dist: celery[redis]<6,>=5.4
25
25
  Requires-Dist: redis<9,>=5
26
- Requires-Dist: simple-module-core==0.0.50
27
- Requires-Dist: simple-module-db==0.0.50
28
- Requires-Dist: simple-module-hosting==0.0.50
29
- Requires-Dist: simple-module-settings==0.0.50
26
+ Requires-Dist: simple-module-core==0.0.51
27
+ Requires-Dist: simple-module-db==0.0.51
28
+ Requires-Dist: simple-module-hosting==0.0.51
29
+ Requires-Dist: simple-module-settings==0.0.51
30
30
  Description-Content-Type: text/markdown
31
31
 
32
32
  # simple_module_background_tasks
@@ -11,10 +11,12 @@ _RESTART = {"requires_restart": True, "group": "Database"}
11
11
  class WorkerDatabaseSettings(BaseSettings):
12
12
  """Inherited by BackgroundTasksSettings with its SM_BG_TASKS_ env prefix."""
13
13
 
14
- db_pool_size: int = Field(default=2, ge=1, json_schema_extra=_RESTART)
15
- db_max_overflow: int = Field(default=3, ge=0, json_schema_extra=_RESTART)
16
- db_recycle: int = Field(default=1800, ge=0, json_schema_extra=_RESTART)
17
- db_statement_timeout_ms: int | None = Field(default=None, ge=0, json_schema_extra=_RESTART)
14
+ db_pool_size: int = Field(default=2, ge=1, le=1000, json_schema_extra=_RESTART)
15
+ db_max_overflow: int = Field(default=3, ge=0, le=1000, json_schema_extra=_RESTART)
16
+ db_recycle: int = Field(default=1800, ge=0, le=2_147_483_647, json_schema_extra=_RESTART)
17
+ db_statement_timeout_ms: int | None = Field(
18
+ default=None, ge=0, le=2_147_483_647, json_schema_extra=_RESTART
19
+ )
18
20
 
19
21
 
20
22
  def worker_database_options(host: Any, worker: WorkerDatabaseSettings) -> dict[str, int]:
@@ -0,0 +1,291 @@
1
+ """Publish to the broker only once the transaction that justifies it commits.
2
+
3
+ A task enqueued inside a transaction races that transaction: the worker can
4
+ pick the message up before the row it refers to is visible (eager mode runs
5
+ it *inside* ``send_task``), and if the commit then fails the task is already
6
+ queued against nothing. Both are fixed the same way — hold the publish until
7
+ the commit has landed, and drop it if the transaction rolls back (GH #452).
8
+
9
+ Two delivery paths, picked per session:
10
+
11
+ - **A request's session** (``get_db``) — the publish goes through
12
+ :meth:`~simple_module_db.RequestSession.on_commit`, which the framework runs
13
+ after the request's commit and before the response is sent, and discards on
14
+ rollback or commit failure.
15
+ - **Any other session** — a worker's sync session, a CLI script's own
16
+ ``async with session.begin()`` — has nobody to run ``on_commit`` callbacks,
17
+ so the publish hangs off SQLAlchemy's ``after_commit`` event instead and is
18
+ dropped when its savepoint or the outermost transaction rolls back.
19
+
20
+ The broker id is reserved up front and returned, so the caller can write it
21
+ onto its own row in the same transaction: the row names the task before the
22
+ task exists, never the other way round.
23
+ """
24
+
25
+ from __future__ import annotations
26
+
27
+ import asyncio
28
+ import logging
29
+ import threading
30
+ import uuid
31
+ from collections.abc import Callable, Sequence
32
+ from concurrent.futures import ThreadPoolExecutor
33
+ from typing import Any
34
+
35
+ from simple_module_db import RequestSession, bind_current_tenant, mark_written
36
+ from simple_module_db.engine.callbacks import open_savepoints
37
+ from simple_module_db.engine.transaction import SESSION_START_KEY
38
+ from sqlalchemy import event
39
+ from sqlalchemy.ext.asyncio import AsyncSession
40
+ from sqlalchemy.orm import Session, SessionTransaction
41
+
42
+
43
+ class _LazyCurrentApp:
44
+ """``celery.current_app``, imported on first use so importing this module stays light."""
45
+
46
+ def __getattr__(self, name: str) -> Any:
47
+ from celery import current_app as _current_app
48
+
49
+ return getattr(_current_app, name)
50
+
51
+
52
+ current_app: Any = _LazyCurrentApp()
53
+
54
+ logger = logging.getLogger(__name__)
55
+
56
+ type Publish = Callable[[], object]
57
+
58
+ _PENDING_KEY = "background_tasks_after_commit"
59
+ _HOOKED_KEY = "background_tasks_after_commit_hooked"
60
+ # Upper bound for best-effort broker publish after commit (#1288).
61
+ PUBLISH_TIMEOUT_SECONDS = 2.0
62
+ _PUBLISH_WORKERS = 4
63
+ _PUBLISH_MAX_INFLIGHT = 8
64
+ _publish_executor = ThreadPoolExecutor(
65
+ max_workers=_PUBLISH_WORKERS, thread_name_prefix="celery-publish"
66
+ )
67
+ _publish_slots = threading.Semaphore(_PUBLISH_MAX_INFLIGHT)
68
+ _bg_publish_tasks: set[asyncio.Task[None]] = set()
69
+
70
+
71
+ def _celery_app_for(task: Any) -> Any:
72
+ return current_app if isinstance(task, str) else getattr(task, "app", None)
73
+
74
+
75
+ def _is_non_eager_celery(celery_app: Any) -> bool:
76
+ """True for a real Celery app publishing to a broker (not eager / mock)."""
77
+ conf = getattr(celery_app, "conf", None)
78
+ eager = getattr(conf, "task_always_eager", None)
79
+ return (
80
+ isinstance(eager, bool)
81
+ and not eager
82
+ and callable(getattr(celery_app, "connection_for_write", None))
83
+ )
84
+
85
+
86
+ def _bounded_transport_options(celery_app: Any, timeout: float) -> dict[str, Any]:
87
+ conf = getattr(celery_app, "conf", None)
88
+ existing = getattr(conf, "broker_transport_options", None)
89
+ opts: dict[str, Any] = dict(existing) if isinstance(existing, dict) else {}
90
+ opts["max_retries"] = 0
91
+ broker_url = getattr(conf, "broker_url", None) or ""
92
+ if isinstance(broker_url, str) and broker_url.startswith(("redis://", "rediss://")):
93
+ opts["socket_connect_timeout"] = min(
94
+ float(opts.get("socket_connect_timeout", timeout)), timeout
95
+ )
96
+ opts["socket_timeout"] = min(float(opts.get("socket_timeout", timeout)), timeout)
97
+ return opts
98
+
99
+
100
+ def _publish_bounded(
101
+ celery_app: Any,
102
+ task: Any,
103
+ args: tuple[Any, ...],
104
+ kwargs: dict[str, Any],
105
+ task_id: str,
106
+ timeout: float,
107
+ ) -> None:
108
+ opts = _bounded_transport_options(celery_app, timeout)
109
+ with celery_app.connection_for_write(connect_timeout=timeout, transport_options=opts) as conn:
110
+ if isinstance(task, str):
111
+ celery_app.send_task(
112
+ task,
113
+ args=list(args),
114
+ kwargs=kwargs,
115
+ task_id=task_id,
116
+ connection=conn,
117
+ retry=False,
118
+ ignore_result=True,
119
+ )
120
+ else:
121
+ task.apply_async(
122
+ args=args,
123
+ kwargs=kwargs,
124
+ task_id=task_id,
125
+ connection=conn,
126
+ retry=False,
127
+ ignore_result=True,
128
+ )
129
+
130
+
131
+ def _run_batch_guarded(batch: Sequence[Publish]) -> None:
132
+ try:
133
+ _run_all(batch)
134
+ finally:
135
+ _publish_slots.release()
136
+
137
+
138
+ async def _offload_batch(batch: Sequence[Publish], timeout: float | None) -> None:
139
+ """Run ``batch`` on the dedicated publisher pool with bounded admission."""
140
+ if not _publish_slots.acquire(blocking=False):
141
+ logger.warning("background_tasks.after_commit.publish_saturated count=%d", len(batch))
142
+ return
143
+ loop = asyncio.get_running_loop()
144
+ try:
145
+ fut = loop.run_in_executor(_publish_executor, _run_batch_guarded, batch)
146
+ except Exception:
147
+ _publish_slots.release()
148
+ raise
149
+ if timeout is None:
150
+ await fut
151
+ return
152
+ try:
153
+ await asyncio.wait_for(asyncio.shield(fut), timeout=timeout)
154
+ except TimeoutError:
155
+ logger.warning(
156
+ "background_tasks.after_commit.publish_timed_out timeout=%s count=%d",
157
+ timeout,
158
+ len(batch),
159
+ )
160
+
161
+
162
+ def enqueue_after_commit(db: AsyncSession | Session, task: Any, *args: Any, **kwargs: Any) -> str:
163
+ """Send *task* once *db*'s transaction commits; never if it rolls back.
164
+
165
+ Delivery is at-most-once: publish intent exists only in memory. Broker
166
+ failure after commit is logged without retry; a process exit between commit
167
+ and publish also loses the job. For must-run work use the event bus's
168
+ ``publish_durable(event, db)`` transactional outbox with a durable handler.
169
+
170
+ *task* is a Celery task (``send_receipt``), a signature
171
+ (``send_receipt.s().set(queue="mail")``, for routing options), or a
172
+ registered task name. ``*args`` / ``**kwargs`` are the task's own
173
+ arguments. Returns the Celery task id the message will carry.
174
+
175
+ Publishes as the tenant bound *now*, so a task enqueued in a request runs
176
+ for that request's tenant even when the commit happens elsewhere.
177
+ """
178
+ task_id = str(uuid.uuid4())
179
+ celery_app = _celery_app_for(task)
180
+ non_eager = _is_non_eager_celery(celery_app)
181
+
182
+ def publish() -> None:
183
+ if non_eager:
184
+ _publish_bounded(celery_app, task, args, kwargs, task_id, PUBLISH_TIMEOUT_SECONDS)
185
+ elif isinstance(task, str):
186
+ current_app.send_task(task, args=list(args), kwargs=kwargs, task_id=task_id)
187
+ else:
188
+ task.apply_async(args=args, kwargs=kwargs, task_id=task_id)
189
+
190
+ after_commit(
191
+ db,
192
+ [bind_current_tenant(publish)],
193
+ offload=non_eager,
194
+ timeout=PUBLISH_TIMEOUT_SECONDS if non_eager else None,
195
+ )
196
+ return task_id
197
+
198
+
199
+ def after_commit(
200
+ db: AsyncSession | Session,
201
+ publishes: Sequence[Publish],
202
+ *,
203
+ offload: bool = False,
204
+ timeout: float | None = None,
205
+ ) -> None:
206
+ """Run each of *publishes* after *db* commits, in order. Internal.
207
+
208
+ *offload* sends the batch to a dedicated publisher thread pool: kombu
209
+ publishes block, and running them on the event loop stalls every other
210
+ request. Left off for eager publishes so Celery's eager mode — which runs
211
+ the task body inside the publish — stays on the loop's thread. When
212
+ *timeout* is set alongside *offload*, the caller waits at most *timeout*
213
+ seconds before logging a warning and returning. One failed publish is
214
+ logged and does not stop the rest: the rows are already committed.
215
+ """
216
+ batch = list(publishes)
217
+ if isinstance(db, RequestSession) and SESSION_START_KEY in db.info:
218
+ # A request that wrote nothing else is rolled back and its ``on_commit``
219
+ # callbacks discarded, which would drop this publish silently. Queueing a
220
+ # task is itself work that must survive to the commit.
221
+ mark_written(db)
222
+ if offload:
223
+ db.on_commit(lambda: _offload_batch(batch, timeout))
224
+ else:
225
+ db.on_commit(lambda: _run_all(batch))
226
+ return
227
+ sync = db.sync_session if isinstance(db, AsyncSession) else db
228
+ savepoints = open_savepoints(sync)
229
+ sync.info.setdefault(_PENDING_KEY, []).extend(
230
+ (savepoints, publish, offload, timeout) for publish in batch
231
+ )
232
+ _hook(sync)
233
+
234
+
235
+ def _run_all(batch: Sequence[Publish]) -> None:
236
+ for publish in batch:
237
+ try:
238
+ publish()
239
+ except Exception:
240
+ logger.warning("background_tasks.after_commit.publish_failed", exc_info=True)
241
+
242
+
243
+ def _dispatch_unmanaged(entries: Sequence[tuple[Any, Publish, bool, float | None]]) -> None:
244
+ inline = [pub for _, pub, offload, _ in entries if not offload]
245
+ offloaded = [(pub, timeout) for _, pub, offload, timeout in entries if offload]
246
+ if inline:
247
+ _run_all(inline)
248
+ if not offloaded:
249
+ return
250
+ try:
251
+ loop = asyncio.get_running_loop()
252
+ except RuntimeError:
253
+ _run_all([pub for pub, _ in offloaded])
254
+ return
255
+ timeouts = [t for _, t in offloaded if t is not None]
256
+ bound = min(timeouts) if timeouts else None
257
+ task = loop.create_task( # noqa: RUF006 — tracked in _bg_publish_tasks
258
+ _offload_batch([pub for pub, _ in offloaded], bound)
259
+ )
260
+ _bg_publish_tasks.add(task)
261
+ task.add_done_callback(_bg_publish_tasks.discard)
262
+
263
+
264
+ def _hook(session: Session) -> None:
265
+ """Attach the commit/rollback listeners to *session* once."""
266
+ if session.info.get(_HOOKED_KEY):
267
+ return
268
+ session.info[_HOOKED_KEY] = True
269
+
270
+ def on_commit(sess: Session) -> None:
271
+ if not sess.in_nested_transaction():
272
+ _dispatch_unmanaged(sess.info.pop(_PENDING_KEY, []))
273
+
274
+ def on_rollback(sess: Session, transaction: SessionTransaction) -> None:
275
+ if transaction.nested and _PENDING_KEY in sess.info:
276
+ sess.info[_PENDING_KEY] = [
277
+ entry for entry in sess.info[_PENDING_KEY] if transaction not in entry[0]
278
+ ]
279
+
280
+ def on_end(sess: Session, transaction: SessionTransaction) -> None:
281
+ # ``after_commit`` already took the batch on the commit path; anything
282
+ # still queued when the outermost transaction ends was rolled back.
283
+ if transaction.parent is None:
284
+ sess.info.pop(_PENDING_KEY, None)
285
+
286
+ event.listen(session, "after_commit", on_commit)
287
+ event.listen(session, "after_soft_rollback", on_rollback)
288
+ event.listen(session, "after_transaction_end", on_end)
289
+
290
+
291
+ __all__ = ["enqueue_after_commit"]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "simple_module_background_tasks"
3
- version = "0.0.50"
3
+ version = "0.0.51"
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,10 +21,10 @@ classifiers = [
21
21
  "Typing :: Typed",
22
22
  ]
23
23
  dependencies = [
24
- "simple_module_core==0.0.50",
25
- "simple_module_db==0.0.50",
26
- "simple_module_hosting==0.0.50",
27
- "simple_module_settings==0.0.50",
24
+ "simple_module_core==0.0.51",
25
+ "simple_module_db==0.0.51",
26
+ "simple_module_hosting==0.0.51",
27
+ "simple_module_settings==0.0.51",
28
28
  "celery[redis]>=5.4,<6",
29
29
  "redis>=5,<9",
30
30
  ]
@@ -0,0 +1,115 @@
1
+ """Bounded non-retrying broker publishes from enqueue_after_commit (#1288)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import threading
7
+ import time
8
+ from contextlib import contextmanager
9
+ from types import SimpleNamespace
10
+ from typing import Any
11
+ from unittest.mock import MagicMock
12
+
13
+ import pytest
14
+ from background_tasks import enqueue_after_commit
15
+ from background_tasks.executions import after_commit as after_commit_mod
16
+ from background_tasks.models import TaskExecution
17
+ from simple_module_db import RequestSession, finalize_session
18
+ from simple_module_db.engine.transaction import SESSION_START_KEY
19
+
20
+
21
+ @pytest.mark.parametrize("managed", [True, False])
22
+ async def test_non_eager_celery_uses_bounded_non_retrying_publish(
23
+ db_session: RequestSession, monkeypatch: pytest.MonkeyPatch, managed: bool
24
+ ) -> None:
25
+ if managed:
26
+ db_session.info[SESSION_START_KEY] = time.perf_counter()
27
+
28
+ seen_conn_kwargs: list[dict[str, Any]] = []
29
+ seen_send: list[tuple[tuple[Any, ...], dict[str, Any]]] = []
30
+ fake_conn = object()
31
+
32
+ class _FakeNonEagerCelery:
33
+ def __init__(self) -> None:
34
+ self.conf = SimpleNamespace(
35
+ task_always_eager=False,
36
+ broker_url="redis://127.0.0.1:6379/0",
37
+ broker_transport_options={"visibility_timeout": 3600},
38
+ )
39
+
40
+ @contextmanager
41
+ def connection_for_write(self, **kw: Any):
42
+ seen_conn_kwargs.append(kw)
43
+ yield fake_conn
44
+
45
+ def send_task(self, *args: Any, **kw: Any) -> Any:
46
+ seen_send.append((args, kw))
47
+ return MagicMock(id=kw.get("task_id"))
48
+
49
+ monkeypatch.setattr(
50
+ "background_tasks.executions.after_commit.current_app", _FakeNonEagerCelery()
51
+ )
52
+ task_id = enqueue_after_commit(db_session, "orders.ship", 9)
53
+ db_session.add(TaskExecution(task_name="orders.ship"))
54
+ await db_session.flush()
55
+ await finalize_session(db_session)
56
+ if after_commit_mod._bg_publish_tasks:
57
+ await asyncio.gather(*list(after_commit_mod._bg_publish_tasks))
58
+
59
+ assert len(seen_conn_kwargs) == 1
60
+ opts = seen_conn_kwargs[0]["transport_options"]
61
+ assert opts["max_retries"] == 0
62
+ assert opts["visibility_timeout"] == 3600
63
+ assert opts["socket_connect_timeout"] > 0
64
+ assert opts["socket_timeout"] > 0
65
+ assert len(seen_send) == 1
66
+ args, kw = seen_send[0]
67
+ assert args == ("orders.ship",)
68
+ assert kw["args"] == [9]
69
+ assert kw["task_id"] == task_id
70
+ assert kw["connection"] is fake_conn
71
+ assert kw["retry"] is False
72
+ assert kw["ignore_result"] is True
73
+
74
+
75
+ async def test_unmanaged_async_session_offloads_stalled_publish(
76
+ db_session: RequestSession, monkeypatch: pytest.MonkeyPatch
77
+ ) -> None:
78
+ entered = threading.Event()
79
+ release = threading.Event()
80
+
81
+ class _StalledCelery:
82
+ def __init__(self) -> None:
83
+ self.conf = SimpleNamespace(
84
+ task_always_eager=False,
85
+ broker_url="redis://127.0.0.1:6379/0",
86
+ broker_transport_options={},
87
+ )
88
+
89
+ @contextmanager
90
+ def connection_for_write(self, **kw: Any):
91
+ yield object()
92
+
93
+ def send_task(self, *args: Any, **kw: Any) -> Any:
94
+ entered.set()
95
+ release.wait(timeout=5.0)
96
+
97
+ monkeypatch.setattr(after_commit_mod, "current_app", _StalledCelery())
98
+ monkeypatch.setattr(after_commit_mod, "PUBLISH_TIMEOUT_SECONDS", 0.25)
99
+
100
+ try:
101
+ enqueue_after_commit(db_session, "orders.ship", 1)
102
+ db_session.add(TaskExecution(task_name="orders.ship"))
103
+ t0 = time.monotonic()
104
+ await db_session.commit()
105
+ assert time.monotonic() - t0 < 0.2
106
+
107
+ deadline = time.monotonic() + 1.0
108
+ while not entered.is_set():
109
+ if time.monotonic() > deadline:
110
+ raise AssertionError("unmanaged offloaded publisher never started")
111
+ await asyncio.sleep(0)
112
+ finally:
113
+ release.set()
114
+ if after_commit_mod._bg_publish_tasks:
115
+ await asyncio.gather(*list(after_commit_mod._bg_publish_tasks))
@@ -1,152 +0,0 @@
1
- """Publish to the broker only once the transaction that justifies it commits.
2
-
3
- A task enqueued inside a transaction races that transaction: the worker can
4
- pick the message up before the row it refers to is visible (eager mode runs
5
- it *inside* ``send_task``), and if the commit then fails the task is already
6
- queued against nothing. Both are fixed the same way — hold the publish until
7
- the commit has landed, and drop it if the transaction rolls back (GH #452).
8
-
9
- Two delivery paths, picked per session:
10
-
11
- - **A request's session** (``get_db``) — the publish goes through
12
- :meth:`~simple_module_db.RequestSession.on_commit`, which the framework runs
13
- after the request's commit and before the response is sent, and discards on
14
- rollback or commit failure.
15
- - **Any other session** — a worker's sync session, a CLI script's own
16
- ``async with session.begin()`` — has nobody to run ``on_commit`` callbacks,
17
- so the publish hangs off SQLAlchemy's ``after_commit`` event instead and is
18
- dropped when its savepoint or the outermost transaction rolls back.
19
-
20
- The broker id is reserved up front and returned, so the caller can write it
21
- onto its own row in the same transaction: the row names the task before the
22
- task exists, never the other way round.
23
- """
24
-
25
- from __future__ import annotations
26
-
27
- import asyncio
28
- import logging
29
- import uuid
30
- from collections.abc import Callable, Sequence
31
- from typing import Any
32
-
33
- from simple_module_db import RequestSession, bind_current_tenant, mark_written
34
- from simple_module_db.engine.callbacks import open_savepoints
35
- from simple_module_db.engine.transaction import SESSION_START_KEY
36
- from sqlalchemy import event
37
- from sqlalchemy.ext.asyncio import AsyncSession
38
- from sqlalchemy.orm import Session, SessionTransaction
39
-
40
-
41
- class _LazyCurrentApp:
42
- """``celery.current_app``, imported on first use so importing this module stays light."""
43
-
44
- def __getattr__(self, name: str) -> Any:
45
- from celery import current_app as _current_app
46
-
47
- return getattr(_current_app, name)
48
-
49
-
50
- current_app: Any = _LazyCurrentApp()
51
-
52
- logger = logging.getLogger(__name__)
53
-
54
- type Publish = Callable[[], object]
55
-
56
- _PENDING_KEY = "background_tasks_after_commit"
57
- _HOOKED_KEY = "background_tasks_after_commit_hooked"
58
-
59
-
60
- def enqueue_after_commit(db: AsyncSession | Session, task: Any, *args: Any, **kwargs: Any) -> str:
61
- """Send *task* once *db*'s transaction commits; never if it rolls back.
62
-
63
- Delivery is at-most-once: publish intent exists only in memory. Broker
64
- failure after commit is logged without retry; a process exit between commit
65
- and publish also loses the job. For must-run work use the event bus's
66
- ``publish_durable(event, db)`` transactional outbox with a durable handler.
67
-
68
- *task* is a Celery task (``send_receipt``), a signature
69
- (``send_receipt.s().set(queue="mail")``, for routing options), or a
70
- registered task name. ``*args`` / ``**kwargs`` are the task's own
71
- arguments. Returns the Celery task id the message will carry.
72
-
73
- Publishes as the tenant bound *now*, so a task enqueued in a request runs
74
- for that request's tenant even when the commit happens elsewhere.
75
- """
76
- task_id = str(uuid.uuid4())
77
-
78
- def publish() -> None:
79
- if isinstance(task, str):
80
- current_app.send_task(task, args=list(args), kwargs=kwargs, task_id=task_id)
81
- else:
82
- task.apply_async(args=args, kwargs=kwargs, task_id=task_id)
83
-
84
- after_commit(db, [bind_current_tenant(publish)])
85
- return task_id
86
-
87
-
88
- def after_commit(
89
- db: AsyncSession | Session, publishes: Sequence[Publish], *, offload: bool = False
90
- ) -> None:
91
- """Run each of *publishes* after *db* commits, in order. Internal.
92
-
93
- *offload* sends the batch to a thread when the request path runs it: kombu
94
- publishes block, and hundreds of them on the event loop stall every other
95
- request. Left off for a single publish so Celery's eager mode — which runs
96
- the task body inside the publish — stays on the loop's thread. One failed
97
- publish is logged and does not stop the rest: the rows are already
98
- committed. Only callers with persisted pending work can reconcile failures.
99
- """
100
- batch = list(publishes)
101
- if isinstance(db, RequestSession) and SESSION_START_KEY in db.info:
102
- # A request that wrote nothing else is rolled back and its ``on_commit``
103
- # callbacks discarded, which would drop this publish silently. Queueing a
104
- # task is itself work that must survive to the commit.
105
- mark_written(db)
106
- if offload:
107
- db.on_commit(lambda: asyncio.to_thread(_run_all, batch))
108
- else:
109
- db.on_commit(lambda: _run_all(batch))
110
- return
111
- sync = db.sync_session if isinstance(db, AsyncSession) else db
112
- savepoints = open_savepoints(sync)
113
- sync.info.setdefault(_PENDING_KEY, []).extend((savepoints, publish) for publish in batch)
114
- _hook(sync)
115
-
116
-
117
- def _run_all(batch: Sequence[Publish]) -> None:
118
- for publish in batch:
119
- try:
120
- publish()
121
- except Exception:
122
- logger.exception("background_tasks.after_commit.publish_failed")
123
-
124
-
125
- def _hook(session: Session) -> None:
126
- """Attach the commit/rollback listeners to *session* once."""
127
- if session.info.get(_HOOKED_KEY):
128
- return
129
- session.info[_HOOKED_KEY] = True
130
-
131
- def on_commit(sess: Session) -> None:
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
- ]
140
-
141
- def on_end(sess: Session, transaction: SessionTransaction) -> None:
142
- # ``after_commit`` already took the batch on the commit path; anything
143
- # still queued when the outermost transaction ends was rolled back.
144
- if transaction.parent is None:
145
- sess.info.pop(_PENDING_KEY, None)
146
-
147
- event.listen(session, "after_commit", on_commit)
148
- event.listen(session, "after_soft_rollback", on_rollback)
149
- event.listen(session, "after_transaction_end", on_end)
150
-
151
-
152
- __all__ = ["enqueue_after_commit"]