refactor: share Queue via Arc
#100
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This refactor improves ergonomics and internal consistency by wrapping all Queue instances in Arc. It simplifies the public API, avoids unnecessary clones, and enables more flexible, re-entrant usage patterns.
Key changes:
Queue ownership:
Job,Worker,Scheduler, andEnqueuedJobnow storeArc<Queue<T>>.Worker::newandScheduler::newnow takeArc<Queue<T>>instead of owning theQueuedirectly.Job-scoped helpers:
Job::queue()->Arc<Queue<Self>>Job::worker()->Worker<Self>Job::scheduler()->Scheduler<Self>Borrow-based execution:
Job::run(&self)andJob::start(&self)now take&selfinstead ofself.Jobwithout moving ownership.Removed wrappers:
Job::run_workerandJob::run_schedulerremoved.job.worker().run().awaitandjob.scheduler().run().awaitinstead.Rationale:
Simpler public API: Consumers think in terms of jobs, not queues. The new helpers reduce boilerplate and expose a safer, more intuitive entry point.
Consistent shared state: Advisory locks and database handles are now consistently shared across job runners via
Arc, reducing the risk of misuse.Avoid unnecessary clones: Fewer
queue.clone()calls, more efficient task spawning.Supports concurrent orchestration: Borrow-based run/start methods allow
tokio::spawn(job.worker().run())without moving the job.Migration:
Update any code accessing
queuedirectly to instead calljob.queue().