Shopify / job-iteration

Makes your background jobs interruptible and resumable by design.
https://www.rubydoc.info/gems/job-iteration
MIT License
1.15k stars 45 forks source link

Support SolidQueue #496

Closed tmimura39 closed 2 months ago

tmimura39 commented 3 months ago

Hi, I am currently using this Gem with Sidekiq as backend. (To be precise, we use maintenance_tasks.)

We are considering moving from Sidekiq to SolidQueue SolidQueue will be the default backend for ActiveJob in Rails v8

It appears that the job-iteration gem does not currently define an interruption_adapter for SolidQueue. How about adding SolidQueue's interruption_adapter in the job-iteration gem to help many people?

This is the kind of content we're expecting.

# frozen_string_literal: true

begin
  require "solid_queue"
rescue LoadError
  # SolidQueue is not available, no need to load the adapter
  return
end

begin
  # SolidQueue.on_worker_stop was introduced in SolidQueue 0.7.1
  gem("solid_queue", ">= 0.7.1")
rescue Gem::LoadError
  warn("job-iteration's interruption adapter for SolidQueue requires SolidQueue 0.7.1 or newer")
  return
end

module JobIteration
  module InterruptionAdapters
    module SolidQueueAdapter
      class << self
        attr_accessor :stopping

        def call
          stopping
        end
      end
    end

    SolidQueue.on_worker_stop do
      JobIteration::Integrations::SolidQueueAdapter.stopping = true
    end

    register(:solid_queue, SolidQueueAdapter)
  end
end
tmimura39 commented 3 months ago

We are having SolidQueue add the functionality to the SolidQueue side. Soon you will be able to create an optimal SolidQueueAdapter.

https://github.com/rails/solid_queue/issues/282#issuecomment-2327657330