rocketjob 2.0.0.rc1 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 766a8b76f06f83475128aa268aa2d54fc4ca7b10
4
- data.tar.gz: 20b232869d4a43acd28fecf4417030e99c88d2dc
3
+ metadata.gz: 6eb90dc1e3aea713b4d981636208f44a0da52e6c
4
+ data.tar.gz: 1f9f590f2789f050d736af772843b78bd98d1795
5
5
  SHA512:
6
- metadata.gz: 56a8ce86eb62461128bace7cf0a8756deab0f88591f1a94f2ea951574cd47cc64e0dae0a2afdef8c6f74d2c4eb658cb00f7e0169612cbcac6d21aa68fff9b306
7
- data.tar.gz: 74facaf88ce3dd6bc744d9074d10a50e98c1366fe8da2a070b6fe4f92daf13a3fa37696466a811f344d1c4672fd75243e64375bdd06e23a0e1685216bd858810
6
+ metadata.gz: 3ab4508ac667d557a4eee4533d4bdbb15c8bb6b10c35a8f9f1f71e53e33f0a1276c7b55b6ba80743169efd19bc6f240311e678a527cdd469a5bed52d45406e66
7
+ data.tar.gz: 201ed97e4992979ada9af839f6951c5c3f8ae373ce6a93d07d6356571f07fc91b5319b8eb2915e2c1dc6be50ef56d845136479db17f7907528ffdf9822bda01a
@@ -131,7 +131,7 @@ module RocketJob
131
131
  # Parse command line options placing results in the corresponding instance variables
132
132
  def parse(argv)
133
133
  parser = OptionParser.new do |o|
134
- o.on('-n', '--name NAME', 'Unique Name of this worker instance (Default: hostname:PID)') do |arg|
134
+ o.on('-n', '--name NAME', 'Unique Name of this worker instance (Default: host_name:PID)') do |arg|
135
135
  @name = arg
136
136
  end
137
137
  o.on('-t', '--threads COUNT', 'Number of worker threads to start') do |arg|
@@ -13,7 +13,7 @@ module Mongo
13
13
  MongoClient.logger.send(level, msg)
14
14
  end
15
15
 
16
- protected
16
+ private
17
17
 
18
18
  def log_operation(name, payload, duration)
19
19
  MongoClient.logger.benchmark_trace(name, duration: (duration * 1000), payload: payload)
@@ -4,7 +4,6 @@ module RocketJob
4
4
  class SimpleJob < RocketJob::Job
5
5
  # No operation, used for performance testing
6
6
  def perform
7
- sleep 1
8
7
  end
9
8
  end
10
9
 
@@ -35,38 +35,37 @@ module RocketJob
35
35
  # skip_job_ids [Array<BSON::ObjectId>]
36
36
  # Job ids to exclude when looking for the next job
37
37
  def self.rocket_job_retrieve(worker_name, skip_job_ids = nil)
38
- run_at = [
38
+ run_at = [
39
39
  {run_at: {'$exists' => false}},
40
40
  {run_at: {'$lte' => Time.now}}
41
41
  ]
42
- query =
43
- if defined?(RocketJobPro)
44
- {
45
- '$and' => [
46
- {
47
- '$or' => [
48
- {'state' => 'queued'}, # Jobs
49
- {'state' => 'running', 'sub_state' => :processing} # Slices
50
- ]
51
- },
52
- {
53
- '$or' => run_at
54
- }
55
- ]
56
- }
57
- else
58
- {
59
- 'state' => 'queued',
60
- '$or' => run_at
61
- }
62
- end
42
+ update = query = nil
43
+ if defined?(RocketJobPro)
44
+ query = {
45
+ '$and' => [
46
+ {
47
+ '$or' => [
48
+ {'state' => 'queued'}, # Jobs
49
+ {'state' => 'running', 'sub_state' => :processing} # Slices
50
+ ]
51
+ },
52
+ {
53
+ '$or' => run_at
54
+ }
55
+ ]
56
+ }
57
+ update = {'$set' => {'worker_name' => worker_name, 'state' => 'running'}}
58
+ else
59
+ query = {'state' => 'queued', '$or' => run_at}
60
+ update = {'$set' => {'worker_name' => worker_name, 'state' => 'running', 'started_at' => Time.now}}
61
+ end
63
62
 
64
63
  query['_id'] = {'$nin' => skip_job_ids} if skip_job_ids && skip_job_ids.size > 0
65
64
 
66
65
  if doc = find_and_modify(
67
66
  query: query,
68
67
  sort: {priority: 1, _id: 1},
69
- update: {'$set' => {'worker_name' => worker_name, 'state' => 'running'}}
68
+ update: update
70
69
  )
71
70
  load(doc)
72
71
  end
@@ -59,7 +59,9 @@ module RocketJob
59
59
  logger.info "Destroyed expired job #{job.class.name}, id:#{job.id}"
60
60
  else
61
61
  job.worker_name = worker_name
62
- job.rocket_job_fail_on_exception!(worker_name) { job.start }
62
+ job.rocket_job_fail_on_exception!(worker_name) do
63
+ defined?(RocketJobPro) ? job.start! : job.start
64
+ end
63
65
  return job if job.running?
64
66
  end
65
67
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module RocketJob #:nodoc
3
- VERSION = '2.0.0.rc1'
3
+ VERSION = '2.0.0.rc2'
4
4
  end
@@ -1,5 +1,4 @@
1
1
  # encoding: UTF-8
2
- require 'socket'
3
2
  require 'concurrent'
4
3
  module RocketJob
5
4
  # Worker
@@ -33,11 +32,10 @@ module RocketJob
33
32
 
34
33
  # @formatter:off
35
34
  # Unique Name of this worker instance
36
- # Defaults to the `hostname` but _must_ be overriden if mutiple Worker instances
37
- # are started on the same host
35
+ # Default: `host name:PID`
38
36
  # The unique name is used on re-start to re-queue any jobs that were being processed
39
37
  # at the time the worker or host unexpectedly terminated, if any
40
- key :name, String, default: -> { "#{Socket.gethostname}:#{$$}" }
38
+ key :name, String, default: -> { "#{SemanticLogger.host}:#{$$}" }
41
39
 
42
40
  # The maximum number of threads that this worker should use
43
41
  # If set, it will override the default value in RocketJob::Config
data/test/test_helper.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
2
 
3
+ begin
4
+ require 'active_model/serializers'
5
+ rescue LoadError
6
+ # Only used when running Rails 5
7
+ end
3
8
  require 'yaml'
4
9
  require 'minitest/autorun'
5
10
  require 'minitest/reporters'
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: 2.0.0.rc1
4
+ version: 2.0.0.rc2
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-01-29 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.21'
33
+ version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.21'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mongo_ha
43
43
  requirement: !ruby/object:Gem::Requirement