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

CronExpression not working inside docker #15

Closed
peatle-mibt opened this issue Jun 15, 2022 · 18 comments
Closed

CronExpression not working inside docker #15

peatle-mibt opened this issue Jun 15, 2022 · 18 comments
Assignees
Labels
invalid This doesn't seem right

Comments

@peatle-mibt
Copy link

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?

@burakkoken
Copy link
Member

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 burakkoken self-assigned this Jun 19, 2022
@burakkoken burakkoken added bug Something isn't working critical Critical Bug labels Jun 19, 2022
@peatle-mibt
Copy link
Author

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

@burakkoken
Copy link
Member

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
Copy link
Member

@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
Copy link
Member

burakkoken commented Jul 23, 2022

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

image

@burakkoken
Copy link
Member

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

@peatle-mibt
Copy link
Author

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.

@burakkoken
Copy link
Member

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 burakkoken reopened this Aug 4, 2022
@peatle-mibt
Copy link
Author

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

@burakkoken
Copy link
Member

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

@peatle-mibt
Copy link
Author

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

@burakkoken
Copy link
Member

Hi, You are using release v1.1.2?

@peatle-mibt
Copy link
Author

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

@burakkoken
Copy link
Member

burakkoken commented Sep 28, 2022

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 burakkoken added invalid This doesn't seem right and removed bug Something isn't working critical Critical Bug labels Sep 28, 2022
@peatle-mibt
Copy link
Author

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.

@burakkoken
Copy link
Member

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
Copy link
Member

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

@peatle-mibt
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants