Sha256: a3e0a40bb8385a39c85ad4c85b1a45d4dbf81256bc52a2832c341bd7bb5026a6

Contents?: true

Size: 1.64 KB

Versions: 7

Compression:

Stored size: 1.64 KB

Contents

module Tekeya
  module Feed
    module Activity
      module Resque
        # A resque worker to copy activities when an entity tracks another
        class DeleteActivity
          include Tekeya::Feed::Activity::Resque

          @queue = :activity_queue

          # @private
          def self.perform(activity_aggregate_key)
            # get the activity properties from the key
            key_components  = activity_aggregate_key.split(':')
            entity_type     = key_components[2].safe_constantize
            entity_id       = key_components[3]

            # get the entity
            entity = entity_type.where(entity_type.entity_primary_key.to_sym => entity_id).first
            # we only need the feed keys of the trackers
            entity_trackers_feeds = entity.trackers.map(&:feed_key)
            entity_trackers_feeds << entity.profile_feed_key
            entity_trackers_feeds << entity.feed_key

            # remove the aggregate key from the trackers' feeds and prepare the activity for garbage collection
            ::Tekeya.redis.multi do
              entity_trackers_feeds.each do |feed_key|
                if ::Tekeya.redis.zrank(feed_key, activity_aggregate_key)
                  # remove the activity aggregate key from the feed
                  ::Tekeya.redis.zrem(feed_key, activity_aggregate_key)
                  # decrement the activity counter
                  ::Tekeya.redis.decr("#{activity_aggregate_key}:counter")
                end
              end
            end

            # trim the tracker feed and cleanup
            collect_garbage [activity_aggregate_key]
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tekeya-0.0.10 lib/tekeya/feed/activity/resque/delete_activity.rb
tekeya-0.0.9 lib/tekeya/feed/activity/resque/delete_activity.rb
tekeya-0.0.7 lib/tekeya/feed/activity/resque/delete_activity.rb
tekeya-0.0.6 lib/tekeya/feed/activity/resque/delete_activity.rb
tekeya-0.0.5 lib/tekeya/feed/activity/resque/delete_activity.rb
tekeya-0.0.4 lib/tekeya/feed/activity/resque/delete_activity.rb
tekeya-0.0.3 lib/tekeya/feed/activity/resque/delete_activity.rb