Skip to content

Commit

Permalink
Beeper.io is no more (#1808)
Browse files Browse the repository at this point in the history
* Beeper.io is no more

* Avoid event propagation or scheduling of missing agents

* Update undefined_agents.html.erb with a link to the wiki
  • Loading branch information
cantino committed Nov 27, 2016
1 parent 8e36fdd commit 8a14a57
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 282 deletions.
8 changes: 5 additions & 3 deletions app/models/agent.rb
Expand Up @@ -370,7 +370,7 @@ def dependencies_missing?
def receive!(options={})
Agent.transaction do
scope = Agent.
select("agents.id AS receiver_agent_id, events.id AS event_id").
select("agents.id AS receiver_agent_id, sources.type AS source_agent_type, agents.type AS receiver_agent_type, events.id AS event_id").
joins("JOIN links ON (links.receiver_id = agents.id)").
joins("JOIN agents AS sources ON (links.source_id = sources.id)").
joins("JOIN events ON (events.agent_id = sources.id AND events.id > links.event_id_at_creation)").
Expand All @@ -379,10 +379,11 @@ def receive!(options={})
scope = scope.where("agents.id in (?)", options[:only_receivers])
end

sql = scope.to_sql()
sql = scope.to_sql

agents_to_events = {}
Agent.connection.select_rows(sql).each do |receiver_agent_id, event_id|
Agent.connection.select_rows(sql).each do |receiver_agent_id, source_agent_type, receiver_agent_type, event_id|
next unless const_defined?(source_agent_type) && const_defined?(receiver_agent_type)
agents_to_events[receiver_agent_id.to_i] ||= []
agents_to_events[receiver_agent_id.to_i] << event_id
end
Expand Down Expand Up @@ -417,6 +418,7 @@ def run_schedule(schedule)
return if schedule == 'never'
types = where(:schedule => schedule).group(:type).pluck(:type)
types.each do |type|
next unless const_defined?(type)
type.constantize.bulk_check(schedule)
end
end
Expand Down
129 changes: 0 additions & 129 deletions app/models/agents/beeper_agent.rb

This file was deleted.

8 changes: 4 additions & 4 deletions app/views/application/undefined_agents.html.erb
Expand Up @@ -19,20 +19,20 @@
</ul>
<br/>
<p>
The issue most probably occurred because of one or more of the following reasons:
This issue probably occurred for one or more of the following reasons:
</p>
<ul>
<li>If the respective Agent is distributed as part of the Huginn application codebase, it may have been removed or moved to an Agent gem. Please see <a href="https://github.com/cantino/huginn/wiki/Dealing-with-Deleted-Agent-Types" target="_blank">this wiki page for more information</a>.</li>
<li>If the respective Agent is distributed as a Ruby gem, it might have been removed from the <code>ADDITIONAL_GEMS</code> environment setting.</li>
<li>If the respective Agent is distributed as part of the Huginn application codebase, it might have been removed from that either on purpose (because the Agent has been deprecated or been moved to an Agent gem) or accidentally. Please check if the Agent(s) in question are available in your Huginn codebase under the path <code>app/models/agents/</code>.</li>
</ul>
<br/>
<p>
You can fix the issue by adding the Agent(s) back to the application codebase by
You can fix this issue by:
</p>
<ul>
<li>deleting the respective Agent(s) from the database using the button below.</li>
<li>adding the respective Agent(s) to the the <code>ADDITIONAL_GEMS</code> environment setting. Please see <a href="https://github.com/cantino/huginn_agent" target="_blank">https://github.com/cantino/huginn_agent</a> for documentation on how to properly set it.</li>
<li>adding the respective Agent(s) code to the Huginn application codebase (in case it was deleted accidentally).</li>
<li>deleting the respective Agent(s) from the database using the button below.</li>
</ul>
<br/>
<div class="btn-group">
Expand Down
33 changes: 32 additions & 1 deletion spec/models/agent_spec.rb
Expand Up @@ -74,6 +74,13 @@
Agent.run_schedule("midnight")
end

it "ignores unknown types" do
Agent.where(id: agents(:bob_weather_agent).id).update_all type: 'UnknownTypeAgent'
mock(Agents::WeatherAgent).bulk_check("midnight").once
mock(Agents::WebsiteAgent).bulk_check("midnight").once
Agent.run_schedule("midnight")
end

it "only runs agents with the given schedule" do
do_not_allow(Agents::WebsiteAgent).async_check
Agent.run_schedule("blah")
Expand Down Expand Up @@ -283,13 +290,37 @@ def receive(events)
Agent.receive!
end

it "should not propogate to disabled Agents" do
it "should not propagate to disabled Agents" do
Agent.async_check(agents(:bob_weather_agent).id)
agents(:bob_rain_notifier_agent).update_attribute :disabled, true
mock(Agent).async_receive(agents(:bob_rain_notifier_agent).id, anything).times(0)
Agent.receive!
end

it "should not propagate to Agents with unknown types" do
Agent.async_check(agents(:jane_weather_agent).id)
Agent.async_check(agents(:bob_weather_agent).id)

Agent.where(id: agents(:bob_rain_notifier_agent).id).update_all type: 'UnknownTypeAgent'

mock(Agent).async_receive(agents(:bob_rain_notifier_agent).id, anything).times(0)
mock(Agent).async_receive(agents(:jane_rain_notifier_agent).id, anything).times(1)

Agent.receive!
end

it "should not propagate from Agents with unknown types" do
Agent.async_check(agents(:jane_weather_agent).id)
Agent.async_check(agents(:bob_weather_agent).id)

Agent.where(id: agents(:bob_weather_agent).id).update_all type: 'UnknownTypeAgent'

mock(Agent).async_receive(agents(:bob_rain_notifier_agent).id, anything).times(0)
mock(Agent).async_receive(agents(:jane_rain_notifier_agent).id, anything).times(1)

Agent.receive!
end

it "should log exceptions" do
mock.any_instance_of(Agents::TriggerAgent).receive(anything).once {
raise "foo"
Expand Down
145 changes: 0 additions & 145 deletions spec/models/agents/beeper_agent_spec.rb

This file was deleted.

0 comments on commit 8a14a57

Please sign in to comment.