Class: Floe::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/floe/runner.rb

Constant Summary collapse

OUTPUT_MARKER =
"__FLOE_OUTPUT__\n"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_options = {}) ⇒ Runner

rubocop:disable Style/RedundantInitialize



7
8
# File 'lib/floe/runner.rb', line 7

def initialize(_options = {}) # rubocop:disable Style/RedundantInitialize
end

Class Method Details

.for_resource(resource) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
27
# File 'lib/floe/runner.rb', line 22

def for_resource(resource)
  raise ArgumentError, "resource cannot be nil" if resource.nil?

  scheme = resource.split("://").first
  resolve_scheme(scheme) || raise(ArgumentError, "Invalid resource scheme [#{scheme}]")
end

.register_scheme(scheme, klass_or_proc) ⇒ Object



12
13
14
# File 'lib/floe/runner.rb', line 12

def register_scheme(scheme, klass_or_proc)
  @runners[scheme] = klass_or_proc
end

Instance Method Details

#cleanup(_runner_context) ⇒ void

This method returns an undefined value.

Cleanup runner context resources Called after a task is completed and the runner_context is no longer needed.

Parameters:

  • runner_context (Hash)

    (the value returned from run_async!)

Raises:

  • (NotImplementedError)


72
73
74
# File 'lib/floe/runner.rb', line 72

def cleanup(_runner_context)
  raise NotImplementedError, "Must be implemented in a subclass"
end

#output(_runner_context) ⇒ String, Hash

For a successful task, return the output

Parameters:

  • runner_context (Hash)

    (the value returned from run_async!)

Returns:

  • (String, Hash)

    output from task

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/floe/runner.rb', line 64

def output(_runner_context)
  raise NotImplementedError, "Must be implemented in a subclass"
end

#run_async!(_resource, _env = {}, _secrets = {}, _context = {}) ⇒ Hash

Run a command asynchronously and create a runner_context

Returns:

  • (Hash)

    runner_context

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/floe/runner.rb', line 32

def run_async!(_resource, _env = {}, _secrets = {}, _context = {})
  raise NotImplementedError, "Must be implemented in a subclass"
end

#running?(_runner_context) ⇒ Boolean

check runner_contet to determine if the task is still running or completed

Parameters:

  • runner_context (Hash)

    (the value returned from run_async!)

Returns:

  • (Boolean)

    value if the task is still running true if the task is still running false if it has completed

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/floe/runner.rb', line 48

def running?(_runner_context)
  raise NotImplementedError, "Must be implemented in a subclass"
end

#status!(_runner_context) ⇒ void

This method returns an undefined value.

update the runner_context

Parameters:

  • runner_context (Hash)

    (the value returned from run_async!)

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/floe/runner.rb', line 39

def status!(_runner_context)
  raise NotImplementedError, "Must be implemented in a subclass"
end

#success?(_runner_context) ⇒ Boolean

For a non-running? task, check if it was successful

Parameters:

  • runner_context (Hash)

    (the value returned from run_async!)

Returns:

  • (Boolean)

    value if the task is still running true if the task completed successfully false if the task had an error

Raises:

  • (NotImplementedError)


57
58
59
# File 'lib/floe/runner.rb', line 57

def success?(_runner_context)
  raise NotImplementedError, "Must be implemented in a subclass"
end