Class: Promiscuous::Subscriber::Worker::EventualDestroyer::PendingDestroy

Inherits:
Object
  • Object
show all
Defined in:
lib/promiscuous/subscriber/worker/eventual_destroyer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ PendingDestroy

Returns a new instance of PendingDestroy.



49
50
51
52
53
54
55
# File 'lib/promiscuous/subscriber/worker/eventual_destroyer.rb', line 49

def initialize(raw)
  params = MultiJson.load(raw).with_indifferent_access

  @class_name  = params[:class_name]
  @instance_id = params[:instance_id]
  @raw         = raw
end

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



33
34
35
# File 'lib/promiscuous/subscriber/worker/eventual_destroyer.rb', line 33

def class_name
  @class_name
end

#instance_idObject

Returns the value of attribute instance_id.



33
34
35
# File 'lib/promiscuous/subscriber/worker/eventual_destroyer.rb', line 33

def instance_id
  @instance_id
end

Class Method Details

.countObject



67
68
69
# File 'lib/promiscuous/subscriber/worker/eventual_destroyer.rb', line 67

def self.count
  redis.zcard(key)
end

.create(options) ⇒ Object



63
64
65
# File 'lib/promiscuous/subscriber/worker/eventual_destroyer.rb', line 63

def self.create(options)
  redis.zadd(key, Time.now.utc.to_i, options.to_json)
end

.next(timeout) ⇒ Object



57
58
59
60
61
# File 'lib/promiscuous/subscriber/worker/eventual_destroyer.rb', line 57

def self.next(timeout)
  redis.zrangebyscore(key, 0, timeout.ago.utc.to_i).map do |raw|
    self.new(raw)
  end
end

Instance Method Details

#destroyObject



45
46
47
# File 'lib/promiscuous/subscriber/worker/eventual_destroyer.rb', line 45

def destroy
  self.class.redis.zrem(self.class.key, @raw)
end

#performObject



35
36
37
38
39
40
41
42
43
# File 'lib/promiscuous/subscriber/worker/eventual_destroyer.rb', line 35

def perform
  model = class_name.constantize
  begin
    model.__promiscuous_fetch_existing(instance_id).destroy
  rescue model.__promiscuous_missing_record_exception
  end

  self.destroy
end