-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
56 lines (47 loc) · 1.23 KB
/
job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package schedly
import (
"sync"
"time"
)
/*job represents a configuration of a task scheduled for execution
*/
type job struct {
jobFunc func()
name string
lastRun time.Time
lastFinish time.Time
exclusive bool
lock sync.Mutex
}
/*Name returns the job name*/
func (j *job) Name() string {
return j.name
}
/*LastFinish return the last time the job finished execution*/
func (j *job) LastFinish() time.Time {
return j.lastFinish
}
/*LastRun returns the last time the job has been launched*/
func (j *job) LastRun() time.Time {
return j.lastRun
}
/*Exclusive returns Exclusive setting of the job. When 'true' it prevents from running multiple instances of the job at the same time*/
func (j *job) Exclusive() bool {
return j.exclusive
}
/*SetExclusive configures Exclusive mode. When 'true' it prevents from running multiple instances of the job at the same time*/
func (j *job) SetExclusive(exclusive bool) *job {
j.exclusive = exclusive
return j
}
/* Run the job.
Parameter `tick` is time from internal ticker. Last job run time is set to this value before launch*/
func (j *job) Run(tick time.Time) {
j.lastRun = tick
if j.exclusive {
j.lock.Lock()
defer j.lock.Unlock()
}
j.jobFunc()
j.lastFinish = time.Now()
}