Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix device archived_at null bug #341

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/jobs/delete_archived_devices_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ def perform(*args)
CheckupNotifyJob.perform_now("Delete archived devices")

Device.unscoped.where(workflow_state: "archived").each do |device|
if device.archived_at < 24.hours.ago
p [device.id, device.archived_at]
if device.archived_at && device.archived_at < 24.hours.ago
CheckupNotifyJob.perform_now("deleting archived device #{device.id}")
device.destroy!
end
Expand Down
5 changes: 5 additions & 0 deletions spec/jobs/delete_archived_devices_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
it "should delete all archived devices, archived_at at least 24 hours ago" do
deviceNormal = create(:device, name: "dontDeleteMe", created_at: 6.weeks.ago, components: [create(:component)])
deviceArchived = create(:device, name: "deleteMe", created_at: 1.month.ago, components: [create(:component)])
deviceArchivedNullArchivedAt = create(:device, name: "dontdeleteMe", created_at: 1.month.ago, components: [create(:component)])
deviceArchivedToday = create(:device, name: "dontDeleteMe", created_at: 2.months.ago, components: [create(:component)])
deviceArchived.archive!
deviceArchivedNullArchivedAt.archive!
deviceArchivedNullArchivedAt.archived_at = nil # A data inconsistency preseent in production that causes the job to fail
deviceArchivedNullArchivedAt.save!
deviceArchivedToday.archive!
deviceArchived.update!({archived_at: 2.days.ago})
expect {
Expand All @@ -23,6 +27,7 @@
expect(Device.unscoped).to include(deviceNormal)
expect(Device.unscoped).not_to include(deviceArchived)
expect(Device.unscoped).to include(deviceArchivedToday)
expect(Device.unscoped).to include(deviceArchivedNullArchivedAt)
end
end
end
Loading