-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recurring job to delete stale application forms
- Loading branch information
1 parent
d0aae0d
commit bb1767b
Showing
8 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
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
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,9 @@ | ||
class DeleteStaleFormsJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(*_args) | ||
Form | ||
.where("created_at < ?", 1.day.ago) | ||
.delete_all | ||
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 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,3 @@ | ||
delete_stale_forms: | ||
cron: "0 1 * * *" | ||
class: DeleteStaleFormsJob |
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,23 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe DeleteStaleFormsJob do | ||
subject(:job) { described_class.new } | ||
|
||
describe "perform" do | ||
let(:stale_form) { build(:form, created_at: 25.hours.ago) } | ||
let(:form) { build(:form) } | ||
|
||
before do | ||
stale_form.save | ||
form.save | ||
end | ||
|
||
it { expect { job.perform }.to change(Form, :count).from(2).to(1) } | ||
|
||
context "delete stale forms" do | ||
before { job.perform } | ||
|
||
it { expect { Form.find(id: stale_form.id) }.to raise_error(ActiveRecord::RecordNotFound) } | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "Schedule jobs" do | ||
subject(:schedule_jobs) { YAML.load_file(schedule_file_path) } | ||
let(:schedule_file_path) { "config/schedule.yml" } | ||
|
||
it "config file exists" do | ||
expect(schedule_jobs).to be_present | ||
end | ||
|
||
describe "DeleteStaleFormsJob" do | ||
let(:job_name) { "delete_stale_forms" } | ||
let(:job) { schedule_jobs[job_name] } | ||
|
||
it "schedule time" do | ||
expect(job["cron"]).to eq("0 1 * * *") | ||
end | ||
|
||
it "job class name" do | ||
expect(job["class"]).to eq("DeleteStaleFormsJob") | ||
end | ||
end | ||
end |