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

implement @start job #52

Closed
wants to merge 1 commit into from
Closed

implement @start job #52

wants to merge 1 commit into from

Conversation

phin1x
Copy link

@phin1x phin1x commented Jun 19, 2019

this pull request implements the issue #30
the start jobs will be executed first in parallel and must complete to start the regular jobs.

@phin1x phin1x requested a review from krallin as a code owner June 19, 2019 16:53
@phin1x phin1x changed the title implemented @start job implement @start job Jun 19, 2019
@tommie
Copy link

tommie commented May 24, 2020

@krallin This would be a useful addition. Is anything missing to have this reviewed?

Copy link
Collaborator

@krallin krallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing. I'm sorry this took so long to review — this hadn't really been on my radar at all :(

I left some suggestions inline. If you'd like to make those, let me know. Otherwise, considering how long we've kept you waiting, I'm happy to finish this up for you. Let me know.

Thanks!

@@ -100,11 +100,18 @@ func ParseCrontab(reader io.Reader) (*Crontab, error) {
continue
}

jobLine, err := parseJobLine(line)
// replace start with so the line will parse without errors
jobLine, err := parseJobLine(strings.Replace(line, StartExpressionValue, "0 0 0 1 1 * *", 1))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to call parseJobLine if we're not really trying to parse a cron expression here? If the job line starts with @start, how about we just split that out and return a crontab line directly, as opposed to roundtrip through parseJobLine with dummy data?

Comment on lines +146 to +149
if expression == crontab.StartExpr {
fn(nextRun, logger)
return
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather handle this purely within the expression interface. Right now, this feels a little hacky, and as a result it means start jobs will not get to finish if you CTRL+C (jobWg.Wait() won't wait for anything and wg.Done() will be called immediately). We also, get incomplete logging.

To do this cleanly, I think we need 2 changes to the interface for expression.Next():

  • Give it a counter of how many times we have gone through this loop already (we ahve this variable in cronIteration already).
  • Return a pointer to a time, then we can check for null and break out of this loop if null.

"job.command": job.Command,
"job.position": job.Position,
})
if firstRun {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather keep the code a little simpler and re-run the start jobs if you reload the crontab.

There are 2 reasons for this:

  • First, it keeps the code simpler. We don't need 2 blocks to run start jobs and regular jobs separately, etc.
  • It enables the user to do more. With the approach you have here, you cannot run @start jobs when reloading the crontab. With the approach I'm proposing, you can choose to not run them (remove them from the crontab before reloading), or to run them (don't remove them).

@start might be a bit un-ideal as a name then. In the issue folks were mentioning using @reboot. I think that'd work well here.

Copy link

@hongkongkiwi hongkongkiwi Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I think restarting the cron jobs when container restarts is very reasonable. Could we get this into the main code? I really would like to use it and keep using the mainline code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it is not a good idea to run all @start jobs again on a reload. if i decleare a job with @start i want the job to run only once at container start.
if we want to be compatible with other cron scheduler we should use @reboot.
if the job should be executed every time the crontab is reloaded, @reboot is a bad name option. mabye @reload is a better option to make it clear, but I'm not happy with it either.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike the other review comments, it seems this needs a decision, on two points:

  • Name. I agree that compatibility with @reboot sounds like a good idea, rather than a custom @start.
  • Whether to run on reload or not. For compatibility with other cron systems, I agree it should not run on reload. This code could probably be simplified. There's no "on load" functionality in Vixie's crontab, so I don't understand why the flexibility would be worth having (without a specific usecase.) That said, I store the crontab in container images, so I never use reload.

@hongkongkiwi
Copy link

Can we get this merged? Any reason it's still pending? Looks like the project is getting updates and this solves the issue.

@phin1x
Copy link
Author

phin1x commented Sep 5, 2020

currently I do not have time to implement the requested changes, maybe towards the end of the year

@phin1x
Copy link
Author

phin1x commented Sep 6, 2020

@krallin if you would complete the pr I would be very happy

@neurosnap
Copy link
Member

At this point we do not have the bandwidth to carry this feature to the finish line. However, If someone would like to pick this back up we would happily review it.

@phin1x phin1x closed this Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants