class Artifactory::Cleaner::DiscoveryWorker
Helper class representing Threads spawned to discover Artifacts
Public Class Methods
new(processing_queues, artifactory_client)
click to toggle source
# File lib/artifactory/cleaner/discovery_worker.rb, line 6 def initialize(processing_queues, artifactory_client) @running = false @working = false @thread = nil @queues = processing_queues @artifactory_client = artifactory_client end
Public Instance Methods
alive?()
click to toggle source
Is the Thread for this worker alive?
# File lib/artifactory/cleaner/discovery_worker.rb, line 33 def alive? @thread ? @thread.alive? : false end
running?()
click to toggle source
Is this DiscoveryWorker running, listening to the queue and processing requests
# File lib/artifactory/cleaner/discovery_worker.rb, line 16 def running? @running end
shutdown(timeout = 300)
click to toggle source
Stop the Thread and re-join the parent
# File lib/artifactory/cleaner/discovery_worker.rb, line 51 def shutdown(timeout = 300) @running = false @thread.join(timeout) if @thread and @thread.alive? end
start()
click to toggle source
Start the DiscoveryWorker and begin processing from the queue
# File lib/artifactory/cleaner/discovery_worker.rb, line 39 def start @running = true @thread = Thread.new do while running? process @queues.incoming.pop(false) end end self end
stop()
click to toggle source
Forcibly kill the Thread and destroy it
# File lib/artifactory/cleaner/discovery_worker.rb, line 58 def stop @running = false @thread.kill if @thread and @thread.alive? @thread = nil end
Also aliased as: kill
to_s()
click to toggle source
String representation of this DiscoveryWorker and it's status
# File lib/artifactory/cleaner/discovery_worker.rb, line 67 def to_s "#<#{self.class}:#{self.object_id}; #{running? ? 'running' : 'not running'}, #{working? ? 'working' : 'idle'}, #{alive? ? 'alive' : 'dead'}>" end
working?()
click to toggle source
Is this DiscoveryWorker currently processing a request?
when running? is true and working? is not, then the worker is idle, blocked, waiting for an action.
when working? is true, there will be at least one more result pushed to the outgoing queue when the current request finishes
# File lib/artifactory/cleaner/discovery_worker.rb, line 27 def working? @working end