Created
August 28, 2010 08:51
-
-
Save venetanji/554911 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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