Class: Agents::RubyAgent
- Inherits:
-
Agent
- Object
- Agent
- Agents::RubyAgent
- Includes:
- FormConfigurable
- Defined in:
- lib/agents/ruby_agent.rb
Instance Method Summary collapse
- #check ⇒ Object
- #default_options ⇒ Object
- #receive(events) ⇒ Object
- #validate_options ⇒ Object
- #working? ⇒ Boolean
Instance Method Details
#check ⇒ Object
61 62 63 64 65 |
# File 'lib/agents/ruby_agent.rb', line 61 def check running_agent do |agent| agent.check end end |
#default_options ⇒ Object
73 74 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 |
# File 'lib/agents/ruby_agent.rb', line 73 def 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
67 68 69 70 71 |
# File 'lib/agents/ruby_agent.rb', line 67 def receive(events) running_agent do |agent| agent.receive events end end |
#validate_options ⇒ Object
42 43 44 |
# File 'lib/agents/ruby_agent.rb', line 42 def errors.add(:base, "The 'code' option is required") unless ['code'].present? end |
#working? ⇒ Boolean
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/agents/ruby_agent.rb', line 46 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 |