Skip to content

[Deferred] Periodic task scheduling #233

@rsamoilov

Description

@rsamoilov

Description

Rage::Deferred currently supports enqueuing one-off tasks and delayed tasks, but there is no built-in way to run tasks on a recurring schedule. Today, users who need periodic jobs (e.g. cleaning up expired records, refreshing caches, syncing data) have to reach for external tools like cron or a separate scheduling library.

The goal of this issue is to add native periodic task scheduling to Rage::Deferred, keeping it consistent with Rage's philosophy of collapsing backend concerns into a single runtime.

Proposed interface

# config/application.rb or config/environments/<environment>.rb
Rage.configure do
  config.deferred.schedule do
    every 1.hour, task: CleanupExpiredInvites
    every 1.minute, task: ResetCache
  end
end

Where CleanupExpiredInvites and ResetCache are standard Rage::Deferred::Task classes with a perform method.

Design considerations

These are open questions that should be addressed in the design proposal:

  • First run timing. After boot, should the first run happen immediately or wait for the first interval to elapse?
  • Leader election in multi-process deployments. If Rage is running multiple worker processes, only one process should own the scheduling responsibility to avoid duplicate task execution. Also, consider what happens when the leader process restarts — do timers reset?
  • Overlap policy. What happens if a scheduled task is still running when the next interval fires?
  • Arguments. Should every support passing arguments to the task's perform method?

Before You Start

This issue requires a design proposal before implementation. Please open a discussion or comment on this issue with a high-level plan that outlines:

  1. The public API (confirming or adjusting the interface above).
  2. How scheduling will be implemented (timer mechanism, which process owns it).
  3. The leader election strategy for multi-process deployments.
  4. How the edge cases above (overlap, first run, restarts) will be handled.

PRs without prior design discussion are unlikely to be accepted.

Tips

  • Check the Deferred docs to understand how Rage::Deferred works, especially the WAL and task execution model.
  • Look at how Rage::Cable selects a process to manage Redis subscriptions in multi-server setups.
  • Check the architecture doc that shows how Rage's core components interact with each other and outlines the design principles.
  • Feel free to ask any questions or request help in the comments below!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions