Class: Factor::Commands::WorkflowCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/commands/workflow_command.rb

Overview

Workflow is a Command to start the factor runtime from the CLI

Constant Summary

Constants inherited from Command

Command::DEFAULT_FILENAME

Instance Attribute Summary

Attributes inherited from Command

#logger

Instance Method Summary collapse

Methods inherited from Command

#load_config, #save_config

Constructor Details

#initializeWorkflowCommand

Returns a new instance of WorkflowCommand.



10
11
12
13
# File 'lib/commands/workflow_command.rb', line 10

def initialize
  @workflows = {}
  super
end

Instance Method Details

#cloud(args, options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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/commands/workflow_command.rb', line 28

def cloud(args, options)
  , workflow_id, api_key = args
  host        = (options.host || "https://factor.io").sub(/(\/)+$/,'')

  if !api_key || !workflow_id || !
    logger.error "API Key, Worklfow ID and Acount ID are all required"
    exit
  end

  logger.info "Getting workflow (#{workflow_id}) from Factor.io Cloud"
  begin
    workflow_url = "#{host}/#{}/workflows/#{workflow_id}.json?auth_token=#{api_key}"
    raw_content = RestClient.get(workflow_url)
    workflow_info = JSON.parse(raw_content)
  rescue => ex
    logger.error "Couldn't retreive workflow: #{ex.message}"
    exit
  end

  workflow_definition = workflow_info["definition"]

  logger.info "Getting credentials from Factor.io Cloud"
  begin
    credential_url = "#{host}/#{}/credentials.json?auth_token=#{api_key}"
    raw_content = RestClient.get(credential_url)
    credentials = JSON.parse(raw_content)
  rescue => ex
    logger.error "Couldn't retreive workflow: #{ex.message}"
    exit
  end

  configatron[:credentials].configure_from_hash(credentials)

  logger.info "Getting connectors from Factor.io Cloud"
  connectors = {}
  begin
    connectors_url = "#{host}/#{}/connectors.json?auth_token=#{api_key}"
    raw_content = RestClient.get(connectors_url)
    raw_connectors = JSON.parse(raw_content)

    raw_connectors.each do |connector_id,connector_info|
      connectors[connector_id] = connector_info['connectors'].values.first
    end
  rescue => ex
    logger.error "Couldn't retreive workflow: #{ex.message}"
    exit
  end

  configatron[:connectors].configure_from_hash(connectors)

  @workflows[workflow_id] = load_workflow_from_definition(workflow_definition)

  block_until_interupt

  logger.info 'Good bye!'
end

#server(_args, options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/commands/workflow_command.rb', line 15

def server(_args, options)
  config_settings = {}
  config_settings[:credentials] = options.credentials
  config_settings[:connectors]  = options.connectors
  workflow_filename = File.expand_path(options.path || '.')
  @destination_stream = File.new(options.log, 'w+') if options.log

  load_config(config_settings)
  load_all_workflows(workflow_filename)
  block_until_interupt
  logger.info 'Good bye!'
end