diff --git a/src/jobservice_v2/env/job_context.go b/src/jobservice_v2/env/job_context.go index 03996c277..9df2bbe50 100644 --- a/src/jobservice_v2/env/job_context.go +++ b/src/jobservice_v2/env/job_context.go @@ -9,9 +9,12 @@ import "context" type JobContext interface { //Build the context // + //dep JobData : Dependencies for building the context, just in case that the build + //function need some external info + // //Returns: // error if meet any problems - Build() error + Build(dep JobData) error //Get property from the context // @@ -27,3 +30,10 @@ type JobContext interface { // context.Context SystemContext() context.Context } + +//JobData defines job context dependencies. +type JobData struct { + ID string + Name string + Args map[string]interface{} +} diff --git a/src/jobservice_v2/job/impl/context.go b/src/jobservice_v2/job/impl/context.go index 2ed0cd4d4..60e15048c 100644 --- a/src/jobservice_v2/job/impl/context.go +++ b/src/jobservice_v2/job/impl/context.go @@ -4,6 +4,7 @@ import ( "context" hlog "github.com/vmware/harbor/src/common/utils/log" + "github.com/vmware/harbor/src/jobservice_v2/env" ) //Context ... @@ -22,8 +23,14 @@ func NewContext(sysCtx context.Context) *Context { } } +//InitDao ... +func (c *Context) InitDao() error { + return nil +} + //Build implements the same method in env.JobContext interface -func (c *Context) Build() error { +//This func will build the job execution context before running +func (c *Context) Build(dep env.JobData) error { return nil } diff --git a/src/jobservice_v2/job/redis_job_wrapper.go b/src/jobservice_v2/job/redis_job_wrapper.go index 41fa2873e..b8125f437 100644 --- a/src/jobservice_v2/job/redis_job_wrapper.go +++ b/src/jobservice_v2/job/redis_job_wrapper.go @@ -22,6 +22,16 @@ func NewRedisJob(j interface{}, ctx *env.Context) *RedisJob { //Run the job func (rj *RedisJob) Run(j *work.Job) error { + //Build job execution context + jData := env.JobData{ + ID: j.ID, + Name: j.Name, + Args: j.Args, + } + if err := rj.context.JobContext.Build(jData); err != nil { + return err + } + //Inject data runningJob := rj.Wrap() runningJob.SetContext(rj.context.JobContext) @@ -37,6 +47,7 @@ func (rj *RedisJob) Run(j *work.Job) error { //TODO: //If error is stopped error, update status to 'Stopped' and return nil //If error is cancelled error, update status to 'Cancelled' and return err + //Need to consider how to rm the retry option return err } diff --git a/src/jobservice_v2/runtime/bootstrap.go b/src/jobservice_v2/runtime/bootstrap.go index c7d03a461..56f231af0 100644 --- a/src/jobservice_v2/runtime/bootstrap.go +++ b/src/jobservice_v2/runtime/bootstrap.go @@ -46,7 +46,7 @@ func (bs *Bootstrap) LoadAndRun(configFile string, detectEnv bool) { //Build specified job context jobCtx := impl.NewContext(ctx) - if err := jobCtx.Build(); err != nil { + if err := jobCtx.InitDao(); err != nil { log.Errorf("Failed to build job conetxt with error: %s\n", err) return }