sbrki / clockwork Goto Github PK
View Code? Open in Web Editor NEW⏰ A simple and intuitive scheduling library in Go.
License: MIT License
⏰ A simple and intuitive scheduling library in Go.
License: MIT License
A prior pull request resolved issue #3 but did not remove the EverySingle function or alias it to the Every function. Aliasing preserves backwards compatibility for a period of time until it is removed in a tagged release.
I am new into this library and I would know if there is the possibility to implement multiple scheduled hours using At
method.
Example
sched.Schedule().Every(2).Days().At("9:30").At("11:30").Do(something)
Or
sched.Schedule().Every(2).Days().At([]string{"12:32", "11:30"}).Do(something)
Hi, today wednesday 2019-03-06, i want execute something tomorrow (2019-03-07) and every Thursday , so i use:
s.Schedule().Every().Thursday().Do(dosomething)
but the console log says Scheduled for 2019-03-14, that is the next week
Hi, interesting project. I have some refactoring suggestions.
In your schedule_next_run
function, you have 7 cases, each handling calculating the next run for any given weekday:
case monday:
if j.next_scheduled_run == (time.Time{}) {
now := time.Now()
last_monday_midnight := time.Date(
now.Year(),
now.Month(),
now.Day()-int(now.Weekday()-time.Monday),
0, 0, 0, 0,
time.Local)
if j.use_at == true {
j.next_scheduled_run = last_monday_midnight.Add(
time.Duration(j.at_hour)*time.Hour +
time.Duration(j.at_minute)*time.Minute,
)
} else {
j.next_scheduled_run = last_monday_midnight
}
}
j.next_scheduled_run = j.next_scheduled_run.Add(7 * 24 * time.Hour)
...
You can refactor the body of each case to a function, accepting the Job
-struct and the day of week:
case monday:
getNextScheduleRun(j, time.Monday)
case tuesday:
getNextScheduleRun(j, time.Tuesday)
...
func getNextScheduleRun(job *Job, day_of_week iota) {
if j.next_scheduled_run == (time.Time{}) {
now := time.Now()
last_any_day_midnight := time.Date(
now.Year(),
now.Month(),
now.Day()-int(now.Weekday()-day_of_week),
0, 0, 0, 0,
time.Local)
if j.use_at == true {
j.next_scheduled_run = last_any_day_midnight.Add(
time.Duration(j.at_hour)*time.Hour +
time.Duration(j.at_minute)*time.Minute,
)
} else {
j.next_scheduled_run = last_any_day_midnight
}
}
j.next_scheduled_run = j.next_scheduled_run.Add(7 * 24 * time.Hour)
}
Today is 17th April 2018.
I execute the following command:
sched.Schedule().Every().Day().At("18:00").Do(task)
The result is:
Scheduled for 2019-04-18 18:00:00 +0200 CEST
Why tomorrow and not today?
I don't think that this library is well tested.
I read another issue about weekday.
Per this reddit comment make the Every function variadic.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.