Repository navigation
Commit 52d40b1
Reset a Perpetual's cancel and next-run time on each run (#626)
Since #619, `Perpetual.__aenter__` returns `copy.copy()` of the declared
instance, and the copy keeps `cancelled` and `_next_when`. A task
function called directly, outside a worker, receives the declared
default itself. A `cancel()`, `after()`, or `at()` from that call then
carried into every later worker run of the task in the same process.
After a direct call that cancelled, each worker run stopped the
perpetual instead of rescheduling it.
`__aenter__` now resets `cancelled` to `False` and `_next_when` to
`None` on the copy. Cron's `__aenter__` already does the same for its
`_iterator`. This matches 0.29, where each run built a new
`Perpetual(every=..., automatic=...)`. A changed `every` still carries
over, as it did in 0.29, because 0.29 also read `self.every`.
The other dependencies that #619 moved to `copy.copy()` don't have this
problem:
- `Retry` and `ExponentialRetry` set `attempt` and `delay` from the
execution on each copy. `Retry.after()` writes `delay`, but 0.29 also
copied `self.delay`.
- `Timeout.run()` calls `start()` on the copy, which sets `_deadline`.
- `ConcurrencyLimit` sets every per-run field on its copy.
The new test calls a perpetual task directly with `after(1h)` and
`cancel()`, then runs it on a worker and checks that it runs three
times. Without the fix, it runs once.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Chris Guidry <chris@theguidrys.us>1 parent 5e911e1 commit 52d40b1
2 files changed
Lines changed: 42 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
| 98 | + | |
| 99 | + | |
96 | 100 | | |
97 | 101 | | |
98 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
0 commit comments