rocketjob 3.0.0.beta3 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -5
- data/lib/rocket_job/active_worker.rb +74 -0
- data/lib/rocket_job/performance.rb +17 -8
- data/lib/rocket_job/plugins/document.rb +1 -1
- data/lib/rocket_job/plugins/job/state_machine.rb +1 -1
- data/lib/rocket_job/plugins/job/throttle.rb +8 -4
- data/lib/rocket_job/plugins/job/worker.rb +3 -3
- data/lib/rocket_job/server.rb +10 -12
- data/lib/rocket_job/version.rb +1 -1
- data/lib/rocket_job/worker.rb +1 -1
- data/lib/rocketjob.rb +1 -1
- data/test/plugins/job/worker_test.rb +9 -11
- metadata +3 -3
- data/lib/rocket_job/active_server.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e00bccf78b1addfe4e7714526085787e009c852
|
4
|
+
data.tar.gz: bdeb1d7b808c5b589421086254f7f301837d513c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e1a31bdef5185bf7ba414d847d49037871a6b913e3eeda57b98f4a37101b93bd63de8f55c36cfa8ee4cf9fabf55486b01ac4d1ade391104067f45b06a31bb13
|
7
|
+
data.tar.gz: 13289e381b6f879d5da29f0b633316b1b4888dac9c1f5df1bd1048bf91acd122f64ce9837edf5ef631f2f4e8811dde3a008c43bb953557a3560eba2ee25c10d8
|
data/README.md
CHANGED
@@ -19,8 +19,22 @@ Checkout http://rocketjob.io/
|
|
19
19
|
|
20
20
|
## Upgrading to V3
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
V3 replaces MongoMapper with Mongoid which supports the latest MongoDB Ruby client driver.
|
23
|
+
|
24
|
+
### Upgrading Mongo Config file
|
25
|
+
Replace `mongo.yml` with `mongoid.yml`.
|
26
|
+
|
27
|
+
Start with the sample [mongoid.yml](https://github.com/rocketjob/rocketjob/blob/feature/mongoid/test/config/mongoid.yml).
|
28
|
+
|
29
|
+
For more information on the new [Mongoid config file](https://docs.mongodb.com/ruby-driver/master/tutorials/5.1.0/mongoid-installation/).
|
30
|
+
|
31
|
+
Note: The `rocketjob` and `rocketjob_slices` clients in the above `mongoid.yml` file are required.
|
32
|
+
|
33
|
+
### Other changes
|
34
|
+
|
35
|
+
* Arguments are no longer supported, use fields for defining all named arguments for a job.
|
36
|
+
|
37
|
+
* Replace usages of `rocket_job do` to set default values:
|
24
38
|
|
25
39
|
~~~ruby
|
26
40
|
rocket_job do |job|
|
@@ -52,12 +66,11 @@ With:
|
|
52
66
|
field :priority, type: Integer, default: 50, user_editable: true
|
53
67
|
~~~
|
54
68
|
|
55
|
-
|
56
69
|
## Ruby Support
|
57
70
|
|
58
71
|
Rocket Job is tested and supported on the following Ruby platforms:
|
59
|
-
- Ruby 2.1, 2.2, 2.3, and above
|
60
|
-
- JRuby
|
72
|
+
- Ruby 2.1, 2.2, 2.3, 2.4, and above
|
73
|
+
- JRuby 9.0.5 and above
|
61
74
|
|
62
75
|
## Versioning
|
63
76
|
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module RocketJob
|
2
|
+
# Information about a server currently working on a job
|
3
|
+
class ActiveWorker
|
4
|
+
# When this server started working on this job / slice
|
5
|
+
attr_accessor :started_at
|
6
|
+
|
7
|
+
attr_accessor :name, :job
|
8
|
+
|
9
|
+
# Returns [Hash<String:ActiveWorker>] hash of all servers sorted by name
|
10
|
+
# and what they are currently working on.
|
11
|
+
# Returns {} if no servers are currently busy doing any work
|
12
|
+
#
|
13
|
+
# Parameters
|
14
|
+
# server_name: [String]
|
15
|
+
# Only jobs running on the specified server
|
16
|
+
def self.all(server_name = nil)
|
17
|
+
servers = []
|
18
|
+
# Need paused, failed or aborted since servers may still be working on active slices
|
19
|
+
query = RocketJob::Job.where(:state.in => [:running, :paused, :failed, :aborted])
|
20
|
+
query = query.where(worker_name: /\A#{server_name}/) if server_name
|
21
|
+
query.each do |job|
|
22
|
+
servers += job.rocket_job_active_workers
|
23
|
+
end
|
24
|
+
servers
|
25
|
+
end
|
26
|
+
|
27
|
+
# Requeues all jobs for which the workers have disappeared
|
28
|
+
def self.requeue_zombies
|
29
|
+
all.each do |active_worker|
|
30
|
+
next if !active_worker.zombie? || !active_worker.job.may_requeue?
|
31
|
+
active_worker.job.requeue!(active_worker.server_name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(name, started_at, job)
|
36
|
+
@name = name
|
37
|
+
@started_at = started_at
|
38
|
+
@job = job
|
39
|
+
end
|
40
|
+
|
41
|
+
# Duration in human readable form
|
42
|
+
def duration
|
43
|
+
RocketJob.seconds_as_duration(duration_s)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Number of seconds this server has been working on this job / slice
|
47
|
+
def duration_s
|
48
|
+
Time.now - started_at
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns [String] the name of the server running this worker
|
52
|
+
def server_name
|
53
|
+
if match = name.match(/(.*:.*):.*/)
|
54
|
+
match[1]
|
55
|
+
else
|
56
|
+
name
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def server
|
61
|
+
@server ||= RocketJob::Server.where(name: server_name).first
|
62
|
+
end
|
63
|
+
|
64
|
+
# The server on which this worker was running is no longer running
|
65
|
+
def zombie?
|
66
|
+
server.nil?
|
67
|
+
end
|
68
|
+
|
69
|
+
def name=(name)
|
70
|
+
@server = nil
|
71
|
+
@name = name
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -14,17 +14,12 @@ module RocketJob
|
|
14
14
|
@mongo_config = 'config/mongoid.yml'
|
15
15
|
end
|
16
16
|
|
17
|
+
# Loads the queue with jobs to be processed once the queue is loaded.
|
18
|
+
# Retain the first and last job for timings, all others are destroyed on completion.
|
17
19
|
def run_test_case(count = self.count)
|
18
20
|
raise 'Please start servers before starting the performance test' if RocketJob::Server.where(:state.in => ['running', 'paused']).count == 0
|
19
21
|
|
20
|
-
|
21
|
-
self.workers = 0
|
22
|
-
RocketJob::Server.running.each do |server|
|
23
|
-
next if server.zombie?
|
24
|
-
self.servers += 1
|
25
|
-
self.workers += server.heartbeat.workers
|
26
|
-
end
|
27
|
-
puts "Running: #{workers} workers, distributed across #{servers} servers"
|
22
|
+
count_running_workers
|
28
23
|
|
29
24
|
puts 'Waiting for workers to pause'
|
30
25
|
RocketJob::Server.pause_all
|
@@ -54,6 +49,9 @@ module RocketJob
|
|
54
49
|
end
|
55
50
|
|
56
51
|
duration = last.reload.completed_at - first.reload.started_at
|
52
|
+
first.destroy
|
53
|
+
last.destroy
|
54
|
+
|
57
55
|
{count: count, duration: duration, jobs_per_second: (count.to_f / duration).to_i}
|
58
56
|
end
|
59
57
|
|
@@ -86,5 +84,16 @@ module RocketJob
|
|
86
84
|
parser.parse! argv
|
87
85
|
end
|
88
86
|
|
87
|
+
def count_running_workers
|
88
|
+
self.servers = 0
|
89
|
+
self.workers = 0
|
90
|
+
RocketJob::Server.running.each do |server|
|
91
|
+
next if server.zombie?
|
92
|
+
self.servers += 1
|
93
|
+
self.workers += server.heartbeat.workers
|
94
|
+
end
|
95
|
+
puts "Running: #{workers} workers, distributed across #{servers} servers"
|
96
|
+
end
|
97
|
+
|
89
98
|
end
|
90
99
|
end
|
@@ -43,7 +43,7 @@ module RocketJob
|
|
43
43
|
|
44
44
|
# Throttle to add when the throttle is exceeded
|
45
45
|
def throttle_filter
|
46
|
-
{:_type.nin => self.class.name}
|
46
|
+
{:_type.nin => [self.class.name]}
|
47
47
|
end
|
48
48
|
|
49
49
|
# Returns [Boolean] whether the throttle for this job has been exceeded
|
@@ -62,9 +62,13 @@ module RocketJob
|
|
62
62
|
|
63
63
|
# Merge filter(s)
|
64
64
|
def throttle_merge_filter(target, source)
|
65
|
-
source.
|
66
|
-
|
67
|
-
|
65
|
+
source.each_pair do |k, v|
|
66
|
+
target[k] =
|
67
|
+
if previous = target[k]
|
68
|
+
v.is_a?(Array) ? previous + v : v
|
69
|
+
else
|
70
|
+
v
|
71
|
+
end
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
@@ -169,9 +169,9 @@ module RocketJob
|
|
169
169
|
end
|
170
170
|
|
171
171
|
# Returns [Hash<String:[Array<ActiveWorker>]>] All servers actively working on this job
|
172
|
-
def
|
173
|
-
return
|
174
|
-
|
172
|
+
def rocket_job_active_workers(server_name = nil)
|
173
|
+
return [] if !running? || (server_name && !worker_name.start_with(server_name))
|
174
|
+
[ActiveWorker.new(worker_name, started_at, self)]
|
175
175
|
end
|
176
176
|
|
177
177
|
end
|
data/lib/rocket_job/server.rb
CHANGED
@@ -266,25 +266,23 @@ module RocketJob
|
|
266
266
|
workers.shift
|
267
267
|
else
|
268
268
|
# Timeout waiting for worker to stop
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
)
|
274
|
-
rescue Mongoid::Errors::DocumentNotFound
|
275
|
-
logger.warn('Server has been destroyed. Going down hard!')
|
276
|
-
break
|
277
|
-
end
|
269
|
+
find_and_update(
|
270
|
+
'heartbeat.updated_at' => Time.now,
|
271
|
+
'heartbeat.workers' => worker_count
|
272
|
+
)
|
278
273
|
end
|
279
274
|
end
|
280
275
|
|
276
|
+
logger.info 'Shutdown'
|
277
|
+
rescue Mongoid::Errors::DocumentNotFound
|
278
|
+
logger.warn('Server has been destroyed. Going down hard!')
|
279
|
+
rescue Exception => exc
|
280
|
+
logger.error('RocketJob::Server is stopping due to an exception', exc)
|
281
|
+
ensure
|
281
282
|
# Logs the backtrace for each running worker
|
282
283
|
if SemanticLogger::VERSION.to_i >= 4
|
283
284
|
workers.each { |thread| logger.backtrace(thread: thread) }
|
284
285
|
end
|
285
|
-
logger.info 'Shutdown'
|
286
|
-
rescue Exception => exc
|
287
|
-
logger.error('RocketJob::Server is stopping due to an exception', exc)
|
288
286
|
end
|
289
287
|
|
290
288
|
# Returns [Fixnum] number of workers (threads) that are alive
|
data/lib/rocket_job/version.rb
CHANGED
data/lib/rocket_job/worker.rb
CHANGED
@@ -99,7 +99,7 @@ module RocketJob
|
|
99
99
|
def process_available_jobs
|
100
100
|
# Only clear out the current_filter after every `re_check_seconds`
|
101
101
|
time = Time.now
|
102
|
-
if (time - @re_check_start) > re_check_seconds
|
102
|
+
if (time - @re_check_start) > re_check_seconds.to_f
|
103
103
|
@recheck_start = time
|
104
104
|
self.current_filter = filter.dup
|
105
105
|
end
|
data/lib/rocketjob.rb
CHANGED
@@ -6,7 +6,7 @@ require 'rocket_job/version'
|
|
6
6
|
|
7
7
|
# @formatter:off
|
8
8
|
module RocketJob
|
9
|
-
autoload :
|
9
|
+
autoload :ActiveWorker, 'rocket_job/active_worker'
|
10
10
|
autoload :CLI, 'rocket_job/cli'
|
11
11
|
autoload :Config, 'rocket_job/config'
|
12
12
|
autoload :DirmonEntry, 'rocket_job/dirmon_entry'
|
@@ -171,28 +171,26 @@ module Plugins
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
-
describe '#
|
174
|
+
describe '#rocket_job_active_workers' do
|
175
175
|
before do
|
176
176
|
@job = QuietJob.create!
|
177
177
|
@worker = RocketJob::Server.create!(name: 'worker:123')
|
178
178
|
end
|
179
179
|
|
180
180
|
it 'should return empty hash for no active jobs' do
|
181
|
-
assert_equal(
|
181
|
+
assert_equal([], @job.rocket_job_active_workers)
|
182
182
|
end
|
183
183
|
|
184
184
|
it 'should return active servers' do
|
185
185
|
assert job = RocketJob::Job.rocket_job_next_job(@worker.name)
|
186
|
-
assert active = job.
|
186
|
+
assert active = job.rocket_job_active_workers
|
187
187
|
assert_equal 1, active.size
|
188
|
-
assert
|
189
|
-
assert_equal
|
190
|
-
|
191
|
-
assert_equal
|
192
|
-
|
193
|
-
|
194
|
-
assert active_server.duration_s
|
195
|
-
assert active_server.duration
|
188
|
+
assert active_worker = active.first
|
189
|
+
assert_equal @job.id, active_worker.job.id
|
190
|
+
assert_equal @worker.name, active_worker.name
|
191
|
+
assert_equal job.started_at, active_worker.started_at
|
192
|
+
assert active_worker.duration_s
|
193
|
+
assert active_worker.duration
|
196
194
|
end
|
197
195
|
end
|
198
196
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocketjob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -80,7 +80,7 @@ files:
|
|
80
80
|
- Rakefile
|
81
81
|
- bin/rocketjob
|
82
82
|
- bin/rocketjob_perf
|
83
|
-
- lib/rocket_job/
|
83
|
+
- lib/rocket_job/active_worker.rb
|
84
84
|
- lib/rocket_job/cli.rb
|
85
85
|
- lib/rocket_job/config.rb
|
86
86
|
- lib/rocket_job/dirmon_entry.rb
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module RocketJob
|
2
|
-
# Information about a server currently working on a job
|
3
|
-
class ActiveServer
|
4
|
-
# When this server started working on this job / slice
|
5
|
-
attr_accessor :started_at
|
6
|
-
|
7
|
-
attr_accessor :name, :job
|
8
|
-
|
9
|
-
# Returns [Hash<String:ActiveWorker>] hash of all servers sorted by name
|
10
|
-
# and what they are currently working on.
|
11
|
-
# Returns {} if no servers are currently busy doing any work
|
12
|
-
def self.all
|
13
|
-
servers = {}
|
14
|
-
# Need paused, failed or aborted since servers may still be working on active slices
|
15
|
-
RocketJob::Job.where(state: [:running, :paused, :failed, :aborted]).each do |job|
|
16
|
-
job.rocket_job_active_servers.each_pair do |name, active_server|
|
17
|
-
(servers[name] ||= []) << active_server
|
18
|
-
end
|
19
|
-
end
|
20
|
-
servers
|
21
|
-
end
|
22
|
-
|
23
|
-
def initialize(name, started_at, job)
|
24
|
-
@name = name
|
25
|
-
@started_at = started_at
|
26
|
-
@job = job
|
27
|
-
end
|
28
|
-
|
29
|
-
# Duration in human readable form
|
30
|
-
def duration
|
31
|
-
RocketJob.seconds_as_duration(duration_s)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Number of seconds this server has been working on this job / slice
|
35
|
-
def duration_s
|
36
|
-
Time.now - started_at
|
37
|
-
end
|
38
|
-
|
39
|
-
def server
|
40
|
-
@server ||= RocketJob::Server.find_by(name: name)
|
41
|
-
end
|
42
|
-
|
43
|
-
def name=(name)
|
44
|
-
@server = nil
|
45
|
-
@name = name
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|