Skip to content

Commit

Permalink
Add notes to the FieldSlipJobTracker object
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-nathan committed Aug 2, 2024
1 parent f63122c commit 397a0f3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
14 changes: 4 additions & 10 deletions app/jobs/field_slip_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,29 @@ 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)
tracker.append_note("Got tracker")
tracker.append_note(Dir.glob("public/field_slips/*").join("\n"))
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.append_note("Done")
tracker.append_note(Dir.glob("public/field_slips/*").join("\n"))
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
5 changes: 5 additions & 0 deletions app/models/field_slip_job_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def elapsed_time
end
end

def append_note(note)
self.notes = (self.notes || "") + note + "\n"
save
end

private

def code_num(num)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNotesToFieldSlipJobTrackers < ActiveRecord::Migration[7.1]
def change
add_column :field_slip_job_trackers, :notes, :text
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_08_01_202223) do
ActiveRecord::Schema[7.1].define(version: 2024_08_02_010123) do
create_table "api_keys", id: :integer, charset: "utf8mb3", force: :cascade do |t|
t.datetime "created_at", precision: nil
t.datetime "last_used", precision: nil
Expand Down Expand Up @@ -97,6 +97,7 @@
t.integer "user_id"
t.boolean "one_per_page", default: false, null: false
t.integer "version", default: 1
t.text "notes"
end

create_table "field_slips", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
Expand Down

0 comments on commit 397a0f3

Please sign in to comment.