Class: CM::Batch::Celluloid

Inherits:
Object
  • Object
show all
Defined in:
lib/CM/batch/celluloid.rb

Instance Method Summary collapse

Instance Method Details

#execute_parallel(operation) ⇒ Object


Utilities



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/CM/batch/celluloid.rb', line 26

def execute_parallel(operation)
  values = []
  timeouts = []

  resources.each do |resource|
    values << ::Celluloid::Future.new(resource) do
      success = true
      begin
        timeouts << ( resource.respond_to?(:timeout) ? resource.timeout : nil )

        resource.execute(operation)
        success = resource.status == code.success

      rescue => error
        logger.error("Resource #{resource.id} #{operation} experienced an error:")
        logger.error(error.inspect)
        logger.error(error.message)
        logger.error(Nucleon::Util::Data.to_yaml(error.backtrace))

        error('resource_execution', { :id => resource.id, :operation => operation, :message => error.message })
        success = false
      end
      success
    end
  end
  values = values.each_with_index.map do |future, index|
    future.value(timeouts[index])
  end
  !values.include?(false)
end

#normalize(reload) ⇒ Object


Plugin interface



9
10
11
12
# File 'lib/CM/batch/celluloid.rb', line 9

def normalize(reload)
  super
  yield if block_given?
end