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

Added latest version #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Job struct {
SkipWait chan bool
err error
schedule scheduled
NextRun time.Time
isRunning bool
sync.RWMutex
}
Expand Down Expand Up @@ -183,10 +184,24 @@ func (j *Job) RunWithArgs(f func(args []string), args []string) (*Job, error) {
return j.startLoop()
}

// RunNow runs a job one time immediately.
func (j *Job) RunNow(f func()) {
j.fn = f
go runJob(j)
}

// RunNowWithArgs runs a job one time immediately.
func (j *Job) RunNowWithArgs(f func(args []string), args []string) {
j.fni = f
j.args = args
go runJob(j)
}

func (j *Job) startLoop() (*Job, error) {
var next time.Duration
var err error
next, err = j.schedule.nextRun()
j.NextRun = time.Now().Add(next)
if err != nil {
return nil, err
}
Expand All @@ -201,6 +216,7 @@ func (j *Job) startLoop() (*Job, error) {
go runJob(j)
}
next, _ = j.schedule.nextRun()
j.NextRun = time.Now().Add(next)
}
}(j)
return j, nil
Expand Down