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

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

Defined Under Namespace

Classes: PendingDestroy

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.check_everyObject



11
12
13
# File 'lib/promiscuous/subscriber/worker/eventual_destroyer.rb', line 11

def self.check_every
  Promiscuous::Config.destroy_check_interval + rand(Promiscuous::Config.destroy_check_interval)
end

.postpone_destroy(model, id) ⇒ Object



28
29
30
# File 'lib/promiscuous/subscriber/worker/eventual_destroyer.rb', line 28

def self.postpone_destroy(model, id)
  PendingDestroy.create(:class_name => model.to_s, :instance_id => id)
end

Instance Method Details

#main_loopObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/promiscuous/subscriber/worker/eventual_destroyer.rb', line 15

def main_loop
  loop do
    begin
      PendingDestroy.next(Promiscuous::Config.destroy_timeout).each(&:perform)
    rescue Exception => e
      Promiscuous.warn "[eventual destroyer] #{e}\n#{e.backtrace.join("\n")}"
      Promiscuous::Config.error_notifier.call(e)
    end

    sleep self.class.check_every.to_f
  end
end

#startObject



2
3
4
# File 'lib/promiscuous/subscriber/worker/eventual_destroyer.rb', line 2

def start
  @thread ||= Thread.new { main_loop }
end

#stopObject



6
7
8
9
# File 'lib/promiscuous/subscriber/worker/eventual_destroyer.rb', line 6

def stop
  @thread.try(:kill)
  @thread = nil
end