Sha256: e1b81ae2553dc4da187c5cf9d2dec9aa4113dc26dfa0f06eab4077adda782282

Contents?: true

Size: 861 Bytes

Versions: 16

Compression:

Stored size: 861 Bytes

Contents

# The base class for all jobs that should be performed in the context of a
# particular Shop's API session. The first argument to any job inheriting from
# this class must be the domain of the relevant store, so that the appropriate
# Shop model can be fetched and the temporary API session created.
class DiscoApp::ShopJob < ActiveJob::Base

  queue_as :default

  before_perform { |job| find_shop(job) }
  before_enqueue { |job| find_shop(job) }

  around_enqueue { |job, block| shop_context(job, block) }
  around_perform { |job, block| shop_context(job, block) }

  private

    def find_shop(job)
      @shop ||= job.arguments.first.is_a?(DiscoApp::Shop) ? job.arguments.first : DiscoApp::Shop.find_by!(shopify_domain: job.arguments.first)
    end

    def shop_context(job, block)
      @shop.temp {
        block.call(job.arguments)
      }
    end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
disco_app-0.9.4 app/jobs/disco_app/shop_job.rb
disco_app-0.9.5 app/jobs/disco_app/shop_job.rb
disco_app-0.9.6 app/jobs/disco_app/shop_job.rb
disco_app-0.9.7 app/jobs/disco_app/shop_job.rb
disco_app-0.9.8 app/jobs/disco_app/shop_job.rb
disco_app-0.9.9 app/jobs/disco_app/shop_job.rb
disco_app-0.9.10 app/jobs/disco_app/shop_job.rb
disco_app-0.9.11 app/jobs/disco_app/shop_job.rb
disco_app-0.10.0 app/jobs/disco_app/shop_job.rb
disco_app-0.10.1 app/jobs/disco_app/shop_job.rb
disco_app-0.10.2 app/jobs/disco_app/shop_job.rb
disco_app-0.10.3 app/jobs/disco_app/shop_job.rb
disco_app-0.10.4 app/jobs/disco_app/shop_job.rb
disco_app-0.10.5 app/jobs/disco_app/shop_job.rb
disco_app-0.11.0 app/jobs/disco_app/shop_job.rb
disco_app-0.11.1 app/jobs/disco_app/shop_job.rb