mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-10 23:07:47 +00:00
Run a job queue heartbeat every 5 minutes
This commit is contained in:
5
app/jobs/heartbeat_job.rb
Normal file
5
app/jobs/heartbeat_job.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class HeartbeatJob
|
||||
def perform
|
||||
Spree::Config.last_job_queue_heartbeat_at = Time.now
|
||||
end
|
||||
end
|
||||
@@ -20,4 +20,7 @@ Spree::AppConfiguration.class_eval do
|
||||
preference :account_invoices_monthly_rate, :decimal, default: 0
|
||||
preference :account_invoices_monthly_cap, :decimal, default: 0
|
||||
preference :account_invoices_tax_rate, :decimal, default: 0
|
||||
|
||||
# Monitoring
|
||||
preference :last_job_queue_heartbeat_at, :string, default: nil
|
||||
end
|
||||
|
||||
@@ -4,9 +4,13 @@ require 'whenever'
|
||||
|
||||
env "MAILTO", "rohan@rohanmitchell.com"
|
||||
|
||||
|
||||
# If we use -e with a file containing specs, rspec interprets it and filters out our examples
|
||||
job_type :run_file, "cd :path; :environment_variable=:environment bundle exec script/rails runner :task :output"
|
||||
|
||||
job_type :enqueue_job, "cd :path; :environment_variable=:environment bundle exec script/rails runner 'Delayed::Job.enqueue(:task.new, priority: :priority)' :output"
|
||||
|
||||
|
||||
every 1.hour do
|
||||
rake 'openfoodnetwork:cache:check_products_integrity'
|
||||
end
|
||||
@@ -23,6 +27,10 @@ every 4.hours do
|
||||
rake 'db2fog:backup'
|
||||
end
|
||||
|
||||
every 5.minutes do
|
||||
enqueue_job 'QueueHeartbeatJob', priority: 0
|
||||
end
|
||||
|
||||
every 1.day, at: '1:00am' do
|
||||
rake 'openfoodnetwork:billing:update_account_invoices'
|
||||
end
|
||||
|
||||
27
spec/jobs/heartbeat_job_spec.rb
Normal file
27
spec/jobs/heartbeat_job_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe HeartbeatJob do
|
||||
context "with time frozen" do
|
||||
let(:run_time) { Time.zone.local(2016, 4, 13, 13, 0, 0) }
|
||||
|
||||
before { Spree::Config.last_job_queue_heartbeat_at = nil }
|
||||
|
||||
around do |example|
|
||||
Timecop.freeze(run_time) { example.run }
|
||||
end
|
||||
|
||||
it "updates the last_job_queue_heartbeat_at config var" do
|
||||
run_job
|
||||
Time.parse(Spree::Config.last_job_queue_heartbeat_at).should == run_time
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def run_job
|
||||
clear_jobs
|
||||
Delayed::Job.enqueue HeartbeatJob.new
|
||||
flush_jobs ignore_exceptions: false
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user