Sha256: ca0e12bb8db13b68fdc92f90c1db9df0ddbf56f74ec95f9aa0b7b094cef5e764

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

# encoding: UTF-8

require 'configatron'

require 'commands/base'
require 'runtime/workflow'

require 'pp'

module Factor
  module Commands
    class RunCommand < Factor::Commands::Command
      def initialize
        @workflows = {}
        super
      end

      def run(args, options)
        config_settings = {}
        config_settings[:credentials] = options.credentials
        config_settings[:connectors]  = options.connectors
        load_config(config_settings)

        connector_settings = configatron.connectors.to_hash
        credential_settings = configatron.credentials.to_hash
        runtime = Factor::Runtime::Workflow.new(connector_settings, credential_settings, logger: logger)

        begin
          params = JSON.parse(args[1] || '{}')
        rescue => ex
          logger.error "'#{args[1]}' can't be parsed as JSON"
        end

        if params
          EM.run do
            runtime.run(args[0],params) do |response_info|
              data = response_info.is_a?(Array) ? response_info.map {|i| i.marshal_dump} : response_info.marshal_dump
              JSON.pretty_generate(data).split("\n").each do |line|
                logger.info line
              end
              EM.stop
            end.on_fail do
              EM.stop
            end
          end

          logger.info 'Good bye!'
        end
      end



      private

      def block_until_interupt
        logger.info 'Ctrl-c to exit'
        begin
          loop do
            sleep 1
          end
        rescue Interrupt
          logger.info 'Exiting app...'
        end
      end


    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
factor-0.6.8 lib/commands/run_command.rb
factor-0.6.7 lib/commands/run_command.rb
factor-0.6.6 lib/commands/run_command.rb