diff --git a/config/sidekiq_queues.yml b/config/sidekiq_queues.yml index 970df2d4465bcef1b50879cf8e7ba543222581b0..df50b55c9e05cf36ac8991b1e951fa2bfde356d3 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 0000000000000000000000000000000000000000..48103dabb10994afd140855f1f7ffd660114a460 --- /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 0000000000000000000000000000000000000000..7ee77613b4d5bebb4895db5c3c8ed74f1638e25a --- /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 50b15accfc57e2dee9dbc7bea780d84487d58dc6..1c5a226771f3591ac0f4b9a14a4118abdbc8ea7f 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 378a68a72bf36153fcc43d8b9c61d8beee774419..5be72d7661a2a1ae2381caffcd4188e2d0e264de 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 0000000000000000000000000000000000000000..c93439c480f43a095609c29f1f36d2eaba14c859 --- /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