-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Cron jobs and timezone handling #136
Comments
Currently apalis uses UTC. |
Any suggestions on how I can test it? My first attempt will be replace |
I think UTC is standard, and based on the machine's time settings. Are you sure that is ok? |
Yes that behaviour is expected. However I'm running my application in an environment which does not have the timezone database (docker scratch). |
Could you give this a try? RUN apt-get update && apt-get install -y tzdata
ENV TZ=Your/Timezone
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone Not sure it will work but just throwing it out there |
I think there is a fix that can help though. pub fn after_owned<Z: TimeZone>(&self, after: DateTime<Z>) -> OwnedScheduleIterator<Z> {
OwnedScheduleIterator::new(self.clone(), after)
} I will offer the same functionality as here: pub fn to_stream_with_timezone<T: Timezone>(self) -> BoxStream { .. } |
Can't do this since this has to be set at build time, and I want users to be able to configure it at start-time.
Yeah, looks good to me! |
Awesome, this should be fixed in the next release. |
What changes would I have to make?
I would be honored! |
I will document a new api, it will be in the release changelog. |
Cool makes sense. Thanks for your prompt response. |
Hey @geofmureithi any updates on this? |
Hopefully by the end of this month. OSS doesn't pay, I still have to pay my bills you know. |
Sorry if I came off as entitled. I understand. |
Ha, not really entitled. I should have added a smile emoji at the end. (Its just that my focus has been on other projects) |
Hi @geofmureithi. Were you able to get to this? |
Here is a quick solution for your case. trait ToStreamWithTimezone {
fn to_stream_with_timezone(self, tz: Timezone) -> BoxStream;
} Then implement it for |
I am not able to figure out how to use it. Is there any example? |
This is how the implementation would look: impl<J: From<DateTime<TZ>> + Job + Send + 'static, T: Timer + Sync + Send + 'static, TZ> ToStreamWithTimezone for
CronStream<J, T>
{
fn to_stream_with_timezone(self, tz: TZ) -> BoxStream<'static, Result<Option<JobRequest<J>>, JobError>> {
let stream = async_stream::stream! {
let mut schedule = self.0.upcoming_owned(tz);
loop {
let next = schedule.next();
match next {
Some(next) => {
let to_sleep = next - DateTime::<TZ>::now();
let to_sleep = to_sleep.to_std().map_err(|e| JobError::Failed(e.into()))?;
self.2.sleep(to_sleep).await;
yield Ok(Some(JobRequest::new(J::from(DateTime::<TZ>::now()))));
},
None => {
yield Ok(None);
}
}
}
};
stream.boxed()
}
} Let me know if it works, I haven't tested it. |
I could not get it working: IgnisDa/ryot@ae2987f |
What was the error? Let me try to run it locally. |
@geofmureithi I was not able to figure out how to use it. I tried it with Here are the changes I made IgnisDa/ryot@bbb8bdd. |
The compiler is telling you of a missing impl From<DateTimeUtc> for ScheduledJob {
fn from(value: DateTimeUtc) -> Self {
Self(value)
}
} |
@geofmureithi Does not work. |
Give it a try now. |
@geofmureithi Yep this works as expected. I think it can be merged. |
@geofmureithi Could you also publish to crates.io? |
Yeah on it |
Thank you very much for fixing this issue. |
@geofmureithi Were you able to get around to publishing it? |
I have a docker container which inherits from
scratch
. I have an apalis cron job which is supposed to execute at 0000 hrs and 1200 hrs everyday. It does execute but at exactly 0530 hrs for me (I live in Asia/Kolkata timezone which has that offset). How can I configure apalis so that it executes at 0000 hrs of my timezone?Setting the
TZ
env variable does not work, probably due to the scratch docker environment.I'm not really sure if this problem even belongs to this repository, but would love any pointers you'd have on debugging this issue.
The text was updated successfully, but these errors were encountered: