You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.2 KiB
82 lines
2.2 KiB
/* |
|
------------------------------------------------------------------------------------------------------------------------ |
|
####### dune ####### Copyright (c) 2021 losyme ##################################################### MIT License ####### |
|
------------------------------------------------------------------------------------------------------------------------ |
|
*/ |
|
|
|
package model |
|
|
|
import ( |
|
"time" |
|
|
|
"forge.chapril.org/dune/jw" |
|
"forge.chapril.org/losyme/errors" |
|
) |
|
|
|
func (m *Model) insertJob(job *jw.Job) (bool, error) { |
|
done, err := m.Storage.InsertJob(job) |
|
if err != nil { |
|
m.Logger.Error( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
|
"Unable to insert a new job", |
|
append( |
|
job.Fields(), |
|
"reason", err, |
|
)..., |
|
) |
|
|
|
return false, err |
|
} |
|
|
|
if !done { |
|
m.Logger.Notice("A job with the same category already exists", job.Fields()...) //:::::::::::::::::::::::::::::: |
|
return false, nil |
|
} |
|
|
|
m.Logger.Info("New job", job.Fields()...) //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
|
|
|
return true, nil |
|
} |
|
|
|
func (m *Model) CreateJob(job *jw.Job) (*jw.Job, error) { |
|
if err := m.validateJob(job); err != nil { |
|
return nil, errors.Wrap( /////////////////////////////////////////////////////////////////////////////////////// |
|
ErrValidation, |
|
errors.WithMessage(err, "unable to create this job"), |
|
) |
|
} |
|
|
|
done, err := m.insertJob(job) |
|
if err != nil { |
|
return nil, errors.Wrap( /////////////////////////////////////////////////////////////////////////////////////// |
|
ErrInternal, |
|
errors.WithMessage(err, "unable to insert this job"), |
|
) |
|
} |
|
|
|
if done { |
|
return job, nil |
|
} |
|
|
|
return nil, nil |
|
} |
|
|
|
func (m *Model) UpdateJob(job *jw.Job) (*jw.Job, error) { |
|
return job, nil |
|
} |
|
|
|
func (m *Model) NotifyJob(id string, data interface{}) error { |
|
// AFINIR |
|
return nil |
|
} |
|
|
|
func (m *Model) SetJobPriority(id string, priority jw.Priority) error { |
|
return m.Storage.SetJobPriority(id, priority) |
|
} |
|
|
|
func (m *Model) SetJobRunAfter(id string, duration time.Duration) error { |
|
return m.Storage.SetJobRunAfter(id, duration) |
|
} |
|
|
|
/* |
|
######################################################################################################## @(°_°)@ ####### |
|
*/
|
|
|