Skip to content

Add PerpetualJob type that self-enqueues from next_batch#204

Open
robacarp wants to merge 4 commits into
masterfrom
claude/perpetual-job-type-CV70b
Open

Add PerpetualJob type that self-enqueues from next_batch#204
robacarp wants to merge 4 commits into
masterfrom
claude/perpetual-job-type-CV70b

Conversation

@robacarp

Copy link
Copy Markdown
Collaborator

A PerpetualJob runs on a schedule (like PeriodicJob) but supports
params (like QueuedJob) and knows how to enqueue itself. Subclasses
implement next_batch which returns an Array of job instances, each
configured with params for a single perform call. Every interval
the framework calls next_batch and enqueues each returned instance.

https://claude.ai/code/session_011P417H3rZzKjMoPqeTTcck

claude added 4 commits March 16, 2026 23:15
A PerpetualJob runs on a schedule (like PeriodicJob) but supports
params (like QueuedJob) and knows how to enqueue itself. Subclasses
implement `next_batch` which returns an Array of job instances, each
configured with params for a single `perform` call. Every interval
the framework calls `next_batch` and enqueues each returned instance.

https://claude.ai/code/session_011P417H3rZzKjMoPqeTTcck
Instead of a separate PerpetualJob class hierarchy, add a next_batch
hook to the Job base class. Any job can override next_batch to return
an Array of QueuedJob instances; after a successful run the executor
enqueues each one. This makes the perpetual pattern composable with
any job type (QueuedJob, PeriodicJob, etc.).

https://claude.ai/code/session_011P417H3rZzKjMoPqeTTcck
Introduces PerpetualJob (a QueuedJob subclass) with a `poll_every` macro
that registers the job for periodic polling. A dedicated
PerpetualJobRunner, driven by the Overseer alongside the Coordinator,
periodically instantiates registered perpetual jobs and calls
`next_batch` to discover and enqueue work — solving the initial enqueue
problem without requiring external triggers.

https://claude.ai/code/session_011P417H3rZzKjMoPqeTTcck
Instead of a dedicated PerpetualJob subclass, QueuedJob now detects at
compile time (via macro finished) whether a subclass defines both
next_batch and poll_every. When both are present, the job is
auto-registered for periodic polling by the PerpetualJobRunner.

This eliminates the separate type — any QueuedJob can opt in to polling
by adding `poll_every` alongside its `next_batch` override.

https://claude.ai/code/session_011P417H3rZzKjMoPqeTTcck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants