From a03babb8b64e4e0dda737ce8ee9eaad42135ad7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Wed, 31 Aug 2022 14:53:25 +0800 Subject: [PATCH] - add StartTask func - add StartTaskCustom func --- const.go | 2 +- jobs_gorm_model.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/const.go b/const.go index 9ce836e..78f271d 100644 --- a/const.go +++ b/const.go @@ -1,3 +1,3 @@ package gojobs -const Version = "1.0.67" +const Version = "1.0.68" diff --git a/jobs_gorm_model.go b/jobs_gorm_model.go index 3fd6dbf..2eb4334 100644 --- a/jobs_gorm_model.go +++ b/jobs_gorm_model.go @@ -124,6 +124,29 @@ func (j *JobsGorm) TaskFindAllWait(tx *gorm.DB, frequency int64) []jobs_gorm_mod return j.taskFindAll(tx, frequency, TASK_WAIT) } +// StartTask 任务启动 +func (j *JobsGorm) StartTask(tx *gorm.DB, id uint) error { + return j.EditTask(tx, id). + Select("status", "status_desc"). + Updates(jobs_gorm_model.Task{ + Status: TASK_IN, + StatusDesc: "启动任务", + }).Error +} + +// StartTaskCustom 任务启动自定义 +func (j *JobsGorm) StartTaskCustom(tx *gorm.DB, customId string, customSequence int64) error { + return tx.Model(&jobs_gorm_model.Task{}). + Where("custom_id = ?", customId). + Where("custom_sequence = ?", customSequence). + Where("status = ?", TASK_WAIT). + Select("status", "status_desc"). + Updates(jobs_gorm_model.Task{ + Status: TASK_IN, + StatusDesc: "启动任务", + }).Error +} + // EditTask 任务修改 func (j *JobsGorm) EditTask(tx *gorm.DB, id uint) *gorm.DB { return tx.Model(&jobs_gorm_model.Task{}).Where("id = ?", id)