jober 0.3.30 → 0.3.37

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: f7ffebeb0c28297bb8898cfed98c2b865a7930ea
4
- data.tar.gz: bcd0d4b2496c31a8546b67127750309d4a0b11e5
3
+ metadata.gz: 68d2b76b5ce65c40e2dd400e56da949542b58ad1
4
+ data.tar.gz: b1bf5509a4eb9046d54a8f210543608b9cd7c685
5
5
  SHA512:
6
- metadata.gz: c66d7db2864706bc7314844b1c8ec443507a4207a998dd6a3fd08cd802909bb5fbb95a61f459bc60edc664bd140454b6ad53c1b1882881bc4339d25dab8453cd
7
- data.tar.gz: 03402f170459a3713768578fc41ecaf0909ab0262735cd2f31ffaf25ee1b71bda815a83cc34afb78472aaddc1c86bd38e886118d8d1b1228ca6fcff766dd1971
6
+ metadata.gz: b85813cff723ce9c897b5737c949c53f223621df6a17aceda7d717e868eeb83dedbb43f5c39897a540ba602a44bf69562a6f2b2a92e5324a73ec633ae0aadde4
7
+ data.tar.gz: 9aedb0ffbe32e15120d4f6ba5036a5f7a93b00487c987114b54b63a8a2ff16654d3da141f77b1a0254f641fa4281711967aac83697530969c8767c77eba66304
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ mkmf.log
16
16
  *.swp
17
17
  todo
18
18
  *.db
19
+ *.db*
@@ -48,6 +48,10 @@ module Jober
48
48
  @classes ||= []
49
49
  end
50
50
 
51
+ def auto_classes
52
+ classes.reject &:manual?
53
+ end
54
+
51
55
  def names
52
56
  classes.map { |k| underscore(k.to_s.gsub('Jober::', '')) }
53
57
  end
@@ -94,7 +98,7 @@ module Jober
94
98
 
95
99
  def llens
96
100
  h = {}
97
- @classes.each do |klass|
101
+ auto_classes.each do |klass|
98
102
  next unless klass.ancestors.include?(Jober::Queue)
99
103
  h[klass.queue_name_base] = klass.len
100
104
  end
@@ -103,7 +107,7 @@ module Jober
103
107
 
104
108
  def stats
105
109
  h = {}
106
- @classes.each do |klass|
110
+ auto_classes.each do |klass|
107
111
  started = klass.read_timestamp(:started)
108
112
  finished = klass.read_timestamp(:finished)
109
113
  crashed = klass.read_timestamp(:crashed)
@@ -21,6 +21,14 @@ class Jober::AbstractTask
21
21
  @workers || 1
22
22
  end
23
23
 
24
+ def manual!
25
+ @manual = true
26
+ end
27
+
28
+ def manual?
29
+ @manual
30
+ end
31
+
24
32
  attr_accessor :short_name
25
33
  end
26
34
 
@@ -40,8 +48,8 @@ class Jober::AbstractTask
40
48
  @stopped = false
41
49
  trap("QUIT") { @stopped = true }
42
50
  trap("INT") { @stopped = true }
43
- @worker_id = opts[:worker_id] || 0
44
- @workers_count = opts[:workers_count] || 1
51
+ @worker_id = (opts[:worker_id] || 0).to_i
52
+ @workers_count = (opts[:workers_count] || 1).to_i
45
53
  @skip_delay = opts[:skip_delay]
46
54
  end
47
55
 
@@ -16,7 +16,7 @@ class Jober::ARLoop < Jober::Task
16
16
  def run
17
17
  prox = proxy
18
18
 
19
- prefix = ''
19
+ prefix = log_prefix
20
20
 
21
21
  if @worker_id && @workers_count && @workers_count > 1 && !@opts[:no_auto_proxy]
22
22
  cond = "id % #{@workers_count} = #{@worker_id}"
@@ -31,13 +31,16 @@ class Jober::ARLoop < Jober::Task
31
31
  _last_batch_id
32
32
  end
33
33
 
34
- prox = prox.where(@opts[:where]) if @opts[:where]
34
+ if @opts[:where]
35
+ prox = prox.where(@opts[:where])
36
+ prefix += "(cwhere) "
37
+ end
35
38
 
36
39
  cnt = 0
37
40
  count = last_batch_id ? prox.where("id > ?", last_batch_id).count : prox.count
38
41
  info { "#{prefix}full count to process #{count}" }
39
42
 
40
- h = {:batch_size => self.class.get_batch_size}
43
+ h = { :batch_size => self.class.get_batch_size }
41
44
  h[:start] = last_batch_id + 1 if last_batch_id
42
45
 
43
46
  t1 = Time.now
@@ -61,6 +64,10 @@ class Jober::ARLoop < Jober::Task
61
64
  info { "#{prefix}processed total #{cnt} #{summary_info}" }
62
65
  end
63
66
 
67
+ def log_prefix
68
+ ''
69
+ end
70
+
64
71
  def summary_info
65
72
  nil
66
73
  end
@@ -11,7 +11,7 @@ class Jober::ThreadedManager
11
11
  end
12
12
 
13
13
  def initialize(klasses = nil, opts = {})
14
- @klasses = Array(klasses || Jober.classes)
14
+ @klasses = Array(klasses || Jober.auto_classes)
15
15
  @stopped = false
16
16
  @objects = @klasses.map do |klass|
17
17
  if klass.is_a?(String)
@@ -1,3 +1,3 @@
1
1
  module Jober
2
- VERSION = "0.3.30"
2
+ VERSION = "0.3.37"
3
3
  end
@@ -76,6 +76,12 @@ describe "ARLoop" do
76
76
  SO["names"].last.should == "unknown 96"
77
77
  end
78
78
 
79
+ it "use auto proxy sharding, work with string values" do
80
+ MyAR.new(:worker_id => '1', :workers_count => '4').execute
81
+ SO["names"].size.should == 10
82
+ SO["names"].last.should == "unknown 96"
83
+ end
84
+
79
85
  it "where" do
80
86
  MyAR.new(:where => "years < 24").execute
81
87
  SO["names"].size.should == 15
@@ -6,6 +6,9 @@ class A3 < Jober::QueueBatch; end
6
6
  class A4 < Jober::UniqueQueue; end
7
7
 
8
8
  class Jober::B1 < Jober::Task; end
9
+ class Manual < Jober::Task;
10
+ manual!
11
+ end
9
12
 
10
13
  describe "Jober" do
11
14
  it "classes" do
@@ -22,4 +25,9 @@ describe "Jober" do
22
25
  Jober.find_class("B2").should == nil
23
26
  Jober.find_class("Jober::B2").should == nil
24
27
  end
28
+
29
+ it "auto_classes" do
30
+ Jober.classes.should include(Manual)
31
+ Jober.auto_classes.should_not include(Manual)
32
+ end
25
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jober
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.30
4
+ version: 0.3.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Konstantin Makarchev'"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-17 00:00:00.000000000 Z
11
+ date: 2015-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis