Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into bump_weibo_2
Browse files Browse the repository at this point in the history
  • Loading branch information
cantino committed May 9, 2015
2 parents 6067c0f + e38e911 commit 40909b3
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 56 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ gem 'weibo_2', github: 'cantino/weibo_2', branch: 'master'
gem "google-api-client", require: 'google/api_client'

# Twitter Agents
gem 'twitter', '~> 5.8.0' # Must to be loaded before cantino-twitter-stream.
gem 'twitter-stream', github: 'dsander/twitter-stream', branch: 'huginn'
gem 'twitter', '~> 5.14.0' # Must to be loaded before cantino-twitter-stream.
gem 'twitter-stream', github: 'cantino/twitter-stream', branch: 'huginn'
gem 'omniauth-twitter'

# Tumblr Agents
Expand Down
38 changes: 19 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
GIT
remote: git://github.com/cantino/twitter-stream.git
revision: f7e7edb0bae013bffabf3598e7147773d9fd370f
branch: huginn
specs:
twitter-stream (0.1.15)
eventmachine (~> 1.0.7)
http_parser.rb (~> 0.6.0)
simple_oauth (~> 0.3.0)

GIT
remote: git://github.com/cantino/weibo_2.git
revision: 00e57d29d8252126014b038cd738b02e05e4cfc5
Expand All @@ -9,16 +19,6 @@ GIT
oauth2 (~> 0.9.1)
rest-client (~> 1.8)

GIT
remote: git://github.com/dsander/twitter-stream.git
revision: 1713b4fe5b387580364b39716bb5c26d6601c50f
branch: huginn
specs:
twitter-stream (0.1.15)
eventmachine (~> 1.0.7)
http_parser.rb (~> 0.6.0)
simple_oauth (~> 0.2.0)

GIT
remote: git://github.com/wunderlist/omniauth-wunderlist.git
revision: d0910d0396107b9302aa1bc50e74bb140990ccb8
Expand Down Expand Up @@ -67,7 +67,7 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.7)
addressable (2.3.8)
arel (6.0.0)
autoparse (0.3.3)
addressable (>= 2.3.1)
Expand Down Expand Up @@ -144,7 +144,7 @@ GEM
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
equalizer (0.0.9)
equalizer (0.0.11)
erector (0.10.0)
treetop (>= 1.2.3)
erubis (2.7.0)
Expand Down Expand Up @@ -212,8 +212,8 @@ GEM
httmultiparty (0.3.10)
httparty (>= 0.7.3)
multipart-post
http (0.5.1)
http_parser.rb
http (0.6.4)
http_parser.rb (~> 0.6.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
http_parser.rb (0.6.0)
Expand Down Expand Up @@ -403,7 +403,7 @@ GEM
jwt (>= 0.1.5)
multi_json (>= 1.0.0)
simple-rss (1.3.1)
simple_oauth (0.2.0)
simple_oauth (0.3.1)
simplecov (0.9.2)
docile (~> 1.1.0)
multi_json (~> 1.0)
Expand Down Expand Up @@ -451,17 +451,17 @@ GEM
builder (>= 2.1.2)
jwt (>= 0.1.2)
multi_json (>= 1.3.0)
twitter (5.8.0)
twitter (5.14.0)
addressable (~> 2.3)
buftok (~> 0.2.0)
equalizer (~> 0.0.9)
faraday (~> 0.9.0)
http (~> 0.5.0)
http (~> 0.6.0)
http_parser.rb (~> 0.6.0)
json (~> 1.8)
memoizable (~> 0.4.0)
naught (~> 1.0)
simple_oauth (~> 0.2.0)
simple_oauth (~> 0.3.0)
typhoeus (0.6.9)
ethon (>= 0.7.1)
tzinfo (1.2.2)
Expand Down Expand Up @@ -571,7 +571,7 @@ DEPENDENCIES
therubyracer (~> 0.12.1)
tumblr_client
twilio-ruby (~> 3.11.5)
twitter (~> 5.8.0)
twitter (~> 5.14.0)
twitter-stream!
typhoeus (~> 0.6.3)
tzinfo (>= 1.2.0)
Expand Down
15 changes: 15 additions & 0 deletions app/jobs/agent_check_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class AgentCheckJob < ActiveJob::Base
# Given an Agent id, load the Agent, call #check on it, and then save it with an updated `last_check_at` timestamp.
def perform(agent_id)
agent = Agent.find(agent_id)
begin
return if agent.unavailable?
agent.check
agent.last_check_at = Time.now
agent.save!
rescue => e
agent.error "Exception during check. #{e.message}: #{e.backtrace.join("\n")}"
raise
end
end
end
16 changes: 16 additions & 0 deletions app/jobs/agent_receive_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class AgentReceiveJob < ActiveJob::Base
# Given an Agent id and an array of Event ids, load the Agent, call #receive on it with the Event objects, and then
# save it with an updated `last_receive_at` timestamp.
def perform(agent_id, event_ids)
agent = Agent.find(agent_id)
begin
return if agent.unavailable?
agent.receive(Event.where(:id => event_ids).order(:id))
agent.last_receive_at = Time.now
agent.save!
rescue => e
agent.error "Exception during receive. #{e.message}: #{e.backtrace.join("\n")}"
raise
end
end
end
38 changes: 6 additions & 32 deletions app/models/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,24 +387,11 @@ def receive!(options={})
end
end

# Given an Agent id and an array of Event ids, load the Agent, call #receive on it with the Event objects, and then
# save it with an updated `last_receive_at` timestamp.
#
# This method is tagged with `handle_asynchronously` and will be delayed and run with delayed_job. It accepts Agent
# and Event ids instead of a literal ActiveRecord models because it is preferable to serialize delayed_jobs with ids.
# This method will enqueue an AgentReceiveJob job. It accepts Agent and Event ids instead of a literal ActiveRecord
# models because it is preferable to serialize jobs with ids.
def async_receive(agent_id, event_ids)
agent = Agent.find(agent_id)
begin
return if agent.unavailable?
agent.receive(Event.where(:id => event_ids).order(:id))
agent.last_receive_at = Time.now
agent.save!
rescue => e
agent.error "Exception during receive. #{e.message}: #{e.backtrace.join("\n")}"
raise
end
AgentReceiveJob.perform_later(agent_id, event_ids)
end
handle_asynchronously :async_receive

# Given a schedule name, run `check` via `bulk_check` on all Agents with that schedule.
# This is called by bin/schedule.rb for each schedule in `SCHEDULES`.
Expand All @@ -425,24 +412,11 @@ def bulk_check(schedule)
end
end

# Given an Agent id, load the Agent, call #check on it, and then save it with an updated `last_check_at` timestamp.
#
# This method is tagged with `handle_asynchronously` and will be delayed and run with delayed_job. It accepts an Agent
# id instead of a literal Agent because it is preferable to serialize delayed_jobs with ids, instead of with the full
# Agents.
# This method will enqueue an AgentCheckJob job. It accepts an Agent id instead of a literal Agent because it is
# preferable to serialize job with ids, instead of with the full Agents.
def async_check(agent_id)
agent = Agent.find(agent_id)
begin
return if agent.unavailable?
agent.check
agent.last_check_at = Time.now
agent.save!
rescue => e
agent.error "Exception during check. #{e.message}: #{e.backtrace.join("\n")}"
raise
end
AgentCheckJob.perform_later(agent_id)
end
handle_asynchronously :async_check
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/agents/email_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def receive(incoming_events)
incoming_events.each do |event|
log "Sending digest mail to #{user.email} with event #{event.id}"
recipients(event.payload).each do |recipient|
SystemMailer.delay.send_message(:to => recipient, :subject => interpolated(event)['subject'], :headline => interpolated(event)['headline'], :body => interpolated(event)['body'], :groups => [present(event.payload)])
SystemMailer.send_message(:to => recipient, :subject => interpolated(event)['subject'], :headline => interpolated(event)['headline'], :body => interpolated(event)['body'], :groups => [present(event.payload)]).deliver_later
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/agents/email_digest_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def check
groups = self.memory['queue'].map { |payload| present(payload) }
log "Sending digest mail to #{user.email} with events [#{ids}]"
recipients.each do |recipient|
SystemMailer.delay.send_message(:to => recipient, :subject => interpolated['subject'], :headline => interpolated['headline'], :groups => groups)
SystemMailer.send_message(:to => recipient, :subject => interpolated['subject'], :headline => interpolated['headline'], :groups => groups).deliver_later
end
self.memory['queue'] = []
self.memory['events'] = []
Expand Down
4 changes: 3 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded.

# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/presenters)
config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/presenters #{config.root}/app/jobs)

# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
Expand Down Expand Up @@ -52,5 +52,7 @@ class Application < Rails::Application

# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true

config.active_job.queue_adapter = :delayed_job
end
end

0 comments on commit 40909b3

Please sign in to comment.