mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-22 00:13:52 +01:00
jobrun: error handling through notification channel
This commit is contained in:
parent
9fdd1ea909
commit
226935ddea
@ -10,11 +10,13 @@ type Job struct {
|
||||
Name string
|
||||
RunFunc func() (err error)
|
||||
LastStart time.Time
|
||||
LastError error
|
||||
Interval time.Duration
|
||||
Repeats bool
|
||||
}
|
||||
|
||||
type JobRunner struct {
|
||||
notificationChan chan Job
|
||||
newJobChan chan Job
|
||||
finishedJobChan chan Job
|
||||
scheduleTimer <-chan time.Time
|
||||
@ -24,6 +26,7 @@ type JobRunner struct {
|
||||
|
||||
func NewJobRunner() *JobRunner {
|
||||
return &JobRunner{
|
||||
notificationChan: make(chan Job),
|
||||
newJobChan: make(chan Job),
|
||||
finishedJobChan: make(chan Job),
|
||||
pending: make(map[string]Job),
|
||||
@ -39,6 +42,10 @@ func (r *JobRunner) AddJob(j Job) {
|
||||
r.newJobChan <- j
|
||||
}
|
||||
|
||||
func (r *JobRunner) NotificationChan() <-chan Job {
|
||||
return r.notificationChan
|
||||
}
|
||||
|
||||
func (r *JobRunner) Start() {
|
||||
|
||||
loop:
|
||||
@ -104,7 +111,8 @@ loop:
|
||||
|
||||
go func(job Job) {
|
||||
if err := job.RunFunc(); err != nil {
|
||||
panic(fmt.Sprintf("%#v", err)) // TODO better policy, store in job + notification channel?
|
||||
job.LastError = err
|
||||
r.notificationChan <- job
|
||||
}
|
||||
r.finishedJobChan <- job
|
||||
}(job)
|
||||
|
Loading…
Reference in New Issue
Block a user