Skip to content
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

Time zone not passed to worker threads #341

Closed
KaneMorgan opened this issue Jun 6, 2023 · 2 comments
Closed

Time zone not passed to worker threads #341

KaneMorgan opened this issue Jun 6, 2023 · 2 comments
Assignees

Comments

@KaneMorgan
Copy link

KaneMorgan commented Jun 6, 2023

I've noticed something that was surprising to me. It seems as though setting the Timezone for the scheduler is not persisted to the child threads.

This should illustrate the issue

require 'rufus-scheduler'
require 'active_support/core_ext/time/zones'

Time.zone = 'Asia/Shanghai'
Rufus::Scheduler.new.in "2s" do
  puts "Timezone is: #{Time.zone} EtOrbi zone: #{EtOrbi.zone}"
end

The output of this is Timezone is: EtOrbi zone: Europe - Belfast

In the parent the timezone is Asia/Shanghai

irb(main):009:0> EtOrbi.zone
=> #<TZInfo::DataTimezone: Asia/Shanghai>

I'd expected for the thread to have the same timezone as the scheduler.

For now I'm explicitly setting the timezone in the do block, but just wondered whether the above was intended

We are on rufus-scheduler 3.8.2

@jmettraux jmettraux self-assigned this Jun 6, 2023
@jmettraux
Copy link
Owner

Hello,

this is not really intended. The scheduler is intended to trigger at the right time, not necessarily with the right timezone.

I refrained looking too much into the issue as the core Ruby was moving towards support for explicit zones, and haven't looked much since.

I am closing the issue but not the conversation.

Kind regards.

@KaneMorgan
Copy link
Author

KaneMorgan commented Jun 7, 2023

Thanks @jmettraux for responding so quickly.

I've done some more digging and I think the source of my confusion is actually in active_support.

It looks like Time.zone= actually only sets the TimeZone for the current thread
https://github.com/rails/rails/blob/v6.1.7.3/activesupport/lib/active_support/core_ext/time/zones.rb#L41

This is probably a good idea in the context of Rails in general but wasn't obvious to me,

Given the above I don't think it's the responsibility of this gem to maintain the timezone, but it may be worth a note in the Timezones section of the readme

Thank you for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants