Created
October 14, 2013 12:30
-
-
Save julesce/6974886 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def self.perform(promotion_id) | |
| promotion = Promotion.find(promotion_id) | |
| promotion.mailings_sent.each do |mailing| | |
| migrate_mailing(mailing) | |
| end | |
| promotion.refresh_stats | |
| promotion.store(:stats_migration_end => Time.now) | |
| end | |
| private | |
| def self.migrate_mailing(mailing) | |
| get_attempts(mailing) do |attempts| | |
| batch_events = [] | |
| attempts.each do |attempt| | |
| m_id = attempt.mailing_id | |
| id = attempt.id | |
| events = [] | |
| attempt.forward_count.times do | |
| events << build_event_hash(m_id, id, PromotionAttemptEvent::EVENT_TYPES[:forwarded]) | |
| end if attempt.forward_count.present? && attempt.forward_count > 0 | |
| events << build_event_hash(m_id, id, PromotionAttemptEvent::EVENT_TYPES[:viewed]) | |
| events << build_event_hash(m_id, id, PromotionAttemptEvent::EVENT_TYPES[:tweeted]) if attempt.state_id == TWEETED | |
| events << build_event_hash(m_id, id, PromotionAttemptEvent::EVENT_TYPES[:facebooked]) if attempt.state_id == FACEBOOKED | |
| events << build_event_hash(m_id, id, PromotionAttemptEvent::EVENT_TYPES[:plusoned]) if attempt.state_id == PLUSONED | |
| events << build_event_hash(m_id, id, PromotionAttemptEvent::EVENT_TYPES[:pinned]) if attempt.state_id == PINNED | |
| batch_events.concat(events) | |
| end | |
| # TODO: Import the batch events array | |
| end | |
| end | |
| def self.build_event_hash(mailing_id, promotion_attempt_id, event_type) | |
| { :mailing_id => mailing_id, :promotion_attempt_id => promotion_attempt_id, :event_type => event_type } | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment