diff --git a/CHANGELOG.md b/CHANGELOG.md index 72dabe4..5ab47cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.1.5] - 2023-12-09 + +### Added + +- Support `log.Logger` contract on Echo Framework. + +### Fixed + +- Fix invalid Schedule Timing caused by `cron.WithSecond()` by adding "0" in front of expression. + ## [1.1.4] - 2023-12-01 ### Fixed @@ -53,6 +63,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support `Schedule` feature. - Support `Queue` feature +[1.1.5]: https://github.com/fwidjaya20/symphonic/compare/v1.1.4...v1.1.5 [1.1.4]: https://github.com/fwidjaya20/symphonic/compare/v1.1.3...v1.1.4 [1.1.3]: https://github.com/fwidjaya20/symphonic/compare/v1.1.2...v1.1.3 [1.1.2]: https://github.com/fwidjaya20/symphonic/compare/v1.1.1...v1.1.2 diff --git a/contracts/schedule/job.go b/contracts/schedule/job.go index 24cb389..3cb21de 100644 --- a/contracts/schedule/job.go +++ b/contracts/schedule/job.go @@ -26,6 +26,9 @@ type Job interface { Hourly() Job HourlyAt(atMinutes ...string) Job Daily() Job + DailyAt(atHours ...string) Job Weekly() Job + WeeklyAt(atDaysOfWeek ...string) Job Monthly() Job + MonthlyAt(atDaysOfMonth ...string) Job } diff --git a/schedule/job.go b/schedule/job.go index 79305dc..255df89 100644 --- a/schedule/job.go +++ b/schedule/job.go @@ -19,9 +19,6 @@ func NewJob(callback func()) schedule.Job { } func (j *Job) SetTiming(expression string) schedule.Job { - if len(strings.Split(expression, " ")) == 5 { - expression = "0 " + expression - } j.timing = expression return j } @@ -71,56 +68,77 @@ func (j *Job) EveryThirtySecond() schedule.Job { } func (j *Job) EveryMinute() schedule.Job { - return j.SetTiming("* * * * *") + return j.SetTiming("0 * * * * *") } func (j *Job) EveryTwoMinute() schedule.Job { - return j.SetTiming("*/2 * * * *") + return j.SetTiming("0 */2 * * * *") } func (j *Job) EveryThreeMinute() schedule.Job { - return j.SetTiming("*/3 * * * *") + return j.SetTiming("0 */3 * * * *") } func (j *Job) EveryFourMinute() schedule.Job { - return j.SetTiming("*/4 * * * *") + return j.SetTiming("0 */4 * * * *") } func (j *Job) EveryFiveMinute() schedule.Job { - return j.SetTiming("*/5 * * * *") + return j.SetTiming("0 */5 * * * *") } func (j *Job) EveryTenMinute() schedule.Job { - return j.SetTiming("*/10 * * * *") + return j.SetTiming("0 */10 * * * *") } func (j *Job) EveryFifteenMinute() schedule.Job { - return j.SetTiming("*/15 * * * *") + return j.SetTiming("0 */15 * * * *") } func (j *Job) EveryThirtyMinute() schedule.Job { - return j.SetTiming("*/30 * * * *") + return j.SetTiming("0 */30 * * * *") } func (j *Job) Hourly() schedule.Job { - return j.SetTiming("0 * * * *") + return j.SetTiming("0 0 * * * *") } func (j *Job) HourlyAt(atMinutes ...string) schedule.Job { if len(atMinutes) > 0 { - return j.SetTiming(fmt.Sprintf("%s * * * *", strings.Join(atMinutes, ","))) + return j.SetTiming(fmt.Sprintf("0 %s * * * *", strings.Join(atMinutes, ","))) } return j.Hourly() } func (j *Job) Daily() schedule.Job { - return j.SetTiming("0 0 * * *") + return j.SetTiming("0 0 0 * * *") +} + +func (j *Job) DailyAt(atHours ...string) schedule.Job { + if len(atHours) > 0 { + return j.SetTiming(fmt.Sprintf("0 0 %s * * *", strings.Join(atHours, ","))) + } + return j.Daily() } func (j *Job) Weekly() schedule.Job { - return j.SetTiming("0 0 * * 0") + return j.SetTiming("0 0 0 * * 0") +} + +func (j *Job) WeeklyAt(atDaysOfWeek ...string) schedule.Job { + if len(atDaysOfWeek) > 0 { + return j.SetTiming(fmt.Sprintf("0 0 0 * * %s", strings.Join(atDaysOfWeek, ","))) + } + return j.Weekly() } func (j *Job) Monthly() schedule.Job { - return j.SetTiming("0 0 1 * *") + return j.SetTiming("0 0 0 1 * *") +} + +func (j *Job) MonthlyAt(atDaysOfMonth ...string) schedule.Job { + if len(atDaysOfMonth) > 0 { + return j.SetTiming(fmt.Sprintf("0 0 0 %s * *", strings.Join(atDaysOfMonth, ","))) + } + return j.Monthly() } diff --git a/schedule/service_provider.go b/schedule/service_provider.go index 2c724c3..1922946 100644 --- a/schedule/service_provider.go +++ b/schedule/service_provider.go @@ -12,6 +12,6 @@ func (sp *ServiceProvider) Boot(app foundation.Application) {} func (sp *ServiceProvider) Register(app foundation.Application) { app.Instance(Binding, func(app foundation.Application) (any, error) { - return NewApplication(), nil + return NewApplication(app.GetLogger()), nil }) }