Class: Flydata::Helper::Action::CheckRemoteActions

Inherits:
BaseAction
  • Object
show all
Defined in:
lib/flydata/helper/action/check_remote_actions.rb

Instance Attribute Summary

Attributes inherited from BaseAction

#config

Instance Method Summary collapse

Methods inherited from BaseAction

#get_service

Constructor Details

#initialize(config) ⇒ CheckRemoteActions

Returns a new instance of CheckRemoteActions.



9
10
11
12
# File 'lib/flydata/helper/action/check_remote_actions.rb', line 9

def initialize(config)
  super
  @api_client = ApiClient.instance
end

Instance Method Details

#execute(opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/flydata/helper/action/check_remote_actions.rb', line 14

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