Class: Baleen::Runner
- Inherits:
-
Object
- Object
- Baleen::Runner
- Extended by:
- Forwardable
- Includes:
- Celluloid
- Defined in:
- lib/baleen/runner.rb
Instance Method Summary collapse
-
#initialize(task, connection = nil) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
Constructor Details
#initialize(task, connection = nil) ⇒ Runner
Returns a new instance of Runner.
46 47 48 49 50 |
# File 'lib/baleen/runner.rb', line 46 def initialize(task, connection=nil) @container = Docker::Container.create('Cmd' => ["bash", "-c", task.commands], 'Image' => task.image) @connection = connection ? connection : Connection.new @task = task end |
Instance Method Details
#run ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/baleen/runner.rb', line 52 def run max_retry = 3; count = 0 begin notify_info("Start container #{@container.id}") @container.start @container.wait(600) #TODO move to configuration notify_info("Finish container #{@container.id}") if @task.commit notify_info("Committing the change of container #{@container.id}") @container.commit({repo: @task.image}) if @task.commit end rescue Excon::Errors::NotFound => e count += 1 if count > max_retry raise Baleen::Error::StartContainerFail else retry end end stdout, stderr = *@container.attach(:stream => false, :stdout => true, :stderr => true, :logs => true) return { status_code: @container.json["State"]["ExitCode"], container_id: @container.id, stdout: stdout, stderr: stderr, file: @task.files, } end |