New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set, serialize, and deserialize Active Job scheduled_at
as Time; deserialize enqueued_at
as Time; deprecate setting scheduled_at=
with numeric/epoch
#48066
Conversation
b25be4d
to
b01ede6
Compare
@bensheldon Could you rebase the changelog please? 🙏 |
@zzak will do! Do you have any thoughts about my last note on changing scheduled_at to be a DateTime instead of a Unix timestamp? On second thought, it should probably be changed before it's exposed in the job 😬 |
b01ede6
to
fe38552
Compare
fe38552
to
8f809b3
Compare
scheduled_at
enqueued_at
as Time
enqueued_at
as Timescheduled_at
as Time; deserialize enqueued_at
as Time
b8745bc
to
c819a72
Compare
@zzak I've rebased and tests are green. fyi, I did slightly expand the scope of this PR to internally treat |
@bensheldon I'm suggesting this change because it's scope was limited in size and improves the API to be succinct with the ecosystem, but won't be backportable once 7.1 is released. My assumption here is that this also doesn't break any compatibility or require a deprecation cycle, so that makes it easier to review. By making this suggestion, however, I'm only asking someone from core (like RF) to double check those assumptions. If you have any other stuff that fits that criteria, I think now is the time. |
226bd4a
to
bb58050
Compare
scheduled_at
as Time; deserialize enqueued_at
as Timescheduled_at
as Time; deserialize enqueued_at
as Time; deprecate setting scheduled_at= with numeric/epoc
scheduled_at
as Time; deserialize enqueued_at
as Time; deprecate setting scheduled_at= with numeric/epocscheduled_at
as Time; deserialize enqueued_at
as Time; deprecate setting scheduled_at=
with numeric/epoc
scheduled_at
as Time; deserialize enqueued_at
as Time; deprecate setting scheduled_at=
with numeric/epocscheduled_at
as Time; deserialize enqueued_at
as Time; deprecate setting scheduled_at=
with numeric/epoch
5e9e50f
to
d81d549
Compare
…serialize `enqueued_at` as Time; deprecate setting `scheduled_at=` with numeric/epoch Co-authored-by: Adam Pahlevi <adam.pahlevi@gmail.com>
d81d549
to
c919b47
Compare
Noting that there was a deprecation warning generated by the test helper: ...and fixed here: |
- Remove outdated versions of Rails (5.2, 6.0) and Ruby (2.5, 2.6) from test matrix due to reaching end of life - Add new versions of Rails (7.1) and Ruby (3.2) to the test matrix - Use separate gemfiles to enforce correct Rails version - Parse `event.payload[:job].enqueued_at` only when needed. In Rails 7.1 it is an instance of `Time` which makes Time.parse fail (see rails/rails#48066) Co-Authored-By: Jacopo Beschi <beschi.jacopo@gmail.com>
- Remove outdated versions of Rails (5.2, 6.0) and Ruby (2.5, 2.6) from test matrix due to reaching end of life - Add new versions of Rails (7.1) and Ruby (3.2) to the test matrix - Use separate gemfiles to enforce correct Rails version - Parse `event.payload[:job].enqueued_at` only when needed. In Rails 7.1 it is an instance of `Time` which makes Time.parse fail (see rails/rails#48066) Co-Authored-By: Jacopo Beschi <beschi.jacopo@gmail.com>
- Remove outdated versions of Rails (5.2, 6.0) and Ruby (2.5, 2.6) from test matrix due to reaching end of life - Add new versions of Rails (7.1) and Ruby (3.2) to the test matrix - Use separate gemfiles to enforce correct Rails version - Parse `event.payload[:job].enqueued_at` only when needed. In Rails 7.1 it is an instance of `Time` which makes Time.parse fail (see rails/rails#48066) Co-authored-by: Jacopo Beschi <beschi.jacopo@gmail.com>
Motivation / Background
This Pull Request has been created to make a job's
scheduled_at
value available during job execution by serializing/deserializing the value.This PR also aligns the behavior of both
scheduled_at
andenqueued_at
to useTime
objects internally instead of epoch-second Floats or Strings. This change forscheduled_at
should be transparent for users that are using the primaryset(wait:, wait_until:
) interface and is non-breaking if setting the value directly e.g.job.scheduled_at = 10.minutes.from_now.to_f
. The adapter interface is unchanged: adapters still receive epoch-second Float params inenqueue_at
.Detail
This change was initially proposed by @adamnoto in #32071 (2018), and closed because
scheduled_at
was viewed as an implementation detail of the backend queue adapter.I am reopening this PR because I believe there have been some changes in the ecosystem, and with Active Job, that warrant revisiting how
scheduled_at
is handled.Ecosystem changes: I'll point to my own
good_job
backend, alsoskiplock
, that are designed for Active Job, and did not exist at the time the previous PR was closed five years ago. With these Active Job-native adapters,scheduled_at
is directly used for scheduled jobs, and rescheduled retries. I think Active Job is in a stronger position today to assert the value, and if not appropriate, adapters are able to override/re-assign the value before execution, for example, as they typically dojob.provider_job_id
Active Job changes: There is a greater interface focus on the instance of
ActiveJob::Base
. For example, introducing#set
and the interface for perform_all_later. It would be nice to have full symmetry of attributes set on an instance before enqueue to be available on the instance after enqueue during execution.The inspiration for reopening this change was that I recently saw the
sidekiq-expiring-job
gem and thought that it would be nice if that could be easily implemented in an Active Jobbefore_perform
. e.g.Lastly,
scheduled_at
is not my favorite because it's a unix timestamp. If this is accepted, I'd love the ok to go through a deprecation cycle (or go through a deprecation cycle before accepting this PR) to convert it to a DateTime likeenqueued_at
is handled.Additional information
Related issues:
Time
,TimeWithZone
andDateTime
. #39698Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]