Sha256: 69c0667920e9eebca29dd6f3b0a208703e98d497fd1c73bb1979c14e93b9ebfb

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module Magent
  class Channel < GenericChannel
    def enqueue(message, args)
      super([message, args])
    end

    def failed(info)
      error_collection.save(info.merge({:channel_id => @name, :created_at => Time.now.utc}))
    end

    def error_count
      error_collection.find({:channel_id => @name}).count()
    end

    def errors(conds = {})
      page = conds.delete(:page) || 1
      per_page = conds.delete(:per_page) || 10

      error_collection.find({:channel_id => @name}, {:skip => (page-1)*per_page, :limit => per_page, :sort => [["created_at", "descending"]]})
    end

    def remove_error(error_id)
      object_id = error_id
      if error_id.kind_of?(String)
        object_id = Mongo::ObjectID.from_string(error_id)
      end

      self.error_collection.remove(:_id => object_id, :channel_id => @name)
    end

    def retry_error(error)
      remove_error(error["_id"])
      enqueue(error["method"], error["payload"])
    end

    def error_collection
      @error_collection ||= Magent.database.collection("errors")
    end
  end # Channel
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
magent-0.1.3 lib/magent/channel.rb