Class: Resque::Plugins::BatchedLogging::BatchLoggerProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/plugins/batched_logging.rb

Overview

For enabling MyJob.in_batches with block syntax

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_type, batch_name) ⇒ BatchLoggerProxy

Returns a new instance of BatchLoggerProxy.



61
62
63
64
65
# File 'lib/resque/plugins/batched_logging.rb', line 61

def initialize(job_type, batch_name)
  @job_type = job_type
  @batch_name = batch_name || @job_type.to_s
  @job_count = 0
end

Instance Attribute Details

#batch_nameObject (readonly)

Returns the value of attribute batch_name.



59
60
61
# File 'lib/resque/plugins/batched_logging.rb', line 59

def batch_name
  @batch_name
end

#job_countObject

Returns the value of attribute job_count.



60
61
62
# File 'lib/resque/plugins/batched_logging.rb', line 60

def job_count
  @job_count
end

#job_typeObject (readonly)

Returns the value of attribute job_type.



59
60
61
# File 'lib/resque/plugins/batched_logging.rb', line 59

def job_type
  @job_type
end

Instance Method Details

#enqueue(*args) ⇒ Object Also known as: create

Capture #create, and #enqueue calls that are done within the scope of a MyJob.in_batches block and enqueue the original job



70
71
72
73
74
75
76
77
78
79
# File 'lib/resque/plugins/batched_logging.rb', line 70

def enqueue(*args)
  if @job_type.respond_to?(:enqueue)
    @job_type.enqueue(*args)
  elsif @job_type.respond_to?(:create)
    @job_type.create(*args)
  else
    Resque.enqueue(@job_type, *args)
  end
  @job_count += 1
end

#run(&block) ⇒ Object



66
67
68
# File 'lib/resque/plugins/batched_logging.rb', line 66

def run(&block)
  instance_eval(&block) if block_given?
end