diff --git a/app/jobs/field_slip_job.rb b/app/jobs/field_slip_job.rb index e7342c841d..d06dd2d808 100644 --- a/app/jobs/field_slip_job.rb +++ b/app/jobs/field_slip_job.rb @@ -4,22 +4,22 @@ 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 @@ -27,12 +27,6 @@ def perform(tracker_id) 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 diff --git a/app/models/field_slip_job_tracker.rb b/app/models/field_slip_job_tracker.rb index 0baed7ac4f..bf7b0efea2 100644 --- a/app/models/field_slip_job_tracker.rb +++ b/app/models/field_slip_job_tracker.rb @@ -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) diff --git a/db/migrate/20240802010123_add_notes_to_field_slip_job_trackers.rb b/db/migrate/20240802010123_add_notes_to_field_slip_job_trackers.rb new file mode 100644 index 0000000000..e78adf0cf1 --- /dev/null +++ b/db/migrate/20240802010123_add_notes_to_field_slip_job_trackers.rb @@ -0,0 +1,5 @@ +class AddNotesToFieldSlipJobTrackers < ActiveRecord::Migration[7.1] + def change + add_column :field_slip_job_trackers, :notes, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 53a1d97ec7..879a141934 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 @@ -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|