Skip to content

Instantly share code, notes, and snippets.

@venetanji
Created August 28, 2010 08:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save venetanji/554911 to your computer and use it in GitHub Desktop.
Save venetanji/554911 to your computer and use it in GitHub Desktop.
class FanCount
@queue = "FanCount"
include Mongoid::Document
field :page_id
field :fans
field :date, :type => DateTime
index :page_id, :unique => true, :background => true
index(
[ [:page_id, Mongo::ASCENDING], [:date, Mongo::DESCENDING] ],
:unique => true,
:background => true)
class << self
def perform(page_id = nil, fan_count = nil)
unless page_id
Page.all.each do |page|
Resque.enqueue(self, page.id, page.fan_count)
end
return true
end
collection.update(
{:date => Date.today.to_time, :page_id => page_id},
{:fans => fan_count, :date => Date.today.to_time, :page_id => page_id},
{:upsert => true}
)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment