-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Schedule a separate job for each group backup
- Loading branch information
1 parent
6798693
commit 95efdea
Showing
8 changed files
with
132 additions
and
150 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito_sac_cas | ||
|
||
class Export::BackupMitgliederScheduleJob < RecurringJob | ||
|
||
run_every 1.day | ||
|
||
ROLE_TYPES_TO_BACKUP = [Group::Sektion, Group::Ortsgruppe].freeze | ||
|
||
def perform_internal | ||
relevant_groups.find_each do |group| | ||
Export::BackupMitgliederExportJob.new(group.id).enqueue! | ||
end | ||
end | ||
|
||
private | ||
|
||
def relevant_groups | ||
Group.where(type: ROLE_TYPES_TO_BACKUP.map(&:sti_name)) | ||
end | ||
|
||
def next_run | ||
interval.from_now.midnight + 5.minutes | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito_sac_cas. | ||
|
||
require 'spec_helper' | ||
|
||
describe Export::BackupMitgliederScheduleJob do | ||
subject(:job) { described_class.new } | ||
let(:relevant_groups) { Group.where(type: [Group::Sektion, Group::Ortsgruppe]) } | ||
|
||
context 'rescheduling' do | ||
it 'reschedules for tomorrow at 5 minutes past midnight' do | ||
job.perform | ||
next_job = Delayed::Job.find_by("handler like '%BackupMitgliederScheduleJob%'") | ||
expect(next_job.run_at).to eq Time.zone.tomorrow + 5.minutes | ||
end | ||
end | ||
|
||
context 'perform' do | ||
it 'only iterates over relevant groups' do | ||
relevant_groups.each do |group| | ||
expect(Export::BackupMitgliederExportJob).to receive(:new) | ||
.with(group.id) | ||
.and_call_original | ||
end | ||
|
||
expect do | ||
job.perform | ||
end.to change { Delayed::Job.where("handler like '%BackupMitgliederExportJob%'").count }.by(relevant_groups.length) | ||
end | ||
end | ||
end |