chrono icon indicating copy to clipboard operation
chrono copied to clipboard

CronExpression not working inside docker

Open peatle-mibt opened this issue 3 years ago • 9 comments

CronExpression can be scheduled but never gets executed.

method: ScheduleWithCron(..., ..., chrono.WithLocation("Europe/Berlin")) expression: does not matter, also */1 * * * * not working docker-file to build and run:

# The base go-image
FROM golang:1.18-alpine as build
# Create a directory for the app
RUN mkdir /app
 # Copy all files from the current directory to the app directory
COPY ./src /app
 # Set working directory
WORKDIR /app
# go build will build an executable file named tics in the current directory
RUN go build -o tics
FROM alpine:latest AS bin
# copy from temporary "build"-image to the current
copy --from=build /app/tics /tics
copy ./tics.yml /tics.yml
EXPOSE 3222
RUN /bin/sh
# Run the tics executable
ENTRYPOINT ./tics

running the same source outside docker as an executable works.

do you have any ideas?

peatle-mibt avatar Jun 15 '22 10:06 peatle-mibt

I don’t have any idea about this problem. but thank you for letting me know that. I’m gonna investigate the root cause of the problem.

burakkoken avatar Jun 19 '22 13:06 burakkoken

did you had time to investigate or need more information? Thank you

peatle-mibt avatar Jul 18 '22 08:07 peatle-mibt

I could not have enough time for the investigation because of my workload. this week, I hope I have enough time for figuring out the problem.

burakkoken avatar Jul 18 '22 17:07 burakkoken

@peatle-mibt It seems your cron expression you are using is wrong, when I try to schedule a function with the same cron expression, I got an error like saying cron expression must consist of 6 fields. Can you please try to fix your cron expression and try it again? Sorry for late checking the issue. Please also let me know if you have any problem.

burakkoken avatar Jul 23 '22 19:07 burakkoken

@peatle-mibt your cron expression should be */1 * * * * *. I'm closing the issue. :)

image

burakkoken avatar Jul 23 '22 19:07 burakkoken

It turns out this is not an issue because the cron expression used is wrong. so this issue will be closed.

burakkoken avatar Jul 23 '22 19:07 burakkoken

I'm sorry, but this was a mistake in the description. it is still not working. From my log when starting:

2022-07-25 08:30:14.921 [INFO] starting reminder service with cron expression */1 * * * * *

I don't see any error in the log and i don't see any msg saying that my scheduled method is called. The method called with ScheduleWithFixedDelay is working. As I said, this only happens inside a docker container.

peatle-mibt avatar Jul 25 '22 08:07 peatle-mibt

I also tried to schedule a task with the expression you specified inside docker. It worked for me. Could you give me some code snippets for investigation? I just reopened this issue.

burakkoken avatar Aug 04 '22 19:08 burakkoken

strange...my code that I tested is:

Scheduler := chrono.NewDefaultTaskScheduler()
	Scheduler.ScheduleWithCron(func(ctx context.Context) {
		log.Info("ping cron")
	}, "*/1 * * * * *", chrono.WithLocation("Europe/Berlin"))
	Scheduler.ScheduleWithFixedDelay(func(ctx context.Context) {
		log.Info("ping delay")
	}, time.Duration(5000*int(time.Millisecond)))

ping delay gets printed, the other not. in windows and with vscode it works.

The OS for docker Linux 5.10.0-13-amd64 #1 SMP Debian 5.10.106-1 (2022-03-17) x86_64 GNU/Linux

docker version: Docker version 20.10.5+dfsg1, build 55c4c88

peatle-mibt avatar Aug 15 '22 09:08 peatle-mibt

Hi @peatle-mibt Can you please confirm that the issue has been resolved with release v1.1.2?

burakkoken avatar Sep 28 '22 09:09 burakkoken

Hello. I can confirm that it works without using a location, but with location it isn't.

peatle-mibt avatar Sep 28 '22 12:09 peatle-mibt

Hi, You are using release v1.1.2?

burakkoken avatar Sep 28 '22 12:09 burakkoken

yes I do. I also tried it within ubuntu 22.04 but no luck, sorry.

peatle-mibt avatar Sep 28 '22 13:09 peatle-mibt

I found the root cause of the problem, it occurs because timezone data is missing in container and it cannot load location info.

If you add the following line in your Dockerfile,

RUN apk add —no—cache tzdata

It should work as expected.

Can you please try this solution?

burakkoken avatar Sep 28 '22 16:09 burakkoken

thank you!!! that did the trick, so it is an docker/image problem, not with your code. But maybe it would be possible to show some kind of error or warning when location info is not available.

peatle-mibt avatar Sep 28 '22 16:09 peatle-mibt

You’re welcome. Right, it was an issue with Docker image.

Actually, when I tried this, schedule function was returning an error saying error: could not load time location .

You can check returned error value after scheduling.

burakkoken avatar Sep 28 '22 16:09 burakkoken

It turns out this is not an issue with chrono. So this issue will be closed

burakkoken avatar Sep 28 '22 18:09 burakkoken

I see. that's little weird about golang, errors can be ignored without explicitly doing so.

peatle-mibt avatar Sep 29 '22 07:09 peatle-mibt