Sha256: d442717d565f5292c14192f2294d6466c8d92c86b2c4d8f660de7d4e81a69540

Contents?: true

Size: 873 Bytes

Versions: 11

Compression:

Stored size: 873 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.with_api_context {
        block.call(job.arguments)
      }
    end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
disco_app-0.12.0 app/jobs/disco_app/shop_job.rb
disco_app-0.12.1 app/jobs/disco_app/shop_job.rb
disco_app-0.12.5 app/jobs/disco_app/shop_job.rb
disco_app-0.12.6 app/jobs/disco_app/shop_job.rb
disco_app-0.12.7 app/jobs/disco_app/shop_job.rb
disco_app-0.13.0 app/jobs/disco_app/shop_job.rb
disco_app-0.13.1 app/jobs/disco_app/shop_job.rb
disco_app-0.13.2 app/jobs/disco_app/shop_job.rb
disco_app-0.13.3 app/jobs/disco_app/shop_job.rb
disco_app-0.13.4 app/jobs/disco_app/shop_job.rb
disco_app-0.12.7.pre.puma.pre.3 app/jobs/disco_app/shop_job.rb