Method: TaskBatcher#process_batch

Defined in:
lib/task_batcher.rb

#process_batch(taskname) ⇒ Object

Generally, the #process_batch method will be called by Event Machine when the batch duration expires. However, it is public because the caller may want to explicitly process a batch.

Parameters:

  • taskname (String, Symbol)

    the name of the batch to process



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/task_batcher.rb', line 196

def process_batch(taskname)
  this_batch = nil

  # Grab the batch.  If another TaskBatcher call is added immediately after
  # this synchronize step, then it just starts a new batch.
  mutex.synchronize do
    this_batch = batches[taskname]
    batches[taskname] = nil
  end
  return nil if this_batch.nil?

  # Grab the block, list of batch args, and callback.  Then run the batch!
  batch_processor = this_batch[:block]
  args_hashes = this_batch[:args_hashes]
  callback = this_batch[:callback] || lambda {|arg_hashes| nil}
  begin
    results = batch_processor[args_hashes]
  rescue Exception => e
    raise Error, "Exception raised during TaskBatcher processing:\n" +
      "#{e.backtrace.join("\n   ")}"
  end

  # Run the callback.  The callback's return value isn't accessible in any
  # meaningful way.
  callback[results]
end