Class: Artifactory::Cleaner::DiscoveryWorker

Inherits:
Object
  • Object
show all
Defined in:
lib/artifactory/cleaner/discovery_worker.rb

Overview

Helper class representing Threads spawned to discover Artifacts

Instance Method Summary collapse

Constructor Details

#initialize(processing_queues, artifactory_client) ⇒ DiscoveryWorker

Returns a new instance of DiscoveryWorker.



6
7
8
9
10
11
12
# 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

Instance Method Details

#alive?Boolean

Is the Thread for this worker alive?

Returns:

  • (Boolean)


33
34
35
# File 'lib/artifactory/cleaner/discovery_worker.rb', line 33

def alive?
  @thread ? @thread.alive? : false
end

#running?Boolean

Is this DiscoveryWorker running, listening to the queue and processing requests

Returns:

  • (Boolean)


16
17
18
# File 'lib/artifactory/cleaner/discovery_worker.rb', line 16

def running?
  @running
end

#shutdown(timeout = 300) ⇒ Object

Stop the Thread and re-join the parent



51
52
53
54
# File 'lib/artifactory/cleaner/discovery_worker.rb', line 51

def shutdown(timeout = 300)
  @running = false
  @thread.join(timeout) if @thread and @thread.alive?
end

#startObject

Start the DiscoveryWorker and begin processing from the queue



39
40
41
42
43
44
45
46
47
# 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

#stopObject Also known as: kill

Forcibly kill the Thread and destroy it



58
59
60
61
62
# File 'lib/artifactory/cleaner/discovery_worker.rb', line 58

def stop
  @running = false
  @thread.kill if @thread and @thread.alive?
  @thread = nil
end

#to_sObject

String representation of this DiscoveryWorker and it’s status



67
68
69
# 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?Boolean

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

Returns:

  • (Boolean)


27
28
29
# File 'lib/artifactory/cleaner/discovery_worker.rb', line 27

def working?
  @working
end