Class: Factor::Commands::WorkflowCommand
- 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
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
- #cloud(args, options) ⇒ Object
-
#initialize ⇒ WorkflowCommand
constructor
A new instance of WorkflowCommand.
- #server(_args, options) ⇒ Object
Methods inherited from Command
Constructor Details
#initialize ⇒ WorkflowCommand
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, ) account_id, workflow_id, api_key = args host = (.host || "https://factor.io").sub(/(\/)+$/,'') if !api_key || !workflow_id || !account_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}/#{account_id}/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.}" exit end workflow_definition = workflow_info["definition"] logger.info "Getting credentials from Factor.io Cloud" begin credential_url = "#{host}/#{account_id}/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.}" exit end configatron[:credentials].configure_from_hash(credentials) logger.info "Getting connectors from Factor.io Cloud" connectors = {} begin connectors_url = "#{host}/#{account_id}/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.}" 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, ) config_settings = {} config_settings[:credentials] = .credentials config_settings[:connectors] = .connectors workflow_filename = File.(.path || '.') @destination_stream = File.new(.log, 'w+') if .log load_config(config_settings) load_all_workflows(workflow_filename) block_until_interupt logger.info 'Good bye!' end |