# frozen_string_literal: true module Wayfarer class Base < ActiveJob::Base include Wayfarer::Middleware::Worker extend Forwardable after_enqueue do |_job| task.counter.increment end after_perform { |job| GC.new(job).run } rescue_from(StandardError) { GC.new(self).run } def self.retry_on(*argv) super(*argv) do |job, error| job.task.barrier.seen?(job.task.url) GC.new(job).run yield job, error if block_given? end end def self.discard_on(*argv) super(*argv) do |job, error| job.task.barrier.seen?(job.task.url) GC.new(job).run yield job, error if block_given? end end def self.crawl_later(url, batch: SecureRandom.uuid) perform_later(Task.new(url, batch)) end def retry_job(...) super(...) # increments the counter by re-enqueuing the job task.counter.decrement end def perform(task) task.job = self chain.call(task) end def task arguments.first end end end