Skip to content

Commit

Permalink
Merge pull request #341 from fablabbcn/device-archive-job-fix
Browse files Browse the repository at this point in the history
fix device archived_at null bug
  • Loading branch information
timcowlishaw authored Jul 20, 2024
2 parents 0fbc289 + 3aa0ebb commit b7c347b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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

0 comments on commit b7c347b

Please sign in to comment.