2014-12-08 19:10:31 -05:00
|
|
|
module Mutant
|
2015-07-06 14:36:39 -04:00
|
|
|
# Parallel execution engine of arbitrary payloads
|
2014-12-08 19:10:31 -05:00
|
|
|
module Parallel
|
|
|
|
|
|
|
|
# Driver for parallelized execution
|
|
|
|
class Driver
|
|
|
|
include Concord.new(:binding)
|
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Scheduler status
|
2014-12-08 19:10:31 -05:00
|
|
|
#
|
|
|
|
# @return [Object]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def status
|
|
|
|
binding.call(__method__)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Stop master gracefully
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def stop
|
|
|
|
binding.call(__method__)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end # Driver
|
|
|
|
|
|
|
|
# Run async computation returing driver
|
|
|
|
#
|
|
|
|
# @return [Driver]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def self.async(config)
|
|
|
|
Driver.new(config.env.new_mailbox.bind(Master.call(config)))
|
|
|
|
end
|
|
|
|
|
|
|
|
# Job result sink
|
|
|
|
class Sink
|
|
|
|
include AbstractType
|
|
|
|
|
|
|
|
# Process job result
|
|
|
|
#
|
|
|
|
# @param [Object]
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
abstract_method :result
|
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Sink status
|
2014-12-08 19:10:31 -05:00
|
|
|
#
|
|
|
|
# @return [Object]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
abstract_method :status
|
|
|
|
|
|
|
|
# Test if processing should stop
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
abstract_method :stop?
|
|
|
|
end # Sink
|
|
|
|
|
|
|
|
# Job to push to workers
|
|
|
|
class Job
|
|
|
|
include Adamantium::Flat, Anima.new(:index, :payload)
|
|
|
|
end # Job
|
|
|
|
|
|
|
|
# Job result object received from workers
|
|
|
|
class JobResult
|
|
|
|
include Adamantium::Flat, Anima.new(:job, :payload)
|
|
|
|
end # JobResult
|
|
|
|
|
|
|
|
# Parallel run configuration
|
|
|
|
class Config
|
2015-09-04 16:20:56 -04:00
|
|
|
include Adamantium::Flat, Anima.new(:env, :processor, :source, :sink, :jobs)
|
2014-12-08 19:10:31 -05:00
|
|
|
end # Config
|
|
|
|
|
|
|
|
# Parallel execution status
|
|
|
|
class Status
|
2015-09-04 16:20:56 -04:00
|
|
|
include Adamantium::Flat, Anima.new(:payload, :done, :active_jobs)
|
2014-12-08 19:10:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end # Parallel
|
|
|
|
end # Mutant
|