Class: Factor::Commands::Workflow
- Defined in:
- lib/commands/workflows.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 ⇒ Workflow
constructor
A new instance of Workflow.
- #server(_args, options) ⇒ Object
Methods inherited from Command
#error, #exception, #info, #load_config, #save_config, #success, #warn
Constructor Details
#initialize ⇒ Workflow
Returns a new instance of Workflow.
12 13 14 |
# File 'lib/commands/workflows.rb', line 12 def initialize @workflows = {} end |
Instance Method Details
#cloud(args, options) ⇒ Object
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 84 |
# File 'lib/commands/workflows.rb', line 29 def cloud(args, ) account_id, workflow_id, api_key = args host = (.host || "https://factor.io").sub(/(\/)+$/,'') if !api_key || !workflow_id || !account_id error "API Key, Worklfow ID and Acount ID are all required" exit end 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 error "Couldn't retreive workflow: #{ex.}" exit end workflow_definition = workflow_info["definition"] 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 error "Couldn't retreive workflow: #{ex.}" exit end configatron[:credentials].configure_from_hash(credentials) 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 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 info 'Good bye!' end |
#server(_args, options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/commands/workflows.rb', line 16 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 info 'Good bye!' end |