free_mutant/lib/mutant/runner.rb

102 lines
1.7 KiB
Ruby
Raw Normal View History

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)
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
# Initialize object
#
# @return [undefined]
#
# @api private
#
2014-10-23 07:37:53 -04:00
def initialize(*)
super
reporter.start(env)
2014-10-23 07:37:53 -04:00
config.integration.setup
2014-10-23 07:37:53 -04:00
@master = config.actor_env.current.bind(Master.call(env))
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)
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
2014-10-23 07:37:53 -04:00
# Return reporter
#
2014-10-23 07:37:53 -04:00
# @return [Reporter]
#
# @api private
#
2014-10-23 07:37:53 -04:00
def reporter
env.config.reporter
end
# Return config
#
# @return [Config]
#
# @api private
#
def config
env.config
end
2014-10-23 07:37:53 -04:00
# Return current status
#
2014-10-23 07:37:53 -04:00
# @return [Status]
#
# @api private
#
2014-10-23 07:37:53 -04:00
def current_status
@master.call(:status)
end
2013-06-14 14:54:02 -04:00
end # Runner
end # Mutant