Class: Workers::GatherOpenGraphData

Inherits:
Base
  • Object
show all
Defined in:
app/workers/gather_open_graph_data.rb

Instance Method Summary collapse

Methods inherited from Base

#suppress_annoying_errors

Instance Method Details

#perform(post_id, url, retry_count = 1) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
# File 'app/workers/gather_open_graph_data.rb', line 10

def perform(post_id, url, retry_count=1)
  post = Post.find(post_id)
  post.open_graph_cache = OpenGraphCache.find_or_create_by_url(url)
  post.save
rescue ActiveRecord::RecordNotFound
  # User created a post and deleted it right afterwards before we
  # we had a chance to run the job.
  # On the other hand sometimes the job runs before the Post is
  # fully persisted. So we just reduce the amount of retries.
  GatherOpenGraphData.perform_in(1.minute, post_id, url, retry_count+1) unless retry_count > 3
end