add updateExecutionTime

task/v1.0.8
git 2025-12-13 16:37:51 +08:00
parent 334117d67f
commit 792c7be92a
Signed by: git
GPG Key ID: 3F65EFFA44207ADD
1 changed files with 16 additions and 0 deletions

View File

@ -44,6 +44,14 @@ func NewContext(ctx context.Context, store istore.Store, task *types.Task, curre
}
}
// updateExecutionTime update task and step execution time when update operation
func (c *Context) updateExecutionTime() {
now := time.Now()
c.task.SetExecutionTime(c.task.Start, now)
c.currentStep.SetExecutionTime(c.currentStep.Start, now)
}
// Context returns the step's context
func (c *Context) Context() context.Context {
return c.ctx
@ -92,6 +100,8 @@ func (c *Context) GetCommonParam(key string) (string, bool) {
// AddCommonParam add task common param and save to store
func (c *Context) AddCommonParam(k, v string) error {
_ = c.task.AddCommonParam(k, v)
c.updateExecutionTime()
return c.store.UpdateTask(c.ctx, c.task)
}
@ -105,6 +115,7 @@ func (c *Context) SetCommonPayload(obj any) error {
if err := c.task.SetCommonPayload(obj); err != nil {
return err
}
c.updateExecutionTime()
return c.store.UpdateTask(c.ctx, c.task)
}
@ -132,6 +143,8 @@ func (c *Context) GetParam(key string) (string, bool) {
// AddParam set step param by key,value and save to store
func (c *Context) AddParam(key string, value string) error {
_ = c.currentStep.AddParam(key, value)
c.updateExecutionTime()
return c.store.UpdateTask(c.ctx, c.task)
}
@ -143,6 +156,8 @@ func (c *Context) GetParams() map[string]string {
// SetParams set all step params and save to store
func (c *Context) SetParams(params map[string]string) error {
c.currentStep.SetParams(params)
c.updateExecutionTime()
return c.store.UpdateTask(c.ctx, c.task)
}
@ -161,6 +176,7 @@ func (c *Context) SetPayload(obj any) error {
if err := c.currentStep.SetPayload(obj); err != nil {
return err
}
c.updateExecutionTime()
return c.store.UpdateTask(c.ctx, c.task)
}