Files
danbooru/app/jobs/application_job.rb
evazion a07e6667b4 jobs: fix backwards job priorities.
Fix bug where jobs had the opposite of the intended priority. Populating saved searches had the
highest priority, while processing uploads had the lowest priority.

Caused by Delayed::Job and GoodJob having opposite interpretations of job priorities. In
Delayed::Job, lower numbers had higher priority, while in GoodJob, higher numbers have higher
priority. This was missed when migrating from Delayed::Job to GoodJob.
2022-11-30 17:56:10 -06:00

37 lines
1009 B
Ruby

# frozen_string_literal: true
# The base class for all background jobs on Danbooru.
#
# @see https://guides.rubyonrails.org/active_job_basics.html
# @see https://github.com/bensheldon/good_job
class ApplicationJob < ActiveJob::Base
# Preload subclasses so `job_classes` returns all subclasses in development mode.
Dir["#{__dir__}/*.rb"].each { |file| require file }
class JobTimeoutError < StandardError; end
queue_as :default
# Jobs with higher priority are processed first. Higher number = higher priority.
queue_with_priority 0
around_perform do |_job, block|
CurrentUser.scoped(User.system) do
ApplicationRecord.without_timeout do
Timeout.timeout(24.hours, JobTimeoutError) do
block.call
end
end
end
end
discard_on ActiveJob::DeserializationError do |_job, error|
DanbooruLogger.log(error)
end
# A list of all available job types. Used by the /jobs search form.
def self.job_classes
subclasses.sort_by(&:name)
end
end