Sha256: 0cebd5b7438cf6c34966c5609ad6b9eaa2364020562d0723ac2b870fd049e989

Contents?: true

Size: 730 Bytes

Versions: 3

Compression:

Stored size: 730 Bytes

Contents

# frozen_string_literal: true

require "active_record"
require "redis"

module SuperSpreader
  class SpreadTracker
    def initialize(job_class, model_class)
      @job_class = job_class
      @model_class = model_class
    end

    def initial_id
      redis_value = redis.hget(initial_id_key, @model_class.name)

      value = redis_value || @model_class.maximum(:id)

      value.to_i
    end

    def initial_id=(value)
      if value.nil?
        redis.hdel(initial_id_key, @model_class.name)
      else
        redis.hset(initial_id_key, @model_class.name, value)
      end
    end

    private

    def redis
      SuperSpreader.redis
    end

    def initial_id_key
      "#{@job_class.name}:initial_id"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
super_spreader-0.2.1 lib/super_spreader/spread_tracker.rb
super_spreader-0.2.0 lib/super_spreader/spread_tracker.rb
super_spreader-0.1.0.beta2 lib/super_spreader/spread_tracker.rb