reugn / go-quartz

Minimalist and zero-dependency scheduling library for Go
https://pkg.go.dev/github.com/reugn/go-quartz/quartz
MIT License
1.8k stars 85 forks source link

add support for generic FunctionJob #37

Closed neomantra closed 2 years ago

neomantra commented 2 years ago

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.

codecov-commenter commented 2 years ago

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%) :arrow_up:

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

neomantra commented 2 years ago

Thanks for merging!