Skip to content

Feature Request: Expose Time Control for Testing #751

Description

@mastercactapus

Description:

Our app manages scheduling, and we're migrating some workloads to River, including updating rotations (e.g., advancing to the next person at a set time) which we're looking to leverage the ScheduledAt option. In app, everything is based on the now() value to avoid clock-drift issues. In our behavioral tests, we currently manipulate PostgreSQL's now() function (via proxying) to control time, but we’ve noticed that scheduled jobs don’t run when DB time advances. Looking deeper, it appears River’s scheduling relies on system time instead of database time.

Feature Request:

Would it be possible to expose a way to control time? The river.Config has a time property that takes a baseservice.TimeGenerator—would making it public (e.g., Time) be enough? This would help with:

  • Testing: Simulating different time scenarios without modifying system time.
  • Production: Keeping ScheduledAt jobs aligned with database time to mitigate clock drift issues.

Potential Approaches:

  1. Make Time Public: Allowing a custom time source to be set.
  2. Sync to DB Time: Providing an option for River to rely on PostgreSQL's now().

Benefits:

  • More reliable scheduling in both tests and production.
  • Prevents early job execution due to clock drift.
  • Simplifies simulating past and future time scenarios in tests.

I would love to hear your thoughts on this; thanks for considering it!

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