Sha256: 344b3b1d778447a5b0a0cf86398f11bc290ec5675331e6933c30f4cb932876e2

Contents?: true

Size: 1.54 KB

Versions: 4

Compression:

Stored size: 1.54 KB

Contents

# encoding: UTF-8

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

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

4 entries across 4 versions & 1 rubygems

Version Path
factor-0.6.12 lib/commands/run_command.rb
factor-0.6.11 lib/commands/run_command.rb
factor-0.6.10 lib/commands/run_command.rb
factor-0.6.9 lib/commands/run_command.rb