Skip to content

Commit 8d9d801

Browse files
committed
Preserve job.enqueued_at timestamp precision
* Allows instrumenters to more accurately deduce queue wait time * Retains IS08601 compatibility References rails#39698
1 parent 989de53 commit 8d9d801

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

activejob/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
* Preserve full-precision `enqueued_at` timestamps for serialized jobs,
2+
allowing more accurate reporting of how long a job spent waiting in the
3+
queue before it was performed.
4+
5+
Retains IS08601 format compatibility.
6+
7+
*Jeremy Daer*
8+
19
* Add `--parent` option to job generator to specify parent class of job.
210

311
Example:

activejob/lib/active_job/core.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def serialize
113113
"exception_executions" => exception_executions,
114114
"locale" => I18n.locale.to_s,
115115
"timezone" => timezone,
116-
"enqueued_at" => Time.now.utc.iso8601
116+
"enqueued_at" => Time.now.utc.iso8601(9)
117117
}
118118
end
119119

activejob/test/cases/job_serialization_test.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,13 @@ class JobSerializationTest < ActiveSupport::TestCase
6565
end
6666
end
6767

68-
test "serialize stores the enqueued_at time" do
69-
h1 = HelloJob.new
70-
type = h1.serialize["enqueued_at"].class
71-
assert_equal String, type
68+
test "serializes enqueued_at with full precision" do
69+
freeze_time
7270

73-
h2 = HelloJob.deserialize(h1.serialize)
74-
# We should be able to parse a timestamp
75-
type = Time.parse(h2.enqueued_at).class
76-
assert_equal Time, type
71+
serialized = HelloJob.new.serialize
72+
assert_kind_of String, serialized["enqueued_at"]
73+
74+
enqueued_at = HelloJob.deserialize(serialized).enqueued_at
75+
assert_equal Time.now.utc, Time.iso8601(enqueued_at)
7776
end
7877
end

0 commit comments

Comments
 (0)