Class: Agents::RubyAgent

Inherits:
Agent
  • Object
show all
Includes:
FormConfigurable
Defined in:
lib/huginn_ruby_agent/ruby_agent.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



63
64
65
66
67
# File 'lib/huginn_ruby_agent/ruby_agent.rb', line 63

def check
  log_errors do
    execute_check
  end
end

#default_optionsObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/huginn_ruby_agent/ruby_agent.rb', line 75

def default_options
  code = "\n    require \"bundler/inline\"\n\n    gemfile do\n      source \"https://rubygems.org\"\n\n      # gem \"mechanize\"\n    end\n\n    class Agent\n      def initialize(api)\n        @api = api\n      end\n\n      def check\n        @api.create_event({ message: 'I made an event!' })\n      end\n\n      def receive(incoming_events)\n        incoming_events.each do |event|\n          @api.create_event({ message: 'new event', event_was: event[:payload] })\n        end\n      end\n    end\n  CODE\n\n  {\n    'code' => code,\n    'expected_receive_period_in_days' => '2',\n    'expected_update_period_in_days' => '2'\n  }\nend\n"

#receive(events) ⇒ Object



69
70
71
72
73
# File 'lib/huginn_ruby_agent/ruby_agent.rb', line 69

def receive(events)
  log_errors do
    execute_receive(events)
  end
end

#validate_optionsObject



45
46
47
# File 'lib/huginn_ruby_agent/ruby_agent.rb', line 45

def validate_options
  errors.add(:base, "The 'code' option is required") unless options['code'].present?
end

#working?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/huginn_ruby_agent/ruby_agent.rb', line 49

def working?
  return false if recent_error_logs?

  if interpolated['expected_update_period_in_days'].present?
    return false unless event_created_within?(interpolated['expected_update_period_in_days'])
  end

  if interpolated['expected_receive_period_in_days'].present?
    return false unless last_receive_at && last_receive_at > interpolated['expected_receive_period_in_days'].to_i.days.ago
  end

  true
end