Sha256: e24c67458f301cb28cd0c34d54d4e681392d8d9a8436b73d2b5643939570849b

Contents?: true

Size: 881 Bytes

Versions: 5

Compression:

Stored size: 881 Bytes

Contents

module Magent
  module Failure
    def failed(info)
      error_collection.save(info.merge({:_id => generate_uid, :channel => @name, :channel_class => self.class.to_s, :created_at => Time.now.utc}))
    end

    def error_count
      error_collection.count()
    end

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

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

    def remove_error(error_id)
      self.error_collection.remove(:_id => error_id)
    end

    def retry_error(error)
      process!(error["message"])
      remove_error(error["_id"])
    end

    def error_collection
      @error_collection ||= Magent.database.collection("#{@name}.errors")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
magent-0.5.4 lib/magent/failure.rb
magent-0.5.3 lib/magent/failure.rb
magent-0.5.2 lib/magent/failure.rb
magent-0.5.1 lib/magent/failure.rb
magent-0.5.0 lib/magent/failure.rb