Skip to content

Commit

Permalink
WatchDog
Browse files Browse the repository at this point in the history
Creating the WatchDog when the execution starts and every 30 minutes checks the execution status, if it has not finished, schedule it again in 30 minutes

Signed-off-by: Rodrigo Nardi <[email protected]>
  • Loading branch information
RodrigoMNardi committed Jan 9, 2025
1 parent 7b8d530 commit 417bdf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 11 additions & 0 deletions lib/github/build/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def create_summary(rerun: false)

logger(Logger::INFO, "@jobs - #{@jobs.inspect}")
create_jobs(rerun)
create_timeout_worker
end

private
Expand All @@ -60,6 +61,16 @@ def create_jobs(rerun)
end
end

def create_timeout_worker
Delayed::Job.where('handler LIKE ?', "%TimeoutExecution%args%-%#{@check_suite.id}%").delete_all

logger(Logger::INFO, "CiJobStatus::Update: TimeoutExecution for '#{@check_suite.id}'")

TimeoutExecution
.delay(run_at: 30.minute.from_now.utc, queue: 'timeout_execution')
.timeout(@check_suite.id)
end

def stage_with_start_in_progress(ci_job)
return unless !ci_job.stage.nil? and ci_job.stage.configuration.start_in_progress?

Expand Down
14 changes: 7 additions & 7 deletions workers/timeout_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ def timeout(check_suite_id)
@logger.info("Timeout execution for check_suite_id: #{check_suite_id} -> finished? #{check_suite.finished?}")

return false if check_suite.finished?
return rescheduling([], check_suite_id) if check_suite.last_job_updated_at_timer > 2.hour.ago.utc
return rescheduling(check_suite_id) if check_suite.last_job_updated_at_timer < 2.hour.ago.utc

@logger.info("Calling Github::PlanExecution::Finished.new(#{check_suite.bamboo_ci_ref}).finished")

rescheduling(finished(check_suite), check_suite_id)
return false if finished?(check_suite) == [200, 'Finished']

rescheduling(check_suite_id)
end

def finished(check_suite)
def finished?(check_suite)
Github::PlanExecution::Finished
.new({ 'bamboo_ref' => check_suite.bamboo_ci_ref, hanged: true })
.finished
end

def rescheduling(resp, check_suite_id)
return true if resp == [200, 'Finished']

def rescheduling(check_suite_id)
@logger.info("Rescheduling check_suite_id: #{check_suite_id}")

Delayed::Job.where('handler LIKE ?', "%TimeoutExecution%args%-%#{check_suite_id}%").delete_all

TimeoutExecution
.delay(run_at: 2.hours.from_now.utc, queue: 'timeout_execution')
.delay(run_at: 30.minute.from_now.utc, queue: 'timeout_execution')
.timeout(check_suite_id)

false
Expand Down

0 comments on commit 417bdf1

Please sign in to comment.