diff --git a/lib/tasks/server_recordings_sync.rake b/lib/tasks/server_recordings_sync.rake index e61903e47d..60da6f75da 100644 --- a/lib/tasks/server_recordings_sync.rake +++ b/lib/tasks/server_recordings_sync.rake @@ -21,6 +21,12 @@ desc 'Server Recordings sync with BBB server' task :server_recordings_sync, %i[provider] => :environment do |_task, args| args.with_defaults(provider: 'greenlight') + Room.select do |room| + room_recordings = room.recordings + Format.where(recording: room_recordings).delete_all + room_recordings.delete_all + end + Room.includes(:user).select(:id, :meeting_id).with_provider(args[:provider]).in_batches(of: 25) do |rooms| meeting_ids = rooms.pluck(:meeting_id) @@ -30,14 +36,7 @@ task :server_recordings_sync, %i[provider] => :environment do |_task, args| next if recordings[:recordings].blank? - # Skip the entire batch if the first and last recordings exist - if Recording.exists?(record_id: recordings[:recordings][0][:recordID]) && Recording.exists?(record_id: recordings[:recordings][-1][:recordID]) - next - end - recordings[:recordings].each do |recording| - next if Recording.exists?(record_id: recording[:recordID]) - RecordingCreator.new(recording:).call success 'Successfully migrated Recording:' info "RecordID: #{recording[:recordID]}" diff --git a/spec/services/recordings_sync_spec.rb b/spec/services/recordings_sync_spec.rb index 92a11caea8..4bf7c8035d 100644 --- a/spec/services/recordings_sync_spec.rb +++ b/spec/services/recordings_sync_spec.rb @@ -43,7 +43,7 @@ allow_any_instance_of(BigBlueButtonApi).to receive(:get_recordings).and_return(no_recording_response) end - it 'does not call RecordingsCreator service' do + it 'does not call RecordingsCreator service and delete all recordings' do expect_any_instance_of(BigBlueButtonApi).to receive(:get_recordings).with(meeting_ids: room.meeting_id) expect(RecordingCreator).not_to receive(:new)