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

add support for generic FunctionJob #37

Merged
merged 2 commits into from Nov 19, 2022
Merged

Conversation

neomantra
Copy link
Contributor

Expand the suite of Jobs to include plain Golang functions, including their closures.

You can create a FunctionJob like so:

n = 0
job := quartz.NewFunctionJob(func() (int, error) {
    n = n + 1
    return n, nil
}
// later on access results
println(job.JobStatus, job.Result)

The other Jobs either shell out or hit endpoint with cron. It is also useful to invoke Go functions. For example, various periodic cleanup tasks for a service.

This simple,. type-safe implementation requires generic support in Go, available in Go 1.18. Note that the library user doesn't need to deal with generics and types at all.

Expand the suite of Jobs to include plain Golang
functions, including their closures.

You can create a FunctionJob like so:
```
job := quartz.NewFunctionJob(func() (int, error) {
    return 42, nil
}
// later on access results
println(job.JobStatus, job.Result)
````
@codecov-commenter
Copy link

Codecov Report

Merging #37 (bcd0493) into master (8d78d00) will decrease coverage by 1.07%.
The diff coverage is 51.72%.

@@            Coverage Diff             @@
##           master      #37      +/-   ##
==========================================
- Coverage   84.45%   83.38%   -1.08%     
==========================================
  Files           6        7       +1     
  Lines         592      620      +28     
==========================================
+ Hits          500      517      +17     
- Misses         62       71       +9     
- Partials       30       32       +2     
Impacted Files Coverage Δ
quartz/function_job.go 50.00% <50.00%> (ø)
quartz/job.go 88.88% <100.00%> (ø)
quartz/scheduler.go 90.69% <0.00%> (+2.32%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@reugn reugn changed the base branch from master to develop November 19, 2022 10:21
@reugn reugn merged commit 051119e into reugn:develop Nov 19, 2022
@neomantra
Copy link
Contributor Author

Thanks for merging!

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

Successfully merging this pull request may close these issues.

None yet

3 participants