mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
feat: updated notification settings and channels
This commit is contained in:
@@ -522,14 +522,12 @@ func (r *RunnerV2) updateTask(status string, e error) (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// update stats
|
||||
r._updateTaskStat(status)
|
||||
r._updateSpiderStat(status)
|
||||
|
||||
// send notification
|
||||
go r.sendNotification()
|
||||
|
||||
// update stats
|
||||
go func() {
|
||||
r._updateTaskStat(status)
|
||||
r._updateSpiderStat(status)
|
||||
}()
|
||||
}
|
||||
|
||||
// get task
|
||||
@@ -579,15 +577,15 @@ func (r *RunnerV2) _updateTaskStat(status string) {
|
||||
// do nothing
|
||||
case constants.TaskStatusRunning:
|
||||
ts.StartTs = time.Now()
|
||||
ts.WaitDuration = ts.StartTs.Sub(ts.CreateTs).Milliseconds()
|
||||
ts.WaitDuration = ts.StartTs.Sub(ts.BaseModelV2.CreatedAt).Milliseconds()
|
||||
case constants.TaskStatusFinished, constants.TaskStatusError, constants.TaskStatusCancelled:
|
||||
if ts.StartTs.IsZero() {
|
||||
ts.StartTs = time.Now()
|
||||
ts.WaitDuration = ts.StartTs.Sub(ts.CreateTs).Milliseconds()
|
||||
ts.WaitDuration = ts.StartTs.Sub(ts.BaseModelV2.CreatedAt).Milliseconds()
|
||||
}
|
||||
ts.EndTs = time.Now()
|
||||
ts.RuntimeDuration = ts.EndTs.Sub(ts.StartTs).Milliseconds()
|
||||
ts.TotalDuration = ts.EndTs.Sub(ts.CreateTs).Milliseconds()
|
||||
ts.TotalDuration = ts.EndTs.Sub(ts.BaseModelV2.CreatedAt).Milliseconds()
|
||||
}
|
||||
if r.svc.GetNodeConfigService().IsMaster() {
|
||||
err = service2.NewModelServiceV2[models2.TaskStatV2]().ReplaceById(ts.Id, *ts)
|
||||
|
||||
@@ -39,12 +39,12 @@ func (svc *ServiceV2) Start() {
|
||||
func (svc *ServiceV2) Enqueue(t *models2.TaskV2, by primitive.ObjectID) (t2 *models2.TaskV2, err error) {
|
||||
// set task status
|
||||
t.Status = constants.TaskStatusPending
|
||||
t.SetCreatedBy(by)
|
||||
t.SetCreated(by)
|
||||
t.SetUpdated(by)
|
||||
|
||||
// add task
|
||||
taskModelSvc := service.NewModelServiceV2[models2.TaskV2]()
|
||||
_, err = taskModelSvc.InsertOne(*t)
|
||||
id, err := taskModelSvc.InsertOne(*t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -54,13 +54,15 @@ func (svc *ServiceV2) Enqueue(t *models2.TaskV2, by primitive.ObjectID) (t2 *mod
|
||||
Priority: t.Priority,
|
||||
NodeId: t.NodeId,
|
||||
}
|
||||
tq.SetId(t.Id)
|
||||
tq.SetId(id)
|
||||
tq.SetCreated(by)
|
||||
tq.SetUpdated(by)
|
||||
|
||||
// task stat
|
||||
ts := models2.TaskStatV2{
|
||||
CreateTs: time.Now(),
|
||||
}
|
||||
ts.SetId(t.Id)
|
||||
ts := models2.TaskStatV2{}
|
||||
ts.SetId(id)
|
||||
ts.SetCreated(by)
|
||||
ts.SetUpdated(by)
|
||||
|
||||
// enqueue task
|
||||
_, err = service.NewModelServiceV2[models2.TaskQueueItemV2]().InsertOne(tq)
|
||||
|
||||
Reference in New Issue
Block a user