Sha256: 69d035aff9c66ed98a5342a912038ea9d20ac937cc299bd25501a9e7c2b7db67

Contents?: true

Size: 1.35 KB

Versions: 15

Compression:

Stored size: 1.35 KB

Contents

require 'flydata/util/file_util'
require 'flydata/api_client'
require 'flydata/helper/base_action'

module Flydata
  module Helper
    module Action
      class CheckRemoteActions < BaseAction
        def initialize(config)
          super
          @api_client = ApiClient.instance
        end

        def execute(opts = {})
          action_position = ActionPosition.new(config)

          # Get actions from flydata web server
          last_id = action_position.load
          actions = @api_client.agent.actions(last_id)

          actions['actions'].each do |action|
            action_name = action['name']
            action_id = action['id'].to_i
            action_info = { id: action_id, config: action['config'] }
            # Request action
            yield action_name.to_sym, action_info
            last_id = action_id if action_id > last_id
          end

          if last_id > 0
            action_position.save(last_id)
            true   # for debug
          else
            false  # for debug
          end
        end
      end

      class ActionPosition
        include Util::FileUtil

        def initialize(config)
          @path = config.helper_action_position_path
        end
        def save(position)
          write_line(@path, position.to_s)
        end
        def load
          read_line(@path).to_i
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
flydata-0.5.10 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.5.9 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.5.8 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.5.7 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.5.6 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.5.5 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.5.4 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.5.3 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.5.2 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.5.1 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.5.0 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.4.3 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.4.2 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.4.1 lib/flydata/helper/action/check_remote_actions.rb
flydata-0.4.0 lib/flydata/helper/action/check_remote_actions.rb