pydocket 0.30.0__tar.gz → 0.32.0__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 (229) hide show
  1. {pydocket-0.30.0 → pydocket-0.32.0}/.coveragerc-core +2 -1
  2. {pydocket-0.30.0 → pydocket-0.32.0}/PKG-INFO +2 -2
  3. {pydocket-0.30.0 → pydocket-0.32.0}/pyproject.toml +1 -1
  4. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/__init__.py +2 -0
  5. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/_execution_progress.py +4 -7
  6. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/_redis.py +81 -48
  7. pydocket-0.32.0/src/docket/_redis_credentials.py +255 -0
  8. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/_redis_sentinel.py +8 -9
  9. pydocket-0.32.0/src/docket/_subscription.py +91 -0
  10. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/_concurrency.py +32 -23
  11. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/docket.py +112 -29
  12. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/execution.py +58 -23
  13. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/worker.py +24 -24
  14. {pydocket-0.30.0 → pydocket-0.32.0}/tests/_rotating_provider.py +5 -3
  15. {pydocket-0.30.0 → pydocket-0.32.0}/tests/concurrency_limits/test_errors_and_resilience.py +57 -0
  16. {pydocket-0.30.0 → pydocket-0.32.0}/tests/concurrency_limits/test_waiter_queue.py +4 -7
  17. {pydocket-0.30.0 → pydocket-0.32.0}/tests/concurrency_limits/test_waiter_safeguard.py +4 -1
  18. {pydocket-0.30.0 → pydocket-0.32.0}/tests/conftest.py +14 -8
  19. pydocket-0.32.0/tests/test_batch_cancellation.py +291 -0
  20. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_credential_provider.py +64 -5
  21. pydocket-0.32.0/tests/test_credential_rotation.py +425 -0
  22. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_dependencies_core.py +4 -7
  23. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_docket_isolation.py +4 -9
  24. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_immediate_retry_state.py +4 -7
  25. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_memory_backend.py +21 -0
  26. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_payload_escaping.py +4 -7
  27. pydocket-0.32.0/tests/test_pubsub_resp_version.py +71 -0
  28. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_results_retrieval.py +3 -3
  29. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_results_storage.py +43 -1
  30. pydocket-0.32.0/tests/test_subscription.py +166 -0
  31. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_crash.py +2 -2
  32. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_lifecycle.py +5 -5
  33. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_reconnection.py +4 -4
  34. pydocket-0.32.0/tests/worker/test_repeated_cancel.py +53 -0
  35. pydocket-0.30.0/src/docket/_redis_credentials.py +0 -142
  36. pydocket-0.30.0/tests/test_credential_rotation.py +0 -294
  37. pydocket-0.30.0/tests/test_pubsub_resp_version.py +0 -48
  38. {pydocket-0.30.0 → pydocket-0.32.0}/.coveragerc-cli +0 -0
  39. {pydocket-0.30.0 → pydocket-0.32.0}/.gitignore +0 -0
  40. {pydocket-0.30.0 → pydocket-0.32.0}/.pre-commit-config.yaml +0 -0
  41. {pydocket-0.30.0 → pydocket-0.32.0}/LICENSE +0 -0
  42. {pydocket-0.30.0 → pydocket-0.32.0}/README.md +0 -0
  43. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/__main__.py +0 -0
  44. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/_cancellation.py +0 -0
  45. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/_docket_snapshot.py +0 -0
  46. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/_execution_scripts.py +0 -0
  47. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/_lua.py +0 -0
  48. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/_prometheus_exporter.py +0 -0
  49. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/_redelivery.py +0 -0
  50. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/_redis_memory.py +0 -0
  51. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/_result_store.py +0 -0
  52. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/_telemetry.py +0 -0
  53. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/_uuid7.py +0 -0
  54. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/agenda.py +0 -0
  55. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/annotations.py +0 -0
  56. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/cli/__init__.py +0 -0
  57. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/cli/_support.py +0 -0
  58. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/__init__.py +0 -0
  59. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/_base.py +0 -0
  60. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/_contextual.py +0 -0
  61. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/_cooldown.py +0 -0
  62. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/_cron.py +0 -0
  63. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/_debounce.py +0 -0
  64. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/_functional.py +0 -0
  65. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/_perpetual.py +0 -0
  66. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/_progress.py +0 -0
  67. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/_ratelimit.py +0 -0
  68. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/_resolution.py +0 -0
  69. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/_retry.py +0 -0
  70. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/dependencies/_timeout.py +0 -0
  71. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/instrumentation.py +0 -0
  72. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/acquire_or_park.lua +0 -0
  73. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/cancel_cleanup.lua +0 -0
  74. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/cancel_task.lua +0 -0
  75. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/claim.lua +0 -0
  76. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/clear.lua +0 -0
  77. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/debounce.lua +0 -0
  78. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/progress_write.lua +0 -0
  79. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/ratelimit.lua +0 -0
  80. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/refresh_lease.lua +0 -0
  81. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/release_and_wake.lua +0 -0
  82. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/scavenge_and_wake.lua +0 -0
  83. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/schedule.lua +0 -0
  84. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/stream_due_tasks.lua +0 -0
  85. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/lua/terminal.lua +0 -0
  86. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/py.typed +0 -0
  87. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/strikelist.py +0 -0
  88. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/tasks.py +0 -0
  89. {pydocket-0.30.0 → pydocket-0.32.0}/src/docket/testing.py +0 -0
  90. {pydocket-0.30.0 → pydocket-0.32.0}/tests/__init__.py +0 -0
  91. {pydocket-0.30.0 → pydocket-0.32.0}/tests/_container.py +0 -0
  92. {pydocket-0.30.0 → pydocket-0.32.0}/tests/_key_leak_checker.py +0 -0
  93. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/__init__.py +0 -0
  94. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/run.py +0 -0
  95. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/test_clear.py +0 -0
  96. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/test_iterate_with_timeout.py +0 -0
  97. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/test_module.py +0 -0
  98. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/test_parsing.py +0 -0
  99. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/test_snapshot.py +0 -0
  100. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/test_striking.py +0 -0
  101. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/test_tasks.py +0 -0
  102. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/test_url_validation.py +0 -0
  103. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/test_version.py +0 -0
  104. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/test_watch.py +0 -0
  105. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/test_worker.py +0 -0
  106. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/test_workers.py +0 -0
  107. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/waiting.py +0 -0
  108. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cli/worker_dependencies.py +0 -0
  109. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cluster/Dockerfile +0 -0
  110. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cluster/entrypoint.sh +0 -0
  111. {pydocket-0.30.0 → pydocket-0.32.0}/tests/cluster/start-cluster.sh +0 -0
  112. {pydocket-0.30.0 → pydocket-0.32.0}/tests/concurrency_limits/__init__.py +0 -0
  113. {pydocket-0.30.0 → pydocket-0.32.0}/tests/concurrency_limits/overlap.py +0 -0
  114. {pydocket-0.30.0 → pydocket-0.32.0}/tests/concurrency_limits/test_annotated.py +0 -0
  115. {pydocket-0.30.0 → pydocket-0.32.0}/tests/concurrency_limits/test_basic.py +0 -0
  116. {pydocket-0.30.0 → pydocket-0.32.0}/tests/concurrency_limits/test_execution_patterns.py +0 -0
  117. {pydocket-0.30.0 → pydocket-0.32.0}/tests/concurrency_limits/test_parked_status.py +0 -0
  118. {pydocket-0.30.0 → pydocket-0.32.0}/tests/concurrency_limits/test_redelivery.py +0 -0
  119. {pydocket-0.30.0 → pydocket-0.32.0}/tests/concurrency_limits/test_worker_mechanics.py +0 -0
  120. {pydocket-0.30.0 → pydocket-0.32.0}/tests/concurrency_limits/waiters.py +0 -0
  121. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/AGENTS.md +0 -0
  122. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/conftest.py +0 -0
  123. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_async_dependencies.py +0 -0
  124. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_builtin_tasks.py +0 -0
  125. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_call_arguments.py +0 -0
  126. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_cancellation.py +0 -0
  127. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_context_injection.py +0 -0
  128. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_cron.py +0 -0
  129. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_errors.py +0 -0
  130. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_idempotency.py +0 -0
  131. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_logging.py +0 -0
  132. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_perpetual.py +0 -0
  133. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_progress_state.py +0 -0
  134. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_results.py +0 -0
  135. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_retries.py +0 -0
  136. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_scheduling.py +0 -0
  137. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_self_perpetuation.py +0 -0
  138. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_shared_dependencies.py +0 -0
  139. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_striking.py +0 -0
  140. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_sync_dependencies.py +0 -0
  141. {pydocket-0.30.0 → pydocket-0.32.0}/tests/fundamentals/test_timeouts.py +0 -0
  142. {pydocket-0.30.0 → pydocket-0.32.0}/tests/instrumentation/test_counters.py +0 -0
  143. {pydocket-0.30.0 → pydocket-0.32.0}/tests/instrumentation/test_export.py +0 -0
  144. {pydocket-0.30.0 → pydocket-0.32.0}/tests/instrumentation/test_tracing.py +0 -0
  145. {pydocket-0.30.0 → pydocket-0.32.0}/tests/lua/calc.lua +0 -0
  146. {pydocket-0.30.0 → pydocket-0.32.0}/tests/lua/count_argv.lua +0 -0
  147. {pydocket-0.30.0 → pydocket-0.32.0}/tests/lua/echo_bool.lua +0 -0
  148. {pydocket-0.30.0 → pydocket-0.32.0}/tests/lua/echo_described_key.lua +0 -0
  149. {pydocket-0.30.0 → pydocket-0.32.0}/tests/lua/echo_dict.lua +0 -0
  150. {pydocket-0.30.0 → pydocket-0.32.0}/tests/lua/echo_keys_and_args.lua +0 -0
  151. {pydocket-0.30.0 → pydocket-0.32.0}/tests/lua/echo_list.lua +0 -0
  152. {pydocket-0.30.0 → pydocket-0.32.0}/tests/lua/echo_numbers.lua +0 -0
  153. {pydocket-0.30.0 → pydocket-0.32.0}/tests/lua/echo_tuple.lua +0 -0
  154. {pydocket-0.30.0 → pydocket-0.32.0}/tests/lua/extra_binding.lua +0 -0
  155. {pydocket-0.30.0 → pydocket-0.32.0}/tests/lua/join_variadic.lua +0 -0
  156. {pydocket-0.30.0 → pydocket-0.32.0}/tests/lua/misdecoded_flag.lua +0 -0
  157. {pydocket-0.30.0 → pydocket-0.32.0}/tests/lua/noscript_echo.lua +0 -0
  158. {pydocket-0.30.0 → pydocket-0.32.0}/tests/sitecustomize.py +0 -0
  159. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_agenda.py +0 -0
  160. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_annotated_dependencies.py +0 -0
  161. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_annotated_providers.py +0 -0
  162. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_automatic_perpetual_recovery.py +0 -0
  163. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_batch_scheduling.py +0 -0
  164. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_call_arguments.py +0 -0
  165. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_cancel_queued_task.py +0 -0
  166. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_cancellation.py +0 -0
  167. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_claim_supersedes.py +0 -0
  168. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_cooldown.py +0 -0
  169. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_debounce.py +0 -0
  170. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_dependencies_advanced.py +0 -0
  171. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_dependency_subclasses.py +0 -0
  172. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_dependency_uniqueness.py +0 -0
  173. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_depends_typing.py +0 -0
  174. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_docket_clear.py +0 -0
  175. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_docket_execution.py +0 -0
  176. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_docket_keys.py +0 -0
  177. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_docket_registration.py +0 -0
  178. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_docket_snapshot.py +0 -0
  179. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_execution.py +0 -0
  180. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_execution_state.py +0 -0
  181. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_exponential_retry_overflow.py +0 -0
  182. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_fallback_task.py +0 -0
  183. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_get_result_cancellation.py +0 -0
  184. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_handler_semantics.py +0 -0
  185. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_interrupted_tasks.py +0 -0
  186. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_key_leak_protection.py +0 -0
  187. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_lease_renewal.py +0 -0
  188. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_lua_decorator.py +0 -0
  189. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_perpetual_handoff.py +0 -0
  190. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_perpetual_race.py +0 -0
  191. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_perpetual_reliability.py +0 -0
  192. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_perpetual_reschedule.py +0 -0
  193. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_perpetual_state.py +0 -0
  194. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_progress_basics.py +0 -0
  195. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_progress_clobber.py +0 -0
  196. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_progress_pubsub.py +0 -0
  197. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_ratelimit.py +0 -0
  198. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_redelivery.py +0 -0
  199. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_redelivery_sweep.py +0 -0
  200. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_redis_connection.py +0 -0
  201. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_reschedule_clears_worker.py +0 -0
  202. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_retry_attempt_copies.py +0 -0
  203. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_retry_replaced.py +0 -0
  204. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_reused_keys.py +0 -0
  205. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_sentinel_urls.py +0 -0
  206. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_socket_timeout.py +0 -0
  207. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_strikelist.py +0 -0
  208. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_striking.py +0 -0
  209. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_task_cycle_round_trips.py +0 -0
  210. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_terminal_acked.py +0 -0
  211. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_testing.py +0 -0
  212. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_timeout_task_errors.py +0 -0
  213. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_uncalled_for_contract.py +0 -0
  214. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_uuid7.py +0 -0
  215. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_worker_cancellation.py +0 -0
  216. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_worker_dependencies.py +0 -0
  217. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_worker_single_dependencies.py +0 -0
  218. {pydocket-0.30.0 → pydocket-0.32.0}/tests/test_worker_task_deps_interaction.py +0 -0
  219. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_bootstrap.py +0 -0
  220. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_core.py +0 -0
  221. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_delivery_batch.py +0 -0
  222. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_due_task_batches.py +0 -0
  223. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_invariants.py +0 -0
  224. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_liveness.py +0 -0
  225. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_run_dependencies.py +0 -0
  226. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_scheduling.py +0 -0
  227. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_strikes_at_startup.py +0 -0
  228. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_task_factory.py +0 -0
  229. {pydocket-0.30.0 → pydocket-0.32.0}/tests/worker/test_ttl_zero.py +0 -0
@@ -13,7 +13,8 @@ omit =
13
13
  tests/_rotating_provider.py
14
14
  tests/sitecustomize.py
15
15
  tests/cli/*.py
16
- # real-Redis-only; skips on the memory and cluster legs
16
+ # real-Redis-only: they skip on the memory leg, and some of their tests skip
17
+ # on the cluster legs
17
18
  tests/test_socket_timeout.py
18
19
  tests/test_pubsub_resp_version.py
19
20
  tests/test_credential_rotation.py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pydocket
3
- Version: 0.30.0
3
+ Version: 0.32.0
4
4
  Summary: A distributed background task system for Python functions
5
5
  Project-URL: Homepage, https://docket.lol/
6
6
  Project-URL: Documentation, https://docket.lol/en/latest/
@@ -26,7 +26,7 @@ Requires-Dist: opentelemetry-api>=1.45.1
26
26
  Requires-Dist: prometheus-client>=0.21.1
27
27
  Requires-Dist: py-key-value-aio[memory,redis]>=0.3.0
28
28
  Requires-Dist: python-json-logger>=2.0.7
29
- Requires-Dist: redis>=6
29
+ Requires-Dist: redis>=6.2
30
30
  Requires-Dist: rich>=13.9.4
31
31
  Requires-Dist: typer>=0.15.1
32
32
  Requires-Dist: typing-extensions>=4.12.0
@@ -30,7 +30,7 @@ dependencies = [
30
30
  "prometheus-client>=0.21.1",
31
31
  "py-key-value-aio[memory,redis]>=0.3.0",
32
32
  "python-json-logger>=2.0.7",
33
- "redis>=6",
33
+ "redis>=6.2",
34
34
  "rich>=13.9.4",
35
35
  "typer>=0.15.1",
36
36
  "typing_extensions>=4.12.0",
@@ -40,6 +40,7 @@ from .execution import (
40
40
  ExecutionCancelled,
41
41
  ExecutionState,
42
42
  TaskCall,
43
+ UnpicklableException,
43
44
  )
44
45
  from .strikelist import StrikeList
45
46
  from .worker import Worker
@@ -78,5 +79,6 @@ __all__ = [
78
79
  "TaskLogger",
79
80
  "testing",
80
81
  "Timeout",
82
+ "UnpicklableException",
81
83
  "Worker",
82
84
  ]
@@ -15,7 +15,7 @@ from typing import (
15
15
  )
16
16
 
17
17
  from ._lua import Arg, Args, Key, redis_script
18
- from ._redis import Pipeline, RedisClient, confirm_subscriptions
18
+ from ._redis import Pipeline, RedisClient
19
19
 
20
20
  from ._telemetry import suppress_instrumentation
21
21
  from typing_extensions import Self
@@ -264,14 +264,11 @@ class ExecutionProgress:
264
264
  - updated_at: ISO 8601 timestamp
265
265
  """
266
266
  channel = self.docket.key(f"progress:{self.key}")
267
- async with self.docket._pubsub() as pubsub:
268
- await pubsub.subscribe(channel)
269
- await confirm_subscriptions(pubsub, 1)
267
+ async with self.docket._subscription(channels=[channel]) as subscription:
270
268
  if ready is not None:
271
269
  ready.set()
272
- async for message in pubsub.listen(): # pragma: no cover
273
- if message["type"] == "message":
274
- yield json.loads(message["data"])
270
+ async for message in subscription.listen(): # pragma: no cover
271
+ yield json.loads(message["data"])
275
272
 
276
273
 
277
274
  __all__ = [
@@ -18,6 +18,7 @@ from contextlib import AsyncExitStack, asynccontextmanager
18
18
  from datetime import datetime, timedelta
19
19
  from types import TracebackType
20
20
  from typing import (
21
+ TYPE_CHECKING,
21
22
  Any,
22
23
  AsyncGenerator,
23
24
  AsyncIterator,
@@ -29,6 +30,7 @@ from typing import (
29
30
  TypeAlias,
30
31
  TypedDict,
31
32
  TypeVar,
33
+ Unpack,
32
34
  cast,
33
35
  overload,
34
36
  runtime_checkable,
@@ -42,7 +44,15 @@ from redis.asyncio.connection import Connection, SSLConnection
42
44
  from redis.credentials import CredentialProvider
43
45
  from redis.exceptions import ConnectionError, RedisError
44
46
 
45
- from ._redis_credentials import ReauthenticatingPool
47
+ from ._redis_credentials import (
48
+ ProtocolOptions,
49
+ ReauthenticatingPool,
50
+ WithoutPubSubReauth,
51
+ pubsub_protocol,
52
+ )
53
+
54
+ if TYPE_CHECKING: # pragma: no cover
55
+ from ._subscription import Subscription
46
56
 
47
57
  logger: logging.Logger = logging.getLogger(__name__)
48
58
 
@@ -63,19 +73,6 @@ BLOCKING_READ_SOCKET_TIMEOUT: float | None = None
63
73
  # caller (a worker clearing its heartbeat during shutdown, for example).
64
74
  CONNECT_TIMEOUT: float = 10.0
65
75
 
66
- # hiredis-py leaks one small list for every RESP3 push reply: it passes a new
67
- # list to PyList_SetSlice, which does not steal the reference, so nothing ever
68
- # frees it. Under RESP3 every pub/sub message is a push reply, and docket's
69
- # subscribers listen for the life of a worker, so the leak has no bound: about
70
- # 100 bytes per message until the process dies. Streams and ordinary commands
71
- # are not push replies, so only the pub/sub connections drop to RESP2 and the
72
- # rest of the client keeps whatever redis-py negotiates. Remove this once
73
- # hiredis-py releases the fix.
74
- # https://github.com/redis/hiredis-py/issues/235
75
- # https://github.com/redis/hiredis-py/pull/239
76
- PUBSUB_RESP_VERSION: int = 2
77
-
78
-
79
76
  # ---------------------------------------------------------------------------
80
77
  # Input type aliases (mirror redis-py's type domain)
81
78
  # ---------------------------------------------------------------------------
@@ -151,6 +148,7 @@ class Pipeline(Protocol):
151
148
  value: EncodableT | None = None,
152
149
  mapping: Mapping[KeyT, EncodableT] | None = None,
153
150
  ) -> "Pipeline": ...
151
+ def publish(self, channel: KeyT, message: EncodableT) -> "Pipeline": ...
154
152
  def sadd(self, name: KeyT, *values: EncodableT) -> "Pipeline": ...
155
153
  def xack(self, name: KeyT, groupname: KeyT, *ids: StreamIDT) -> "Pipeline": ...
156
154
  def xdel(self, name: KeyT, *ids: StreamIDT) -> "Pipeline": ...
@@ -250,22 +248,6 @@ class PubSubClient(Protocol):
250
248
  async def aclose(self) -> None: ...
251
249
 
252
250
 
253
- async def confirm_subscriptions(pubsub: PubSubClient, count: int) -> None:
254
- """Block until the server has confirmed ``count`` subscription commands.
255
-
256
- ``PubSub.subscribe()`` only sends the SUBSCRIBE command; the server's
257
- confirmation arrives later as the first pub/sub message. A publisher on
258
- another connection can therefore beat the subscription unless the caller
259
- waits for the confirmation before signaling readiness.
260
-
261
- Subscription confirmations are delivered on a fresh connection before any
262
- published message can arrive, so consuming the first ``count`` messages
263
- consumes exactly the confirmations.
264
- """
265
- for _ in range(count):
266
- await pubsub.get_message(ignore_subscribe_messages=False, timeout=None)
267
-
268
-
269
251
  # ---------------------------------------------------------------------------
270
252
  # RedisClient: the public surface advertised by docket.redis()
271
253
  # ---------------------------------------------------------------------------
@@ -610,6 +592,22 @@ def is_cluster_client(redis: RedisClient) -> bool:
610
592
  return isinstance(redis, RedisCluster)
611
593
 
612
594
 
595
+ def non_transactional_pipeline(redis: RedisClient) -> Pipeline:
596
+ """Open a pipeline that sends its commands without MULTI/EXEC.
597
+
598
+ Wrapping a batch in MULTI/EXEC would make it one uninterruptible block on
599
+ the server, which delays worker claims and heartbeats. The batch methods
600
+ don't need it, because each command they send is atomic on its own.
601
+ """
602
+ try:
603
+ return redis.pipeline(transaction=False)
604
+ except TypeError: # pragma: no cover - burner's pipeline() takes no arguments
605
+ # The in-process memory backend executes commands sequentially
606
+ # with no MULTI/EXEC concept, so its default pipeline already
607
+ # behaves this way.
608
+ return redis.pipeline()
609
+
610
+
613
611
  async def close_resource(resource: AsyncCloseable, name: str) -> None:
614
612
  """Close a resource with error handling.
615
613
 
@@ -658,7 +656,7 @@ class RedisConnection:
658
656
  # client copies its whole response-callback table, so a client per call
659
657
  # costs real CPU.
660
658
  _client: Redis | None
661
- # Standalone mode: a second pool, at PUBSUB_RESP_VERSION, for pub/sub only
659
+ # Standalone mode: a second pool for pub/sub only, at pubsub_protocol()
662
660
  _pubsub_pool: ConnectionPool | None
663
661
  # Cluster mode: the RedisCluster client for data operations
664
662
  _cluster_client: RedisCluster | None
@@ -749,7 +747,9 @@ class RedisConnection:
749
747
  )
750
748
  self._stack.enter_context(self._rotation.following_pool(self._node_pool))
751
749
 
752
- self._node_client = Redis(connection_pool=self._node_pool)
750
+ self._node_client = Redis(
751
+ connection_pool=self._node_pool, event_dispatcher=WithoutPubSubReauth()
752
+ )
753
753
  self._stack.callback(lambda: setattr(self, "_node_client", None))
754
754
  self._stack.push_async_callback(
755
755
  close_resource, self._node_client, "node client"
@@ -777,7 +777,7 @@ class RedisConnection:
777
777
  self._stack.push_async_callback(close_resource, self._client, "client")
778
778
 
779
779
  self._pubsub_pool = await self._connection_pool_from_url(
780
- protocol=PUBSUB_RESP_VERSION
780
+ **pubsub_protocol(self._credential_provider)
781
781
  )
782
782
  self._stack.callback(lambda: setattr(self, "_pubsub_pool", None))
783
783
  self._stack.push_async_callback(
@@ -916,13 +916,13 @@ class RedisConnection:
916
916
  if self._parsed.scheme == "rediss+cluster"
917
917
  else Connection,
918
918
  decode_responses=False,
919
- protocol=PUBSUB_RESP_VERSION,
919
+ **pubsub_protocol(self._credential_provider),
920
920
  socket_timeout=BLOCKING_READ_SOCKET_TIMEOUT,
921
921
  socket_connect_timeout=CONNECT_TIMEOUT,
922
922
  )
923
923
 
924
924
  async def _connection_pool_from_url(
925
- self, decode_responses: bool = False, protocol: int | None = None
925
+ self, decode_responses: bool = False, **protocol: Unpack[ProtocolOptions]
926
926
  ) -> ConnectionPool:
927
927
  """Create a Redis connection pool from the URL.
928
928
 
@@ -932,24 +932,21 @@ class RedisConnection:
932
932
 
933
933
  Args:
934
934
  decode_responses: If True, decode Redis responses from bytes to strings
935
- protocol: The RESP version to negotiate, or None to leave redis-py's
936
- default alone. redis-py 6 sends ``HELLO None`` when the
937
- pool carries an explicit ``protocol=None``, so the key is only
938
- passed when a version is set.
935
+ protocol: The RESP version to negotiate and the parser to read it
936
+ with, or nothing to leave redis-py's defaults alone. redis-py
937
+ 6 sends ``HELLO None`` when the pool carries an explicit
938
+ ``protocol=None``, so the pool gets only the keys given here.
939
939
 
940
940
  Returns:
941
941
  A ConnectionPool ready for use with Redis clients
942
942
  """
943
- protocol_kwargs: dict[str, int] = (
944
- {"protocol": protocol} if protocol is not None else {}
945
- )
946
943
  if self.is_sentinel:
947
944
  from ._redis_sentinel import sentinel_connection_pool
948
945
 
949
946
  return sentinel_connection_pool(
950
947
  self.url,
951
948
  decode_responses=decode_responses,
952
- **protocol_kwargs,
949
+ **protocol,
953
950
  **self._credential_kwargs,
954
951
  socket_timeout=BLOCKING_READ_SOCKET_TIMEOUT,
955
952
  socket_connect_timeout=CONNECT_TIMEOUT,
@@ -957,7 +954,7 @@ class RedisConnection:
957
954
  return ReauthenticatingPool.from_url( # pyright: ignore[reportUnknownMemberType]
958
955
  self.url,
959
956
  decode_responses=decode_responses,
960
- **protocol_kwargs,
957
+ **protocol,
961
958
  **self._credential_kwargs,
962
959
  socket_timeout=BLOCKING_READ_SOCKET_TIMEOUT,
963
960
  socket_connect_timeout=CONNECT_TIMEOUT,
@@ -988,10 +985,14 @@ class RedisConnection:
988
985
 
989
986
  @asynccontextmanager
990
987
  async def pubsub(self) -> AsyncGenerator[PubSubClient, None]:
991
- """Get a pub/sub connection, handling standalone, cluster, and memory modes."""
988
+ """Get a pub/sub connection, handling standalone, cluster, and memory modes.
989
+
990
+ While it is open, a credential rotation re-authenticates it in place
991
+ (see ``_redis_credentials``)."""
992
992
  if self._cluster_client is not None: # pragma: no cover
993
993
  async with self._cluster_pubsub() as ps:
994
- yield cast(PubSubClient, ps)
994
+ with self._rotation.following_subscriber(ps):
995
+ yield cast(PubSubClient, ps)
995
996
  elif self._memory_client is not None:
996
997
  ps = self._memory_client.pubsub()
997
998
  try:
@@ -999,10 +1000,25 @@ class RedisConnection:
999
1000
  finally:
1000
1001
  await ps.aclose()
1001
1002
  else: # pragma: no cover - needs a standalone Redis server
1002
- async with Redis(connection_pool=require_open(self._pubsub_pool)) as r:
1003
- async with r.pubsub() as pubsub: # pyright: ignore[reportUnknownMemberType]
1003
+ async with (
1004
+ Redis(
1005
+ connection_pool=require_open(self._pubsub_pool),
1006
+ event_dispatcher=WithoutPubSubReauth(),
1007
+ ) as r,
1008
+ r.pubsub() as pubsub, # pyright: ignore[reportUnknownMemberType]
1009
+ ):
1010
+ with self._rotation.following_subscriber(pubsub):
1004
1011
  yield cast(PubSubClient, pubsub)
1005
1012
 
1013
+ def subscription(
1014
+ self, *, channels: Iterable[str] = (), patterns: Iterable[str] = ()
1015
+ ) -> Subscription:
1016
+ """A Subscription to these channels and patterns, on a pub/sub
1017
+ connection of its own that it opens when entered."""
1018
+ from ._subscription import Subscription
1019
+
1020
+ return Subscription(self.pubsub(), channels=channels, patterns=patterns)
1021
+
1006
1022
  async def publish(self, channel: str, message: str) -> int:
1007
1023
  """Publish a message to a pub/sub channel."""
1008
1024
  if self._cluster_client is not None: # pragma: no cover
@@ -1014,6 +1030,23 @@ class RedisConnection:
1014
1030
  client = require_open(self._client)
1015
1031
  return cast(int, await client.publish(channel, message)) # pyright: ignore[reportUnknownMemberType]
1016
1032
 
1033
+ async def publish_many(self, messages: Sequence[tuple[str, str]]) -> None:
1034
+ """Publish each ``(channel, message)`` pair in one pipelined round-trip.
1035
+
1036
+ On a cluster this goes through the node client, as ``publish`` does,
1037
+ because redis-py blocks PUBLISH in cluster pipelines.
1038
+ """
1039
+ if self._cluster_client is not None: # pragma: no cover
1040
+ client = cast(RedisClient, require_open(self._node_client))
1041
+ elif self._memory_client is not None:
1042
+ client = self._memory_client
1043
+ else: # pragma: no cover - needs a standalone Redis server
1044
+ client = cast(RedisClient, require_open(self._client))
1045
+ async with non_transactional_pipeline(client) as pipeline:
1046
+ for channel, message in messages:
1047
+ pipeline.publish(channel, message)
1048
+ await pipeline.execute()
1049
+
1017
1050
  @asynccontextmanager
1018
1051
  async def _cluster_pubsub(self) -> AsyncGenerator[PubSub, None]: # pragma: no cover
1019
1052
  """Create a pub/sub connection using the shared node pool.
@@ -0,0 +1,255 @@
1
+ """Re-authenticating docket's connections when a credential provider rotates.
2
+
3
+ redis-py registers a re-auth callback with a StreamingCredentialProvider for
4
+ each client that it gives the provider. A provider like redis-entraid's keeps
5
+ only the newest callback, and docket opens many clients on one provider: the
6
+ data and pub/sub clients, the result store, and the strike list. So docket
7
+ gives the provider only to its pools, which never register, and registers one
8
+ callback for each provider here. That callback re-authenticates every open
9
+ pool and cluster that uses the provider, and every subscribed connection.
10
+
11
+ A subscribed RESP2 connection can't send AUTH, but a subscribed RESP3
12
+ connection can, so with a streaming provider the pub/sub connections negotiate
13
+ RESP3. The callback writes AUTH onto each subscribed connection and reads
14
+ nothing: the subscriber's own reader is already waiting on that socket, and it
15
+ reads the reply as a pub/sub message of type "pong". The connection is never
16
+ closed, so the subscriber loses no message and receives none twice. redis-py
17
+ has its own re-auth for RESP3 pub/sub, but it reads the AUTH reply itself,
18
+ which fails while the subscriber's reader waits on the socket, and it registers
19
+ a callback with the provider for every subscriber, so docket turns it off.
20
+
21
+ A connection in use during a refresh gets its AUTH when it comes back to its
22
+ pool. redis-py sends that AUTH from a listener that runs after the connection
23
+ is already available again, so another task can take the connection and read
24
+ from the socket before the AUTH reply arrives (redis/redis-py#4433). docket's
25
+ pools are ReauthenticatingPools, which send it before giving the connection back.
26
+ """
27
+
28
+ import logging
29
+ from contextlib import AbstractContextManager, contextmanager
30
+ from typing import Generator, TypedDict, TypeVar
31
+ from weakref import WeakKeyDictionary
32
+
33
+ from redis._parsers import BaseParser, _AsyncRESP3Parser
34
+ from redis.asyncio import ConnectionPool
35
+ from redis.asyncio.client import PubSub
36
+ from redis.asyncio.cluster import ClusterNode, RedisCluster
37
+ from redis.asyncio.connection import AbstractConnection
38
+ from redis.auth.token import TokenInterface
39
+ from redis.credentials import CredentialProvider, StreamingCredentialProvider
40
+ from redis.event import AfterPubSubConnectionInstantiationEvent, EventDispatcher
41
+
42
+ logger: logging.Logger = logging.getLogger(__name__)
43
+
44
+ T = TypeVar("T")
45
+
46
+
47
+ class ProtocolOptions(TypedDict, total=False):
48
+ """The RESP version a pool negotiates, and the parser that reads it. A
49
+ missing key leaves redis-py's default."""
50
+
51
+ protocol: int
52
+ parser_class: type[BaseParser]
53
+
54
+
55
+ def pubsub_protocol(provider: CredentialProvider | None) -> ProtocolOptions:
56
+ """The protocol for docket's pub/sub connections.
57
+
58
+ Only a streaming provider rotates, and only RESP3 lets a subscribed
59
+ connection send AUTH, so the pub/sub connections negotiate RESP3 with a
60
+ streaming provider and RESP2 otherwise.
61
+
62
+ Under RESP3 every pub/sub message is a push reply, and hiredis-py 3.4.1 and
63
+ earlier leak one small list for each one (redis/hiredis-py#235, fixed in
64
+ 3.4.2 by redis/hiredis-py#239). docket's subscribers listen for the life
65
+ of a worker, so that leak has no bound: about 100 bytes per message until
66
+ the process dies. docket can't choose which hiredis-py an application
67
+ installs, so RESP3 pub/sub reads with redis-py's own Python parser, which
68
+ doesn't leak. RESP2 pub/sub messages are not push replies, so the
69
+ RESP2 connections keep whichever parser redis-py picks.
70
+ """
71
+ if isinstance(provider, StreamingCredentialProvider):
72
+ return {"protocol": 3, "parser_class": _AsyncRESP3Parser}
73
+ return {"protocol": 2}
74
+
75
+
76
+ class WithoutPubSubReauth(EventDispatcher):
77
+ """redis-py's event dispatcher, without its re-auth for pub/sub.
78
+
79
+ For each RESP3 pub/sub connection with a streaming provider, redis-py
80
+ registers a callback with the provider that sends AUTH and then reads the
81
+ reply. A provider like redis-entraid's keeps only the newest callback, so
82
+ that registration takes the refreshes away from docket's Rotation. And the
83
+ read fails with "readuntil() called while another coroutine is already
84
+ waiting" while a subscriber waits on the same socket, which breaks the
85
+ connection. The Rotation re-authenticates subscribers instead.
86
+ """
87
+
88
+ def dispatch(self, event: object) -> None:
89
+ if isinstance(event, AfterPubSubConnectionInstantiationEvent):
90
+ return
91
+ super().dispatch(event)
92
+
93
+
94
+ class ReauthenticatingPool(ConnectionPool):
95
+ """A ConnectionPool that sends a connection's pending AUTH while the
96
+ connection is still in use, so redis-py's release listener finds nothing
97
+ left to send."""
98
+
99
+ async def release(self, connection: AbstractConnection) -> None:
100
+ try:
101
+ if connection.is_connected:
102
+ await connection.re_auth()
103
+ else:
104
+ # A closed connection authenticates with the provider's current
105
+ # credentials when it next connects, so sending its queued AUTH
106
+ # would only reconnect it early. A subscriber's connection
107
+ # always comes back closed.
108
+ connection.set_re_auth_token(None) # pyright: ignore[reportArgumentType]
109
+ except BaseException:
110
+ # A failed AUTH leaves its token queued, and redis-py's listener
111
+ # would send it again once the connection is available. Without
112
+ # the token and the socket, the next use reconnects with the
113
+ # provider's current credentials instead.
114
+ connection.set_re_auth_token(None) # pyright: ignore[reportArgumentType]
115
+ await connection.disconnect(nowait=True)
116
+ raise
117
+ finally:
118
+ await super().release(connection)
119
+
120
+
121
+ @contextmanager
122
+ def _member(members: set[T], member: T) -> Generator[None, None, None]:
123
+ members.add(member)
124
+ try:
125
+ yield
126
+ finally:
127
+ members.discard(member)
128
+
129
+
130
+ class Rotation:
131
+ """The open pools, clusters, and subscribers that one provider's refreshed
132
+ credentials must reach."""
133
+
134
+ def __init__(self) -> None:
135
+ self._pools: set[ConnectionPool] = set()
136
+ self._clusters: set[RedisCluster] = set()
137
+ self._subscribers: set[PubSub] = set()
138
+
139
+ def following_pool(self, pool: ConnectionPool) -> AbstractContextManager[None]:
140
+ return _member(self._pools, pool)
141
+
142
+ def following_cluster(
143
+ self, cluster: RedisCluster
144
+ ) -> AbstractContextManager[None]: # pragma: no cover - needs a cluster
145
+ return _member(self._clusters, cluster)
146
+
147
+ def following_subscriber(
148
+ self, pubsub: PubSub
149
+ ) -> AbstractContextManager[None]: # pragma: no cover - needs a real Redis
150
+ return _member(self._subscribers, pubsub)
151
+
152
+ async def reauthenticate(
153
+ self, token: TokenInterface
154
+ ) -> None: # pragma: no cover - needs a real Redis
155
+ # A pool sends AUTH on its idle connections now, and on each connection
156
+ # in use when that connection comes back to the pool. A pool's AUTH
157
+ # reads its reply, so when a pool has an idle connection, a token the
158
+ # server rejects raises here, before any subscriber is sent it.
159
+ for pool in list(self._pools):
160
+ await pool.re_auth_callback(token)
161
+ for cluster in list(self._clusters):
162
+ for node in cluster_nodes(cluster):
163
+ await node.re_auth_callback(token)
164
+ for pubsub in list(self._subscribers):
165
+ await reauthenticate_subscriber(pubsub, token)
166
+
167
+ async def log_error(
168
+ self, error: Exception
169
+ ) -> None: # pragma: no cover - needs a failing provider
170
+ logger.warning("The credential provider failed to refresh", exc_info=error)
171
+
172
+
173
+ def cluster_nodes(
174
+ cluster: RedisCluster,
175
+ ) -> list[ClusterNode]: # pragma: no cover - needs a cluster
176
+ """Every node object of ``cluster`` that holds connections.
177
+
178
+ redis-py reads the cluster's slots through its startup nodes, and when it
179
+ copies the discovered nodes into ``startup_nodes`` it keeps the startup
180
+ node it already has, so that connection belongs to an object that
181
+ ``get_nodes()`` doesn't return. Without it, the slots connection keeps
182
+ the old token, and the server closes it when that token expires.
183
+ """
184
+ manager = cluster.nodes_manager
185
+ nodes = [*manager.nodes_cache.values(), *manager.startup_nodes.values()]
186
+ return list({id(node): node for node in nodes}.values())
187
+
188
+
189
+ async def reauthenticate_subscriber(
190
+ pubsub: PubSub, token: TokenInterface
191
+ ) -> None: # pragma: no cover - needs a real Redis
192
+ """Write AUTH onto a subscribed connection and leave the reply to its reader.
193
+
194
+ A subscriber whose connection is closed authenticates when it reconnects,
195
+ with the provider's current credentials. The server's reply arrives at the
196
+ subscriber's reader: "+OK", which Subscription drops, or an error, which
197
+ redis-py raises from the reader's next read, as it raises a rejected AUTH
198
+ from any command.
199
+ """
200
+ connection = pubsub.connection
201
+ if connection is None or not connection.is_connected:
202
+ return
203
+ try:
204
+ # The reader is waiting for a reply on this socket, so this only
205
+ # writes. Health checks read a reply, so they are off.
206
+ await connection.send_command(
207
+ "AUTH", token.try_get("oid"), token.get_value(), check_health=False
208
+ )
209
+ except Exception:
210
+ logger.warning(
211
+ "Could not re-authenticate a subscribed connection", exc_info=True
212
+ )
213
+
214
+
215
+ _rotations: "WeakKeyDictionary[StreamingCredentialProvider, Rotation]" = (
216
+ WeakKeyDictionary()
217
+ )
218
+
219
+
220
+ def rotation_for(provider: CredentialProvider | None) -> Rotation:
221
+ """The Rotation that a provider's refreshes reach. Only a streaming
222
+ provider refreshes, so any other provider gets one that never runs."""
223
+ if not isinstance(provider, StreamingCredentialProvider):
224
+ return Rotation()
225
+ if provider not in _rotations:
226
+ rotation = Rotation()
227
+ # redis-py types these callbacks as sync, but its own async clients
228
+ # register coroutine functions here, and the async token managers
229
+ # await them.
230
+ provider.on_next(rotation.reauthenticate) # pyright: ignore[reportArgumentType]
231
+ provider.on_error(rotation.log_error) # pyright: ignore[reportArgumentType]
232
+ _rotations[provider] = rotation
233
+ return _rotations[provider]
234
+
235
+
236
+ class WithoutRotation(CredentialProvider):
237
+ """A provider's credentials without its stream of refreshes.
238
+
239
+ RedisCluster registers its own re-auth callback with a streaming provider
240
+ each time it initializes, which would take the refreshes away from every
241
+ other connection. This gives it the credentials and nothing to register.
242
+ """
243
+
244
+ def __init__(
245
+ self, provider: CredentialProvider
246
+ ) -> None: # pragma: no cover - needs a cluster
247
+ self._provider = provider
248
+
249
+ def get_credentials(self) -> tuple[str] | tuple[str, str]: # pragma: no cover
250
+ return self._provider.get_credentials()
251
+
252
+ async def get_credentials_async(
253
+ self,
254
+ ) -> tuple[str] | tuple[str, str]: # pragma: no cover - needs a cluster
255
+ return await self._provider.get_credentials_async()
@@ -11,7 +11,7 @@ from __future__ import annotations
11
11
  import logging
12
12
  import socket
13
13
  from dataclasses import dataclass
14
- from typing import Any, Sequence, cast
14
+ from typing import Any, Sequence, Unpack, cast
15
15
  from urllib.parse import ParseResult, parse_qs, unquote, urlencode, urlparse
16
16
 
17
17
  from redis.asyncio import ConnectionPool, Redis
@@ -20,7 +20,7 @@ from redis.asyncio.sentinel import Sentinel, SentinelConnectionPool
20
20
  from redis.credentials import CredentialProvider
21
21
 
22
22
  from ._redis import close_resource
23
- from ._redis_credentials import ReauthenticatingPool
23
+ from ._redis_credentials import ProtocolOptions, ReauthenticatingPool
24
24
 
25
25
  logger: logging.Logger = logging.getLogger(__name__)
26
26
 
@@ -261,10 +261,10 @@ def sentinel_connection_pool(
261
261
  url: str,
262
262
  *,
263
263
  decode_responses: bool,
264
- protocol: int | None = None,
265
264
  credential_provider: CredentialProvider | None = None,
266
265
  socket_timeout: float | None,
267
266
  socket_connect_timeout: float | None,
267
+ **protocol: Unpack[ProtocolOptions],
268
268
  ) -> ConnectionPool:
269
269
  """Create a connection pool that resolves the master through Sentinel.
270
270
 
@@ -277,13 +277,13 @@ def sentinel_connection_pool(
277
277
  Args:
278
278
  url: The redis+sentinel:// or rediss+sentinel:// URL.
279
279
  decode_responses: If True, decode Redis responses from bytes to strings.
280
- protocol: The RESP version to negotiate, or None to leave redis-py's
281
- default alone.
282
280
  credential_provider: Supplies the data-node credentials in place of
283
281
  the URL's, or None to use the URL's.
284
282
  socket_timeout: The read timeout for data-node connections.
285
283
  socket_connect_timeout: The TCP connect timeout for data-node
286
284
  connections.
285
+ protocol: The RESP version to negotiate and the parser to read it
286
+ with, or nothing to leave redis-py's defaults alone.
287
287
 
288
288
  Returns:
289
289
  A ConnectionPool ready for use with Redis clients.
@@ -300,11 +300,10 @@ def sentinel_connection_pool(
300
300
  "socket_keepalive": True,
301
301
  "socket_keepalive_options": SENTINEL_SOCKET_KEEPALIVE_OPTIONS,
302
302
  **config.connection_kwargs,
303
+ # redis-py 6 sends ``HELLO None`` for an explicit ``protocol=None``, so
304
+ # the pool gets only the keys the caller gave.
305
+ **protocol,
303
306
  }
304
- # redis-py 6 sends ``HELLO None`` for an explicit ``protocol=None``, so
305
- # the key is only present when a version is set.
306
- if protocol is not None:
307
- pool_kwargs["protocol"] = protocol
308
307
  if credential_provider is not None:
309
308
  pool_kwargs["credential_provider"] = credential_provider
310
309
  return OwnedSentinelConnectionPool(config.service_name, sentinel, **pool_kwargs)