Class: Coursemology::Evaluator::DockerContainer

Inherits:
Docker::Container
  • Object
show all
Defined in:
lib/coursemology/evaluator/docker_container.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(image, argv: nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/coursemology/evaluator/docker_container.rb', line 4

def create(image, argv: nil)
  pull_image(image)

  ActiveSupport::Notifications.instrument('create.docker.evaluator.coursemology',
                                          image: image) do |payload|
    options = { 'Image' => image }
    options['Cmd'] = argv if argv && !argv.empty?

    payload[:container] = super(options)
  end
end

Instance Method Details

#deleteObject



73
74
75
76
77
78
# File 'lib/coursemology/evaluator/docker_container.rb', line 73

def delete
  ActiveSupport::Notifications.instrument('destroy.docker.evaluator.coursemology',
                                          container: id) do
    super
  end
end

#exit_codeFixnum?

Gets the exit code of the container.

Returns:

  • (Fixnum)

    The exit code of the container, if wait was called before.

  • (nil)

    If the container is still running, or wait was not called.



69
70
71
# File 'lib/coursemology/evaluator/docker_container.rb', line 69

def exit_code
  info.fetch('State', {})['ExitCode']
end

#wait(time = nil) ⇒ Fixnum

Waits for the container to exit the Running state.

This will time out for long running operations, so keep retrying until we return.

Parameters:

  • time (Fixnum|nil) (defaults to: nil)

    The amount of time to wait.

Returns:

  • (Fixnum)

    The exit code of the container.



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/coursemology/evaluator/docker_container.rb', line 52

def wait(time = nil)
  container_state = info
  while container_state.fetch('State', {}).fetch('Running', true)
    super
    refresh!
    container_state = info
  end

  container_state['State']['ExitCode']
rescue Docker::Error::TimeoutError
  retry
end