2012-08-14 16:45:34 -04:00
|
|
|
module Mutant
|
2013-04-20 14:50:36 -04:00
|
|
|
# Runner baseclass
|
2012-08-14 16:45:34 -04:00
|
|
|
class Runner
|
2014-07-17 09:59:25 -04:00
|
|
|
include Adamantium::Flat, Concord.new(:env), Procto.call(:result)
|
2013-07-14 19:17:15 -04:00
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
# Status of the runner execution
|
|
|
|
class Status
|
|
|
|
include Adamantium, Anima::Update, Anima.new(
|
|
|
|
:env_result,
|
|
|
|
:active_jobs,
|
|
|
|
:done
|
|
|
|
)
|
|
|
|
end # Status
|
|
|
|
|
|
|
|
# Job to push to workers
|
|
|
|
class Job
|
|
|
|
include Adamantium::Flat, Anima.new(:index, :mutation)
|
|
|
|
end # Job
|
|
|
|
|
|
|
|
# Job result object received from workers
|
|
|
|
class JobResult
|
|
|
|
include Adamantium::Flat, Anima.new(:job, :result)
|
|
|
|
end
|
|
|
|
|
|
|
|
REPORT_FREQUENCY = 20.0
|
|
|
|
REPORT_DELAY = 1 / REPORT_FREQUENCY
|
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
# Initialize object
|
2013-07-14 19:17:15 -04:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-10-23 07:37:53 -04:00
|
|
|
def initialize(*)
|
2014-07-03 17:16:12 -04:00
|
|
|
super
|
2013-07-14 19:17:15 -04:00
|
|
|
|
2014-10-07 19:47:28 -04:00
|
|
|
reporter.start(env)
|
2014-10-23 07:37:53 -04:00
|
|
|
config.integration.setup
|
2014-08-10 18:09:29 -04:00
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
@master = config.actor_env.current.bind(Master.call(env))
|
2014-07-03 17:16:12 -04:00
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
status = nil
|
2014-07-17 09:59:25 -04:00
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
loop do
|
|
|
|
status = current_status
|
|
|
|
break if status.done
|
|
|
|
reporter.progress(status)
|
|
|
|
Kernel.sleep(REPORT_DELAY)
|
2014-10-07 19:47:28 -04:00
|
|
|
end
|
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
reporter.progress(status)
|
2013-01-15 17:46:05 -05:00
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
@master.call(:stop)
|
2014-07-17 09:59:25 -04:00
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
@result = status.env_result
|
2014-07-17 09:59:25 -04:00
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
reporter.report(@result)
|
2014-07-17 09:59:25 -04:00
|
|
|
end
|
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
# Return result
|
2014-07-17 09:59:25 -04:00
|
|
|
#
|
2014-10-23 07:37:53 -04:00
|
|
|
# @return [Result::Env]
|
2014-07-17 09:59:25 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-10-23 07:37:53 -04:00
|
|
|
attr_reader :result
|
2014-07-17 09:59:25 -04:00
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
private
|
2013-07-14 19:17:15 -04:00
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
# Return reporter
|
2014-07-14 09:55:18 -04:00
|
|
|
#
|
2014-10-23 07:37:53 -04:00
|
|
|
# @return [Reporter]
|
2014-07-14 09:55:18 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-10-23 07:37:53 -04:00
|
|
|
def reporter
|
|
|
|
env.config.reporter
|
2014-07-14 09:55:18 -04:00
|
|
|
end
|
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
# Return config
|
2013-04-20 20:20:18 -04:00
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
# @return [Config]
|
2013-04-20 20:20:18 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
def config
|
|
|
|
env.config
|
2013-04-20 20:20:18 -04:00
|
|
|
end
|
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
# Return current status
|
2014-10-07 19:47:28 -04:00
|
|
|
#
|
2014-10-23 07:37:53 -04:00
|
|
|
# @return [Status]
|
2014-10-07 19:47:28 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-10-23 07:37:53 -04:00
|
|
|
def current_status
|
|
|
|
@master.call(:status)
|
2014-10-07 19:47:28 -04:00
|
|
|
end
|
|
|
|
|
2013-06-14 14:54:02 -04:00
|
|
|
end # Runner
|
|
|
|
end # Mutant
|