From f29958df004c6344f719be8cb1a47ad88a81ab1c Mon Sep 17 00:00:00 2001 From: Jay Montal Date: Wed, 10 May 2023 15:49:34 -0600 Subject: [PATCH] Timeout on status check non failures - Adds `created_at` and `updated_at` to status_check_responses table Changelog: changed EE: true --- config/sidekiq_queues.yml | 2 ++ ...dd_timestamps_to_status_check_responses.rb | 7 ++++++ db/schema_migrations/20230510212130 | 1 + db/structure.sql | 4 +++- ee/app/workers/all_queues.yml | 9 +++++++ .../update_status_check_response_worker.rb | 24 +++++++++++++++++++ 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20230510212130_add_timestamps_to_status_check_responses.rb create mode 100644 db/schema_migrations/20230510212130 create mode 100644 ee/app/workers/compliance_management/update_status_check_response_worker.rb diff --git a/config/sidekiq_queues.yml b/config/sidekiq_queues.yml index 970df2d4465bce..df50b55c9e05cf 100644 --- a/config/sidekiq_queues.yml +++ b/config/sidekiq_queues.yml @@ -139,6 +139,8 @@ - 1 - - compliance_management_update_default_framework - 1 +- - compliance_management_update_status_check_response + - 1 - - container_repository - 1 - - container_repository_delete diff --git a/db/migrate/20230510212130_add_timestamps_to_status_check_responses.rb b/db/migrate/20230510212130_add_timestamps_to_status_check_responses.rb new file mode 100644 index 00000000000000..48103dabb10994 --- /dev/null +++ b/db/migrate/20230510212130_add_timestamps_to_status_check_responses.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddTimestampsToStatusCheckResponses < Gitlab::Database::Migration[2.1] + def change + add_timestamps_with_timezone(:status_check_responses, null: false, default: -> { 'NOW()' }) + end +end diff --git a/db/schema_migrations/20230510212130 b/db/schema_migrations/20230510212130 new file mode 100644 index 00000000000000..7ee77613b4d5be --- /dev/null +++ b/db/schema_migrations/20230510212130 @@ -0,0 +1 @@ +74fa0c34c52fe29791066fad3afac250a805b2ff92bfcb08339f3dbe94501871 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 50b15accfc57e2..1c5a226771f359 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -22871,7 +22871,9 @@ CREATE TABLE status_check_responses ( external_approval_rule_id bigint, sha bytea NOT NULL, external_status_check_id bigint NOT NULL, - status smallint DEFAULT 0 NOT NULL + status smallint DEFAULT 0 NOT NULL, + created_at timestamp with time zone DEFAULT now() NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL ); CREATE SEQUENCE status_check_responses_id_seq diff --git a/ee/app/workers/all_queues.yml b/ee/app/workers/all_queues.yml index 378a68a72bf361..5be72d7661a2a1 100644 --- a/ee/app/workers/all_queues.yml +++ b/ee/app/workers/all_queues.yml @@ -1182,6 +1182,15 @@ :weight: 1 :idempotent: true :tags: [] +- :name: compliance_management_update_status_check_response + :worker_name: ComplianceManagement::UpdateStatusCheckResponseWorker + :feature_category: :compliance_management + :has_external_dependencies: false + :urgency: :low + :resource_boundary: :unknown + :weight: 1 + :idempotent: true + :tags: [] - :name: create_github_webhook :worker_name: CreateGithubWebhookWorker :feature_category: :integrations diff --git a/ee/app/workers/compliance_management/update_status_check_response_worker.rb b/ee/app/workers/compliance_management/update_status_check_response_worker.rb new file mode 100644 index 00000000000000..c93439c480f43a --- /dev/null +++ b/ee/app/workers/compliance_management/update_status_check_response_worker.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module ComplianceManagement + class UpdateStatusCheckResponseWorker + include ApplicationWorker + + idempotent! + data_consistency :delayed + urgency :low + feature_category :compliance_management + + BATCH_SIZE = 100 + + def perform + qualified_status_check_responses.each_batch(of: BATCH_SIZE) do |batch| + batch.update_all(status: 1) + end + end + + def qualified_status_check_responses + MergeRequests::StatusCheckResponse.not_passed.where('created_at < ?', 2.hours.ago) # rubocop: disable CodeReuse/ActiveRecord + end + end +end -- GitLab