Skip to content

Commit

Permalink
Another job test
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-nathan committed Aug 2, 2024
1 parent 818c67b commit 97f7ce1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/jobs/field_slip_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,35 @@ class FieldSlipJob < ApplicationJob
queue_as :default

def perform(tracker_id)
extra_log("Start")
log("Starting FieldSlipJob.perform(#{tracker_id})")
cleanup_old_pdfs(tracker_id)
tracker = FieldSlipJobTracker.find(tracker_id)
raise(:field_slip_job_no_tracker.t) unless tracker

extra_log("Processing")
tracker.processing
icon = "public/logo-120.png"
view = FieldSlipView.new(tracker, icon)
view.render
view.save_as(tracker.filepath)
extra_log("Done")
tracker.done
log("Done with FieldSlipJob.perform(#{tracker_id})")
extra_log("End")
tracker.filepath
end

private

MAX_JOB_AGE = 1.week

def extra_log(msg)
open("/tmp/extra_log", "a") do |f|
f.write("#{msg}\n")
end
end

def cleanup_old_pdfs(tracker_id)
FieldSlipJobTracker.where.not(id: tracker_id).find_each do |tracker|
next unless tracker.updated_at < Time.zone.now - MAX_JOB_AGE
Expand Down

0 comments on commit 97f7ce1

Please sign in to comment.