Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notes to the FieldSlipJobTracker object #2280

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = (notes || "") + note + "\n"
save
end

private

def code_num(num)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

class AddVersionToFieldSlipJobTrackers < ActiveRecord::Migration[7.1]
def change
add_column :field_slip_job_trackers, :version, :integer, default: 1
add_column(:field_slip_job_trackers, :version, :integer, default: 1)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

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
Loading