Sha256: 39ab16e3dbd8de461c76e19b700e7eb75d663ad5f21d2495520e872c1b420858

Contents?: true

Size: 987 Bytes

Versions: 3

Compression:

Stored size: 987 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 enqueue_error(error)
      enqueue(error["message"], 1)
      remove_error(error["_id"])
    end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
magent-0.6.2 lib/magent/failure.rb
magent-0.6.1 lib/magent/failure.rb
magent-0.6.0 lib/magent/failure.rb