Skip to content

Commit

Permalink
delete 5 year old drafts from expired vacancies
Browse files Browse the repository at this point in the history
  • Loading branch information
starswan committed Nov 7, 2024
1 parent d5c66bc commit 6ba12dc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class DeleteOldDraftApplicationsForExpiredVacanciesJob < ApplicationJob
queue_as :low

def perform
JobApplication.joins(:vacancy)
.draft
.where(job_applications: { updated_at: ...5.years.ago })
.merge(Vacancy.expired)
.find_each(&:destroy!)
end
end
10 changes: 0 additions & 10 deletions app/jobs/withdraw_draft_applications_for_expired_vacancies_job.rb

This file was deleted.

5 changes: 5 additions & 0 deletions config/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ delete_old_applications:
class: 'DeleteOldNonDraftJobApplicationsJob'
queue: low

withdraw_stale_drafts:
cron: '0 10 * * *'
class: 'DeleteOldDraftApplicationsForExpiredVacanciesJob'
queue: low

remove_vacancies_that_expired_yesterday_from_google_index:
cron: '0 04 * * *'
class: 'RemoveVacanciesThatExpiredYesterdayFromGoogleIndexJob'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
require "rails_helper"

RSpec.describe WithdrawDraftApplicationsForExpiredVacanciesJob, type: :job do
RSpec.describe DeleteOldDraftApplicationsForExpiredVacanciesJob do
before do
vacancy.save!
JobApplication.draft.first.update!(updated_at: 6.years.ago)
described_class.perform_now
end

context "with an expired vacancy" do
let(:vacancy) do
build(:vacancy, :expired,
job_applications: [
build(:job_application, :status_draft),
build(:job_application, :status_draft),
build(:job_application, :status_submitted),
])
end

it "marks draft application as withdrawn" do
expect(JobApplication.all.map(&:status)).to match_array(%w[submitted withdrawn])
end

it "sets withdrawn_at" do
expect(JobApplication.all.map(&:withdrawn_at).filter_map { |datetime| datetime.to_date if datetime.present? }).to match_array([Date.today])
it "deletes the old draft application" do
expect(JobApplication.all.map(&:status)).to match_array(%w[submitted draft])
end
end

Expand Down

0 comments on commit 6ba12dc

Please sign in to comment.