Class: ScatterGather::GatherJobProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/scatter_gather/gather_job_proxy.rb

Overview

Proxy class that mimics ActiveJob behavior for gather jobs

Instance Method Summary collapse

Constructor Details

#initialize(target_class, ids, config) ⇒ GatherJobProxy

Returns a new instance of GatherJobProxy.



5
6
7
8
9
# File 'lib/scatter_gather/gather_job_proxy.rb', line 5

def initialize(target_class, ids, config)
  @target_class = target_class
  @ids = ids
  @config = config.with_indifferent_access
end

Instance Method Details

#perform_later(*args, **kwargs) ⇒ void

This method returns an undefined value.

Mimic ActiveJob's perform_later method

Parameters:

  • args (Array)

    Positional arguments to pass to the target job's perform method

  • kwargs (Hash)

    Keyword arguments to pass to the target job's perform method



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/scatter_gather/gather_job_proxy.rb', line 15

def perform_later(*args, **kwargs)
  job_arguments = {cn: @target_class.name, p: args, k: kwargs}
  gather_job_params = {
    wait_for_active_job_ids: @ids,
    target_job: job_arguments,
    gather_config: @config,
    remaining_attempts: @config.fetch(:max_attempts) - 1
  }
  tagged = ActiveSupport::TaggedLogging.new(Rails.logger).tagged("ScatterGather")
  tagged.info { "Enqueueing gather job waiting for #{@ids.inspect} to run a #{@target_class.name} after" }
  ScatterGather::GatherJob.perform_later(**gather_job_params)
end