diff --git a/config/delayed_job.rb b/config/delayed_job.rb index 09f7aa4..9f1f106 100644 --- a/config/delayed_job.rb +++ b/config/delayed_job.rb @@ -34,8 +34,6 @@ class << self Delayed::Worker.max_attempts = 5 Delayed::Worker.max_run_time = 5.minutes -Delayed::Job.delete_all unless ENV.fetch('RAILS_ENV', 'test') == 'test' - # Load the database configuration config = YAML.load_file('config/database.yml')[ENV.fetch('RACK_ENV', 'development')] diff --git a/lib/github/build/action.rb b/lib/github/build/action.rb index fe61f2a..bb954ae 100644 --- a/lib/github/build/action.rb +++ b/lib/github/build/action.rb @@ -3,6 +3,17 @@ # action.rb # Part of NetDEF CI System # +# This class handles the build action for a given CheckSuite. +# It creates summaries, jobs, and timeout workers for the CheckSuite. +# +# Methods: +# - initialize(check_suite, github, jobs, logger_level: Logger::INFO): Initializes the Action class with the +# given parameters. +# - create_summary(rerun: false): Creates a summary for the CheckSuite, including jobs and timeout workers. +# +# Example usage: +# Github::Build::Action.new(check_suite, github, jobs).create_summary +# # Copyright (c) 2023 by # Network Device Education Foundation, Inc. ("NetDEF") # @@ -11,6 +22,13 @@ module Github module Build class Action + ## + # Initializes the Action class with the given parameters. + # + # @param [CheckSuite] check_suite The CheckSuite to handle. + # @param [Github] github The Github instance to use. + # @param [Array] jobs The jobs to create for the CheckSuite. + # @param [Integer] logger_level The logging level to use (default: Logger::INFO). def initialize(check_suite, github, jobs, logger_level: Logger::INFO) @check_suite = check_suite @github = github @@ -26,6 +44,10 @@ def initialize(check_suite, github, jobs, logger_level: Logger::INFO) logger(Logger::WARN, ">>>> Building action to CheckSuite: #{@check_suite.inspect}") end + ## + # Creates a summary for the CheckSuite, including jobs and timeout workers. + # + # @param [Boolean] rerun Indicates if the jobs should be rerun (default: false). def create_summary(rerun: false) logger(Logger::INFO, "SUMMARY #{@stages.inspect}") @@ -37,10 +59,15 @@ def create_summary(rerun: false) logger(Logger::INFO, "@jobs - #{@jobs.inspect}") create_jobs(rerun) + create_timeout_worker end private + ## + # Creates jobs for the CheckSuite. + # + # @param [Boolean] rerun Indicates if the jobs should be rerun. def create_jobs(rerun) @jobs.each do |job| ci_job = create_ci_job(job) @@ -60,6 +87,20 @@ def create_jobs(rerun) end end + ## + # Creates a timeout worker for the CheckSuite. + def create_timeout_worker + 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 + + ## + # Starts the stage in progress if configured to do so. + # + # @param [CiJob] ci_job The CI job to start in progress. def stage_with_start_in_progress(ci_job) return unless !ci_job.stage.nil? and ci_job.stage.configuration.start_in_progress? @@ -67,6 +108,11 @@ def stage_with_start_in_progress(ci_job) ci_job.stage.in_progress(@github, output: {}) end + ## + # Creates a CI job for the given job parameters. + # + # @param [Hash] job The job parameters. + # @return [CiJob, nil] The created CI job or nil if the stage configuration is not found. def create_ci_job(job) stage_config = StageConfiguration.find_by(bamboo_stage_name: job[:stage]) @@ -79,6 +125,10 @@ def create_ci_job(job) CiJob.create(check_suite: @check_suite, name: job[:name], job_ref: job[:job_ref], stage: stage) end + ## + # Creates a check run stage for the given stage configuration. + # + # @param [StageConfiguration] stage_config The stage configuration. def create_check_run_stage(stage_config) stage = Stage.find_by(name: stage_config.github_check_run_name, check_suite_id: @check_suite.id) @@ -92,6 +142,11 @@ def create_check_run_stage(stage_config) stage.enqueue(@github, output: initial_output(stage)) end + ## + # Creates a new stage for the given stage configuration. + # + # @param [StageConfiguration] stage_config The stage configuration. + # @return [Stage] The created stage. def create_stage(stage_config) name = stage_config.github_check_run_name @@ -110,6 +165,11 @@ def create_stage(stage_config) stage end + ## + # Generates the initial output for a CI job. + # + # @param [CiJob] ci_job The CI job. + # @return [Hash] The initial output. def initial_output(ci_job) output = { title: '', summary: '' } url = "https://ci1.netdef.org/browse/#{ci_job.check_suite.bamboo_ci_ref}" @@ -120,6 +180,11 @@ def initial_output(ci_job) output end + ## + # Logs a message with the given severity. + # + # @param [Integer] severity The severity level. + # @param [String] message The message to log. def logger(severity, message) @loggers.each do |logger_object| logger_object.add(severity, message) diff --git a/lib/github/plan_execution/finished.rb b/lib/github/plan_execution/finished.rb index 27e6666..fc1bf99 100644 --- a/lib/github/plan_execution/finished.rb +++ b/lib/github/plan_execution/finished.rb @@ -3,6 +3,18 @@ # check_suite_finished.rb # Part of NetDEF CI System # +# This class handles the logic for determining if a CheckSuite has finished execution. +# It interacts with the Bamboo CI system to fetch the build status and updates the CheckSuite accordingly. +# +# Methods: +# - initialize(payload): Initializes the Finished class with the given payload. +# - finished: Main method to handle the completion logic for a CheckSuite. +# - fetch_build_status: Fetches the build status from Bamboo CI. +# - in_progress?(build_status): Checks if the CI build is still in progress. +# +# Example usage: +# Github::PlanExecution::Finished.new(payload).finished +# # Copyright (c) 2024 by # Network Device Education Foundation, Inc. ("NetDEF") # @@ -17,12 +29,22 @@ module PlanExecution class Finished include BambooCi::Api + ## + # Initializes the Finished class with the given payload. + # + # @param [Hash] payload The payload containing information about the CheckSuite. def initialize(payload) - @check_suite = CheckSuite.find_by(bamboo_ci_ref: payload['bamboo_ref']) + @check_suite = CheckSuite.find_by(bamboo_ci_ref: payload['bamboo_ref']) if payload['bamboo_ref'] + @check_suite = CheckSuite.find(payload['check_suite_id']) if payload['check_suite_id'] @logger = GithubLogger.instance.create('github_plan_execution_finished.log', Logger::INFO) @hanged = payload['hanged'] || false end + ## + # Main method to handle the completion logic for a CheckSuite. + # Fetches the CI execution status and updates the CheckSuite accordingly. + # + # @return [Array] An array containing the status code and message. def finished @logger.info ">>> Check Suite: #{@check_suite.inspect}" @@ -31,9 +53,9 @@ def finished fetch_ci_execution build_status = fetch_build_status - @logger.info ">>> build_status: #{build_status.inspect}" + @logger.info ">>> build_status: #{build_status.inspect}. Hanged? #{@hanged}" - return [200, 'Still running'] if in_progress?(build_status) + return [200, 'Still running'] if in_progress?(build_status) and !@hanged check_stages clear_deleted_jobs @@ -42,11 +64,19 @@ def finished [200, 'Finished'] end + ## + # Fetches the build status from Bamboo CI. + # + # @return [Hash] The build status. def fetch_build_status get_request(URI("https://127.0.0.1/rest/api/latest/result/status/#{@check_suite.bamboo_ci_ref}")) end - # Checks if CI still running + ## + # Checks if the CI build is still in progress. + # + # @param [Hash] build_status The build status. + # @return [Boolean] Returns true if the build is still in progress, false otherwise. def in_progress?(build_status) @logger.info ">>> ci_stopped?: #{ci_stopped?(build_status)}" @logger.info ">>> ci_hanged?: #{ci_hanged?(build_status)}" @@ -59,6 +89,9 @@ def in_progress?(build_status) private + ## + # Updates the status of all stages for the CheckSuite. + # Builds a summary for the last stage's last job. def update_all_stages last_stage = Stage @@ -71,8 +104,8 @@ def update_all_stages build_summary(last_stage.jobs.last) end - # This method will move all tests that no longer exist in BambooCI to the skipped state, - # because there are no executions for them. + ## + # Moves all tests that no longer exist in BambooCI to the skipped state. def clear_deleted_jobs github_check = Github::Check.new(@check_suite) @@ -81,22 +114,44 @@ def clear_deleted_jobs end end + ## + # Checks if the CI build has stopped. + # + # @param [Hash] build_status The build status. + # @return [Boolean] Returns true if the build has stopped, false otherwise. def ci_stopped?(build_status) build_status.key?('message') and !build_status.key?('finished') end + ## + # Checks if the CI build has hanged. + # + # @param [Hash] build_status The build status. + # @return [Boolean] Returns true if the build has hanged, false otherwise. def ci_hanged?(build_status) return true if ci_stopped?(build_status) build_status.dig('progress', 'percentageCompleted').to_f >= 2.0 end + ## + # Updates the status of a stage based on the CI job result. + # + # @param [CiJob] ci_job The CI job to update. + # @param [Hash] result The result of the CI job. + # @param [Github::Check] github The Github check instance. def update_stage_status(ci_job, result, github) return if ci_job.nil? || (ci_job.finished? && !ci_job.job_ref.nil?) update_ci_job_status(github, ci_job, result['state']) end + ## + # Updates the status of a CI job based on the state. + # + # @param [Github::Check] github_check The Github check instance. + # @param [CiJob] ci_job The CI job to update. + # @param [String] state The state of the CI job. def update_ci_job_status(github_check, ci_job, state) ci_job.enqueue(github_check) if ci_job.job_ref.nil? @@ -119,6 +174,11 @@ def update_ci_job_status(github_check, ci_job, state) build_summary(ci_job) end + ## + # Creates an output message for a CI job. + # + # @param [CiJob] ci_job The CI job to create the message for. + # @return [Hash] The output message. def create_output_message(ci_job) url = "https://ci1.netdef.org/browse/#{ci_job.job_ref}" @@ -128,6 +188,10 @@ def create_output_message(ci_job) } end + ## + # Builds a summary for a CI job. + # + # @param [CiJob] ci_job The CI job to build the summary for. def build_summary(ci_job) summary = Github::Build::Summary.new(ci_job, agent: 'WatchDog') summary.build_summary @@ -135,6 +199,11 @@ def build_summary(ci_job) finished_execution?(ci_job.check_suite) end + ## + # Checks if the execution of the CheckSuite has finished. + # + # @param [CheckSuite] check_suite The CheckSuite to check. + # @return [Boolean] Returns true if the execution has finished, false otherwise. def finished_execution?(check_suite) return false unless check_suite.pull_request.current_execution?(check_suite) return false unless check_suite.finished? @@ -154,6 +223,8 @@ def slack_notify_cancelled(job) SlackBot.instance.notify_cancelled(job) end + ## + # Checks the stages of the CheckSuite and updates their status. def check_stages github_check = Github::Check.new(@check_suite) @logger.info ">>> @result: #{@result.inspect}" @@ -168,6 +239,8 @@ def check_stages end end + ## + # Fetches the CI execution status for the CheckSuite. def fetch_ci_execution @result = get_status(@check_suite.bamboo_ci_ref) end diff --git a/lib/github/update_status.rb b/lib/github/update_status.rb index e06ae05..5214746 100644 --- a/lib/github/update_status.rb +++ b/lib/github/update_status.rb @@ -3,6 +3,16 @@ # update_status.rb # Part of NetDEF CI System # +# This class handles the update of the status for a given CI job. +# It updates the job status, logs messages, and manages delayed jobs. +# +# Methods: +# - initialize(payload): Initializes the UpdateStatus class with the given payload. +# - update: Updates the status of the CI job based on the payload. +# +# Example usage: +# Github::UpdateStatus.new(payload).update +# # Copyright (c) 2023 by # Network Device Education Foundation, Inc. ("NetDEF") # @@ -17,6 +27,10 @@ module Github class UpdateStatus + ## + # Initializes the UpdateStatus class with the given payload. + # + # @param [Hash] payload The payload containing information about the CI job. def initialize(payload) @status = payload['status'] @@ -28,6 +42,10 @@ def initialize(payload) logger_initializer end + ## + # Updates the status of the CI job based on the payload. + # + # @return [Array] An array containing the status code and message. def update return job_not_found if @job.nil? return [304, 'Not Modified'] if @job.queued? and @status != 'in_progress' and @job.name != 'Checkout Code' @@ -40,12 +58,18 @@ def update private + ## + # Handles the case when the CI job is not found. + # + # @return [Array] An array containing the status code and message. def job_not_found logger(Logger::ERROR, "CI JOB not found: '#{@reference}'") [404, 'CI JOB not found'] end + ## + # Records the failure statistics for the CI job. def failures_stats @failures.each do |failure| TopotestFailure.create(ci_job: @job, @@ -56,11 +80,14 @@ def failures_stats end end + ## + # Updates the status of the CI job. + # + # @return [Array] An array containing the status code and message. def update_status case @status when 'in_progress' @job.in_progress(@github_check) - create_timeout_worker when 'success' @job.success(@github_check) @job.update_execution_time @@ -80,44 +107,39 @@ def update_status [500, 'Internal Server Error'] 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: 2.hours.from_now.utc, queue: 'timeout_execution') - .timeout(@check_suite.id) - end - + ## + # Inserts a new delayed job for the CI job. def insert_new_delayed_job queue = @job.check_suite.pull_request.github_pr_id % 10 delete_and_create_delayed_job(queue) end + ## + # Deletes existing delayed jobs and creates a new one. + # + # @param [Integer] queue The queue number for the delayed job. def delete_and_create_delayed_job(queue) - fetch_delayed_job.destroy_all + fetch_delayed_job(queue).destroy_all CiJobStatus .delay(run_at: DELAYED_JOB_TIMER.seconds.from_now.utc, queue: queue) .update(@job.check_suite.id, @job.id) end - def fetch_delayed_job - Delayed::Job.where('handler LIKE ?', "%method_name: :update\nargs:\n- #{@job.check_suite.id}%") - end - - def current_execution? - pull_request = @check_suite.pull_request - last_check_suite = pull_request.check_suites.reload.all.order(:created_at).last - - logger Logger::INFO, "last_check_suite: #{last_check_suite.inspect}" - logger Logger::INFO, "@check_suite: #{@check_suite.inspect}" - - @check_suite.id == last_check_suite.id + ## + # Fetches the delayed job for the given queue. + # + # @param [Integer] queue The queue number for the delayed job. + # @return [ActiveRecord::Relation] The relation containing the delayed jobs. + def fetch_delayed_job(queue) + Delayed::Job + .where(queue: queue) + .where('handler LIKE ?', "%method_name: :update\nargs:\n- #{@check_suite.id}%") end + ## + # Handles the failure case for the CI job. # The unable2find string must match the phrase defined in the ci-files repository file # github_checks/hook_api.py method __topotest_title_summary def failure @@ -130,12 +152,19 @@ def failure .update(@job.id, 1) end + ## + # Logs a message with the given severity. + # + # @param [Integer] severity The severity level. + # @param [String] message The message to log. def logger(severity, message) @loggers.each do |logger_object| logger_object.add(severity, message) end end + ## + # Initializes the logger for the UpdateStatus class. def logger_initializer @loggers = [] @loggers << GithubLogger.instance.create('github_update_status.log', Logger::INFO) diff --git a/spec/lib/github/build/action_spec.rb b/spec/lib/github/build/action_spec.rb index d0ef533..c70b884 100644 --- a/spec/lib/github/build/action_spec.rb +++ b/spec/lib/github/build/action_spec.rb @@ -47,6 +47,8 @@ allow(fake_github_check).to receive(:check_runs_for_ref).and_return({}) allow(BambooCi::Result).to receive(:fetch).and_return({}) + allow(TimeoutExecution).to receive_message_chain(:delay, :timeout).and_return(true) + stage end diff --git a/spec/lib/github/build_plan_spec.rb b/spec/lib/github/build_plan_spec.rb index f6b7e81..d2425a1 100644 --- a/spec/lib/github/build_plan_spec.rb +++ b/spec/lib/github/build_plan_spec.rb @@ -18,6 +18,7 @@ before do allow(File).to receive(:read).and_return('') allow(OpenSSL::PKey::RSA).to receive(:new).and_return(OpenSSL::PKey::RSA.new(2048)) + allow(TimeoutExecution).to receive_message_chain(:delay, :timeout).and_return(true) end describe 'Valid commands' do diff --git a/spec/lib/github/re_run/command_spec.rb b/spec/lib/github/re_run/command_spec.rb index 02e0f74..d5f2748 100644 --- a/spec/lib/github/re_run/command_spec.rb +++ b/spec/lib/github/re_run/command_spec.rb @@ -17,6 +17,7 @@ before do allow(File).to receive(:read).and_return('') allow(OpenSSL::PKey::RSA).to receive(:new).and_return(OpenSSL::PKey::RSA.new(2048)) + allow(TimeoutExecution).to receive_message_chain(:delay, :timeout).and_return(true) end describe 'Invalid payload' do diff --git a/spec/lib/github/re_run/comment_spec.rb b/spec/lib/github/re_run/comment_spec.rb index 15e8de5..da3fd3a 100644 --- a/spec/lib/github/re_run/comment_spec.rb +++ b/spec/lib/github/re_run/comment_spec.rb @@ -21,6 +21,8 @@ allow(Github::Build::UnavailableJobs).to receive(:new).and_return(fake_unavailable) allow(fake_unavailable).to receive(:update).and_return([]) + + allow(TimeoutExecution).to receive_message_chain(:delay, :timeout).and_return(true) end describe 'Invalid payload' do diff --git a/spec/lib/github/update_status_spec.rb b/spec/lib/github/update_status_spec.rb index 6ee8a48..f33f7ca 100644 --- a/spec/lib/github/update_status_spec.rb +++ b/spec/lib/github/update_status_spec.rb @@ -484,6 +484,26 @@ end end + context 'when Ci Job TopoTest Part 0 update from in_progress -> success, but check suite is old' do + let(:pull_request) { create(:pull_request) } + let(:check_suite) { create(:check_suite, pull_request: pull_request) } + let(:check_suite_current) { create(:check_suite, pull_request: pull_request) } + let(:stage1) { create(:stage, check_suite: check_suite) } + + let(:ci_job) { create(:ci_job, status: 'in_progress', stage: stage1, check_suite: check_suite) } + let(:status) { 'success' } + + before do + check_suite + check_suite_current + ci_job + end + + it 'must returns success' do + expect(update_status.update).to eq([200, 'Success']) + end + end + context 'when Ci Job TopoTest Part 0 update from in_progress -> failure' do let(:check_suite) { create(:check_suite) } let(:stage1) { create(:stage, check_suite: check_suite) } diff --git a/spec/workers/timeout_execution_spec.rb b/spec/workers/timeout_execution_spec.rb index 59565a5..f9114dd 100644 --- a/spec/workers/timeout_execution_spec.rb +++ b/spec/workers/timeout_execution_spec.rb @@ -29,29 +29,28 @@ end end - context 'when timeout is called, but hanged' do + context 'when timeout is called and rescheduled' do let(:check_suite) { create(:check_suite) } before do allow(CheckSuite).to receive(:find).and_return(check_suite) allow(check_suite).to receive(:finished?).and_return(false) - allow(check_suite).to receive(:last_job_updated_at_timer).and_return(Time.now.utc - 3.hours) - allow(finished_instance).to receive(:finished).and_return([200, 'Finished']) + allow(check_suite).to receive(:last_job_updated_at_timer).and_return(Time.now.utc + 3.hours) + allow(TimeoutExecution).to receive_message_chain(:delay, :timeout).and_return(true) end it 'calls timeout job' do - expect(described_class.timeout(check_suite.id)).to be_truthy + expect(described_class.timeout(check_suite.id)).to be_falsey end end - context 'when timeout is called and rescheduled' do + context 'when timeout is called, last update in 2 hour ago' do let(:check_suite) { create(:check_suite) } before do allow(CheckSuite).to receive(:find).and_return(check_suite) - allow(check_suite).to receive(:finished?).and_return(false) - allow(check_suite).to receive(:last_job_updated_at_timer).and_return(Time.now.utc + 3.hours) - allow(TimeoutExecution).to receive_message_chain(:delay, :timeout).and_return(true) + allow(check_suite).to receive(:finished?).and_return(false, true) + allow(check_suite).to receive(:last_job_updated_at_timer).and_return(Time.now.utc - 3.hours) end it 'calls timeout job' do @@ -59,17 +58,18 @@ end end - context 'when timeout is called, last update in 2 hour ago' do + context 'when timeout is called, last update in 2 hour ago and timeout is called' do let(:check_suite) { create(:check_suite) } before do allow(CheckSuite).to receive(:find).and_return(check_suite) - allow(check_suite).to receive(:finished?).and_return(false) - allow(check_suite).to receive(:last_job_updated_at_timer).and_return(Time.now.utc - 3.hours) + allow(check_suite).to receive(:finished?).and_return(false, false) + allow(check_suite).to receive(:last_job_updated_at_timer).and_return(Time.now.utc + 3.hours, + Time.now.utc - 3.hour) + allow(finished_instance).to receive(:finished).and_return([200, 'Finished']) end it 'calls timeout job' do - expect(TimeoutExecution).to receive(:timeout) expect(described_class.timeout(check_suite.id)).to be_falsey end end diff --git a/workers/timeout_execution.rb b/workers/timeout_execution.rb index 82119f0..8ce3517 100644 --- a/workers/timeout_execution.rb +++ b/workers/timeout_execution.rb @@ -1,8 +1,21 @@ # SPDX-License-Identifier: BSD-2-Clause # -# ci_job_status.rb +# timeout_execution.rb # Part of NetDEF CI System # +# This class handles the timeout execution logic for a given CheckSuite. +# It checks if the CheckSuite has finished or if it needs to be rescheduled +# or handled by the watchdog process. +# +# Methods: +# - timeout(check_suite_id): Main method to handle the timeout logic for a CheckSuite. +# - watchdog(check_suite): Handles the CheckSuite if it is considered hanged. +# - rescheduling(check_suite_id): Reschedules the timeout execution for a CheckSuite. +# +# Example usage: +# - TimeoutExecution.timeout(check_suite_id) +# - TimeoutExecution.delay(...).timeout(check_suite_id) +# # Copyright (c) 2024 by # Network Device Education Foundation, Inc. ("NetDEF") # @@ -12,6 +25,14 @@ class TimeoutExecution class << self + ## + # Handles the timeout logic for a given CheckSuite. + # Logs the timeout execution and checks if the CheckSuite has finished. + # If the CheckSuite has not finished and the last job update was more than 2 hours ago, + # it calls the watchdog method. Otherwise, it reschedules the timeout execution. + # + # @param [Integer] check_suite_id The ID of the CheckSuite to handle. + # @return [Boolean] Returns false if the CheckSuite has finished or if it is rescheduled. def timeout(check_suite_id) @logger = GithubLogger.instance.create('timeout_execution_worker.log', Logger::INFO) check_suite = CheckSuite.find(check_suite_id) @@ -19,28 +40,34 @@ 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 watchdog(check_suite) 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) + @logger.info("Rescheduling check_suite_id: #{check_suite_id}") + rescheduling(check_suite_id) end - def finished(check_suite) + ## + # Handles the CheckSuite if it is considered hanged. + # Calls the finished method of Github::PlanExecution::Finished with the hanged flag set to true. + # + # @param [CheckSuite] check_suite The CheckSuite to handle. + def watchdog(check_suite) Github::PlanExecution::Finished - .new({ 'bamboo_ref' => check_suite.bamboo_ci_ref, hanged: true }) + .new({ 'check_suite_id' => check_suite.id, 'hanged' => true }) .finished - end - - def rescheduling(resp, check_suite_id) - return true if resp == [200, 'Finished'] - @logger.info("Rescheduling check_suite_id: #{check_suite_id}") - - Delayed::Job.where('handler LIKE ?', "%TimeoutExecution%args%-%#{check_suite_id}%").delete_all + true + end + ## + # Reschedules the timeout execution for a given CheckSuite. + # Logs the rescheduling and deletes any existing delayed jobs for the CheckSuite. + # Schedules a new timeout execution to run 30 minutes from now. + # + # @param [Integer] check_suite_id The ID of the CheckSuite to reschedule. + def rescheduling(check_suite_id) 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