mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-25 11:21:02 +00:00
Only update agent.LastWork if not done recently (#4031)
This commit is contained in:
parent
bcecbbd398
commit
b8c1d68eb1
1 changed files with 20 additions and 8 deletions
|
@ -98,8 +98,7 @@ func (s *RPC) Extend(c context.Context, workflowID string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
agent.LastWork = time.Now().Unix()
|
||||
err = s.store.AgentUpdate(agent)
|
||||
err = s.updateAgentLastWork(agent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -237,8 +236,7 @@ func (s *RPC) Init(c context.Context, strWorkflowID string, state rpc.WorkflowSt
|
|||
}
|
||||
s.updateForgeStatus(c, repo, currentPipeline, workflow)
|
||||
|
||||
agent.LastWork = time.Now().Unix()
|
||||
return s.store.AgentUpdate(agent)
|
||||
return s.updateAgentLastWork(agent)
|
||||
}
|
||||
|
||||
// Done marks the workflow with the given ID as done.
|
||||
|
@ -331,8 +329,7 @@ func (s *RPC) Done(c context.Context, strWorkflowID string, state rpc.WorkflowSt
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
agent.LastWork = time.Now().Unix()
|
||||
return s.store.AgentUpdate(agent)
|
||||
return s.updateAgentLastWork(agent)
|
||||
}
|
||||
|
||||
// Log writes a log entry to the database and publishes it to the pubsub.
|
||||
|
@ -362,8 +359,9 @@ func (s *RPC) Log(c context.Context, rpcLogEntry *rpc.LogEntry) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
agent.LastWork = time.Now().Unix()
|
||||
if err := s.store.AgentUpdate(agent); err != nil {
|
||||
|
||||
err = s.updateAgentLastWork(agent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -510,3 +508,17 @@ func (s *RPC) getHostnameFromContext(ctx context.Context) (string, error) {
|
|||
}
|
||||
return "", errors.New("no hostname in metadata")
|
||||
}
|
||||
|
||||
func (s *RPC) updateAgentLastWork(agent *model.Agent) error {
|
||||
// only update agent.LastWork if not done recently
|
||||
if time.Unix(agent.LastWork, 0).Add(1 * time.Minute).Before(time.Now()) {
|
||||
return nil
|
||||
}
|
||||
|
||||
agent.LastWork = time.Now().Unix()
|
||||
if err := s.store.AgentUpdate(agent); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue