diff options
author | Matt Jankowski <mjankowski@thoughtbot.com> | 2017-05-10 14:32:05 -0400 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-05-10 20:32:05 +0200 |
commit | cc9a6a710f6cf6d193589778570a13f89f7d18f4 (patch) | |
tree | 445c65ee448f43ccc2ea2d77c170b673e68c2f07 /app | |
parent | 2fba4196efd594bcd8922ab479569ac614b9beea (diff) |
Spec feed insert worker (#2965)
* Spec for feed insert worker when missing records * more specs! * Refactor feed insert worker
Diffstat (limited to 'app')
-rw-r--r-- | app/workers/feed_insert_worker.rb | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/app/workers/feed_insert_worker.rb b/app/workers/feed_insert_worker.rb index a58dfaa74..65c02d3ef 100644 --- a/app/workers/feed_insert_worker.rb +++ b/app/workers/feed_insert_worker.rb @@ -3,13 +3,34 @@ class FeedInsertWorker include Sidekiq::Worker + attr_reader :status, :follower + def perform(status_id, follower_id) - status = Status.find(status_id) - follower = Account.find(follower_id) + @status = Status.find_by(id: status_id) + @follower = Account.find_by(id: follower_id) + + check_and_insert + end + + private + + def check_and_insert + if records_available? + perform_push unless feed_filtered? + else + true + end + end + + def records_available? + status.present? && follower.present? + end + + def feed_filtered? + FeedManager.instance.filter?(:home, status, follower.id) + end - return if FeedManager.instance.filter?(:home, status, follower.id) + def perform_push FeedManager.instance.push(:home, follower, status) - rescue ActiveRecord::RecordNotFound - true end end |