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

timezone issue for scheduler #315

Closed
qli-aa opened this issue May 30, 2018 · 10 comments
Closed

timezone issue for scheduler #315

qli-aa opened this issue May 30, 2018 · 10 comments

Comments

@qli-aa
Copy link

qli-aa commented May 30, 2018

sample code from apscheduler docs:

from pytz import utc
....
scheduler = BackgroundScheduler(jobstores=jobstores, executors=executors, job_defaults=job_defaults, timezone=utc)

it works for ubuntu, but after I change OS to amazonlinux, does not work
error message:

ERROR:apscheduler.jobstores.default:Unable to restore job "xxxx_job" -- removing it
Traceback (most recent call last):
  File "/usr/local/lib64/python2.7/site-packages/apscheduler/jobstores/sqlalchemy.py", line 141, in _get_jobs
    jobs.append(self._reconstitute_job(row.job_state))
  File "/usr/local/lib64/python2.7/site-packages/apscheduler/jobstores/sqlalchemy.py", line 125, in _reconstitute_job
    job_state = pickle.loads(job_state)
  File "/usr/local/lib/python2.7/site-packages/pytz/__init__.py", line 283, in _p
    return unpickler(*args)
  File "/usr/local/lib/python2.7/site-packages/pytz/tzinfo.py", line 539, in unpickler
    tz = pytz.timezone(zone)
  File "/usr/local/lib/python2.7/site-packages/pytz/__init__.py", line 177, in timezone
    raise UnknownTimeZoneError(zone)
UnknownTimeZoneError: 'local'

then I add a file /etc/timezone with content 'Etc/UTC', it works

when add a scheduled job, should it use timezone I passed in code otherwise read from /etc/timezone ?
looks like it always get it from system config

@qli-aa
Copy link
Author

qli-aa commented May 31, 2018

I found 2 issues here:

  1. apscheduler does not use timezone keyword I passed ?
  2. pytz/tzlocal try to get timezone function had a bug with amazonlinux distribution issue

@agronholm
Copy link
Owner

  1. How did you pass the timezone argument?
  2. Where should tzlocal find the local timezone on amazonlinux?

@qli-aa
Copy link
Author

qli-aa commented May 31, 2018

pass timezone=utc to BackgroundScheduler like this:

from pytz import utc
scheduler = BackgroundScheduler(jobstores=jobstores, executors=executors, job_defaults=job_defaults, timezone=utc)
  1. amazonlinux should be /etc/localtime, like centos/redhat instead of /etc/timezone, but tzlocal think it was not centos-like OS (because /etc/localtime exists but not a symlink), then return local timezone

@agronholm
Copy link
Owner

amazonlinux should be /etc/localtime, like centos/redhat instead of /etc/timezone, but tzlocal think it was not centos-like OS (because /etc/localtime exists but not a symlink), then return local timezone

Didn't you just say that you had to create /etc/timezone yourself?

@qli-aa
Copy link
Author

qli-aa commented Jun 1, 2018

yes. I created /etc/timezone as a workaround solution
#2 is not because of apscheduler, I'm just wondering why the time param does not effect I passed

@agronholm
Copy link
Owner

For 1), lots of people use an explicit time zone and it works fine for them. Would you mind giving me a complete, minimal standalone script that demonstrates the problem?
For 2), if /etc/timezone is not there, does it at least have /etc/localtime or another source of timezone information?

@bngo92
Copy link

bngo92 commented Oct 15, 2018

This is the issue I'm seeing with APScheduler-3.0.5 on CentOS Linux release 7.4.1708 (Core)

Traceback (most recent call last):
  File "apscheduler/schedulers/base.py", line 334, in add_job
    'trigger': self._create_trigger(trigger, trigger_args),
  File "apscheduler/schedulers/base.py", line 787, in _create_trigger
    return self._create_plugin_instance('trigger', trigger, trigger_args)
  File "apscheduler/schedulers/base.py", line 773, in _create_plugin_instance
    return plugin_cls(**constructor_kwargs)
  File "apscheduler/triggers/cron/__init__.py", line 52, in __init__
    self.timezone = astimezone(timezone)
  File "apscheduler/util.py", line 80, in astimezone
    raise ValueError('Unable to determine the name of the local timezone -- use an explicit timezone instead')
ValueError: Unable to determine the name of the local timezone -- use an explicit timezone instead

/etc/localtime does say UTC but since the zone is always local when using /etc/localtime, APScheduler doesn't work.

TZif2UTCTZif2UTC
UTC0

@agronholm
Copy link
Owner

@bngo92 Does this happen with the latest versions of tzlocal and apscheduler?

@likewhoa
Copy link

likewhoa commented Mar 1, 2019

@bngo92 You need to use a timezone name (such as Europe/Helsinki). For me it was America/New_York. echo "America/New_York >/etc/timezone for instance.

@agronholm
Copy link
Owner

As for the first observed problem, it happened while restoring an existing job. The timezone you set for the scheduler does not affect jobs added before that. So, not a bug. As for the second, report that to the tzlocal issue tracker.

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

No branches or pull requests

4 participants