Class: RubyJob::ThreadedServer

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_job/threaded_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num_threads:, jobstore:) ⇒ ThreadedServer

Returns a new instance of ThreadedServer.



7
8
9
10
11
# File 'lib/ruby_job/threaded_server.rb', line 7

def initialize(num_threads:, jobstore:)
  @num_threads = num_threads
  @jobstore = jobstore
  @options = { wait: true, wait_delay: 0.5 }
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/ruby_job/threaded_server.rb', line 5

def options
  @options
end

Instance Method Details

#haltObject



33
34
35
36
# File 'lib/ruby_job/threaded_server.rb', line 33

def halt
  halt_at(Time.now)
  self
end

#halt_at(time) ⇒ Object



28
29
30
31
# File 'lib/ruby_job/threaded_server.rb', line 28

def halt_at(time)
  @jobstore.pause_at(time)
  self
end

#resumeObject



38
39
40
41
# File 'lib/ruby_job/threaded_server.rb', line 38

def resume
  halt_at(nil)
  self
end

#resume_until(time) ⇒ Object



43
44
45
46
47
# File 'lib/ruby_job/threaded_server.rb', line 43

def resume_until(time)
  resume
  halt_at(time)
  self
end

#set(**options) ⇒ Object



13
14
15
16
# File 'lib/ruby_job/threaded_server.rb', line 13

def set(**options)
  @options.merge!(options)
  self
end

#startObject



18
19
20
21
22
23
24
25
26
# File 'lib/ruby_job/threaded_server.rb', line 18

def start
  Thread.new do
    @num_threads.times.map do
      Thread.new do
        JobProcessor.new(@jobstore).run(**@options)
      end
    end.each(&:join)
  end
end