Sha256: 633ca0d87306ba3bbf161518eebb9268d45576280bcc5dd0a6d33174a0e430ea

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

module Resque
  module Plugins
    module History

      MAX_HISTORY_SIZE = 500
      HISTORY_SET_NAME = "resque_history"

      def maximum_history_size
        @max_history ||= MAX_HISTORY_SIZE
      end

      def on_failure_history(exception, *args)
        Resque.redis.lpush(HISTORY_SET_NAME, {:class => "#{self}",
                                              :time => Time.now.strftime("%Y-%m-%d %H:%M"),
                                              :args => args,
                                              :error => exception.message
        }.to_json)

        if Resque.redis.llen(HISTORY_SET_NAME) > maximum_history_size
          Resque.redis.rpop(HISTORY_SET_NAME)
        end

      end


      def before_perform_history(*args)
        @start_time = Time.now
      end

      def after_perform_history(*args)
        elapsed_seconds = (Time.now - @start_time).to_i
        Resque.redis.lpush(HISTORY_SET_NAME, {:class => "#{self}",
                                              :args => args,
                                              :time => Time.now.strftime("%Y-%m-%d %H:%M"),
                                              :execution =>elapsed_seconds
        }.to_json)

        if Resque.redis.llen(HISTORY_SET_NAME) > maximum_history_size
          Resque.redis.rpop(HISTORY_SET_NAME)
        end

      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
resque-history-1.12.0 lib/resque-history/plugins/history.rb
resque-history-1.11.1 lib/resque-history/plugins/history.rb
resque-history-1.11.0 lib/resque-history/plugins/history.rb
resque-history-1.10.0 lib/resque-history/plugins/history.rb
resque-history-1.9.5 lib/resque-history/plugins/history.rb
resque-history-1.9.4 lib/resque-history/plugins/history.rb