Class: Chore::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/chore/fetcher.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manager) ⇒ Fetcher

Returns a new instance of Fetcher.



5
6
7
8
9
# File 'lib/chore/fetcher.rb', line 5

def initialize(manager)
  @stopping = false
  @manager = manager
  @strategy = Chore.config.consumer_strategy.new(self)
end

Instance Attribute Details

#consumersObject (readonly)

Returns the value of attribute consumers.



3
4
5
# File 'lib/chore/fetcher.rb', line 3

def consumers
  @consumers
end

#managerObject (readonly)

Returns the value of attribute manager.



3
4
5
# File 'lib/chore/fetcher.rb', line 3

def manager
  @manager
end

Instance Method Details

#provide_work(n) ⇒ Object

returns upto n work units



33
34
35
# File 'lib/chore/fetcher.rb', line 33

def provide_work(n)
  @strategy.provide_work(n)
end

#return_work(work_units) ⇒ Object

gives work back to the consumer in case it couldn't be assigned



38
39
40
# File 'lib/chore/fetcher.rb', line 38

def return_work(work_units)
  @strategy.return_work(work_units)
end

#startObject

Starts the fetcher with the configured Consumer Strategy. This will begin consuming messages from your queue



12
13
14
15
# File 'lib/chore/fetcher.rb', line 12

def start
  Chore.logger.info "Fetcher starting up"
  @strategy.fetch
end

#stop!Object

Stops the fetcher, preventing any further messages from being pulled from the queue



18
19
20
21
22
23
24
25
# File 'lib/chore/fetcher.rb', line 18

def stop!
  unless @stopping
    Chore.logger.info "Fetcher shutting down started"
    @stopping = true
    @strategy.stop!
    Chore.logger.info "Fetcher shutting down completed"
  end
end

#stopping?Boolean

Determines in the fetcher is in the process of stopping

Returns:

  • (Boolean)


28
29
30
# File 'lib/chore/fetcher.rb', line 28

def stopping?
  @stopping
end