This is an automated email from the ASF dual-hosted git repository.

mappjzc pushed a commit to branch release-v0.16
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/release-v0.16 by this push:
     new ad6b5ab98 fix: fix cron (#4788)
ad6b5ab98 is described below

commit ad6b5ab9857a31eb35dbf918ed4e0160f0888a3b
Author: mappjzc <[email protected]>
AuthorDate: Mon Mar 27 22:13:40 2023 +0800

    fix: fix cron (#4788)
    
    Fix cron use error blueprint to run pipelines.
    
    Nddtfjiang <[email protected]>
---
 backend/server/services/blueprint.go | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/backend/server/services/blueprint.go 
b/backend/server/services/blueprint.go
index 17819f133..7b24b4814 100644
--- a/backend/server/services/blueprint.go
+++ b/backend/server/services/blueprint.go
@@ -43,6 +43,20 @@ var (
        blueprintLog = logruslog.Global.Nested("blueprint")
 )
 
+type BlueprintJob struct {
+       Blueprint *models.Blueprint
+}
+
+func (bj BlueprintJob) Run() {
+       blueprint := bj.Blueprint
+       pipeline, err := createPipelineByBlueprint(blueprint)
+       if err != nil {
+               blueprintLog.Error(err, fmt.Sprintf("run cron job failed on 
blueprint:[%d][%s]", blueprint.ID, blueprint.Name))
+       } else {
+               blueprintLog.Info("Run new cron job successfully,blueprint 
id:[%d] pipeline id:[%d]", blueprint.ID, pipeline.ID)
+       }
+}
+
 // CreateBlueprint accepts a Blueprint instance and insert it to database
 func CreateBlueprint(blueprint *models.Blueprint) errors.Error {
        err := validateBlueprintAndMakePlan(blueprint)
@@ -220,14 +234,13 @@ func ReloadBlueprints(c *cron.Cron) errors.Error {
                        blueprintLog.Error(err, failToCreateCronJob)
                        return err
                }
-               if _, err := c.AddFunc(blueprint.CronConfig, func() {
-                       pipeline, err := createPipelineByBlueprint(blueprint)
-                       if err != nil {
-                               blueprintLog.Error(err, fmt.Sprintf("run cron 
job failed on blueprint:[%d][%s]", blueprint.ID, blueprint.Name))
-                       } else {
-                               blueprintLog.Info("Run new cron job 
successfully,pipeline id:[%d] pipeline id:[%d]", blueprint.ID, pipeline.ID)
-                       }
-               }); err != nil {
+
+               blueprintLog.Info("Add blueprint id:[%d] cronConfg[%s] to cron 
job", blueprint.ID, blueprint.CronConfig)
+               blueprintJob := &BlueprintJob{
+                       Blueprint: blueprint,
+               }
+
+               if _, err := c.AddJob(blueprint.CronConfig, blueprintJob); err 
!= nil {
                        blueprintLog.Error(err, failToCreateCronJob)
                        return errors.Default.Wrap(err, "created cron job 
failed")
                }

Reply via email to