aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/jobs
diff options
context:
space:
mode:
authorAndrew White <andrew.white@unboxed.co>2018-02-22 14:14:42 +0000
committerAndrew White <andrew.white@unboxed.co>2018-02-22 14:14:42 +0000
commita9d1167b1fdae6f5f5496738b3e7d1e05949dcd0 (patch)
tree8a46f129aaed18c7c48b35aa0e48f9a19c1bc219 /activejob/test/jobs
parent9c0c90979a759a41628e0cd9d73821b0b34d03fc (diff)
downloadrails-a9d1167b1fdae6f5f5496738b3e7d1e05949dcd0.tar.gz
rails-a9d1167b1fdae6f5f5496738b3e7d1e05949dcd0.tar.bz2
rails-a9d1167b1fdae6f5f5496738b3e7d1e05949dcd0.zip
Add support for timezones to Active Job
Record what was the current timezone in effect when the job was enqueued and then restore when the job is executed in same way that the current locale is recorded and restored.
Diffstat (limited to 'activejob/test/jobs')
-rw-r--r--activejob/test/jobs/timezone_dependent_job.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/activejob/test/jobs/timezone_dependent_job.rb b/activejob/test/jobs/timezone_dependent_job.rb
new file mode 100644
index 0000000000..41f473d533
--- /dev/null
+++ b/activejob/test/jobs/timezone_dependent_job.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+require_relative "../support/job_buffer"
+
+class TimezoneDependentJob < ActiveJob::Base
+ def perform(now)
+ now = now.in_time_zone
+ new_year = localtime(2018, 1, 1)
+
+ if now >= new_year
+ JobBuffer.add("Happy New Year!")
+ else
+ JobBuffer.add("Just #{(new_year - now).div(3600)} hours to go")
+ end
+ end
+
+ private
+
+ def localtime(*args)
+ Time.zone ? Time.zone.local(*args) : Time.utc(*args)
+ end
+end