Git Product home page Git Product logo

clockwork's People

Contributors

buoyantair avatar samlitowitz avatar saromanov avatar sbrki avatar whiteshtef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

clockwork's Issues

Alias EverySingle

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.

Question: Multiple At

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)

Weekday problem

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

Refactoring of weekday scheduling

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)
}

Every day at x not working

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.