sidekiq-superworker 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -98,6 +98,18 @@ Superworker.create(:MySuperworker, :user_id, :comment_id) do
98
98
  end
99
99
  ```
100
100
 
101
+ ### Options
102
+
103
+ #### Insert Method
104
+
105
+ When a superjob is queued, records for all of its subjobs are created. By default, each subjob record will be created using a separate insert query. If you're creating superjobs with large numbers of subjobs and want to improve performance, you can create these records using a multiple insert query instead. To this, set `:insert_method` to `:multiple`:
106
+
107
+ ```ruby
108
+ # config/initializers/superworker.rb
109
+ Sidekiq::Superworker.options[:insert_method] = :multiple
110
+
111
+ ```
112
+
101
113
  ### Logging
102
114
 
103
115
  To make debugging easier, Sidekiq Superworker provides detailed log messages when its logger is set to the DEBUG level:
@@ -1,4 +1,5 @@
1
1
  require 'sidekiq'
2
+ require 'activerecord-import'
2
3
 
3
4
  directory = File.dirname(File.absolute_path(__FILE__))
4
5
  require "#{directory}/client_ext.rb"
@@ -8,6 +9,18 @@ Dir.glob("#{directory}/../../app/models/sidekiq/superworker/*.rb") { |file| requ
8
9
 
9
10
  module Sidekiq
10
11
  module Superworker
12
+ DEFAULTS = {
13
+ insert_method: :single
14
+ }
15
+
16
+ def self.options
17
+ @options ||= DEFAULTS.dup
18
+ end
19
+
20
+ def self.options=(opts)
21
+ @options = opts
22
+ end
23
+
11
24
  def self.logger
12
25
  Logging.logger
13
26
  end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Superworker
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
@@ -34,7 +34,7 @@ module Sidekiq
34
34
 
35
35
  def create_subjobs(arg_values, options={})
36
36
  records = @dsl_hash.nested_hash_to_records(@nested_hash, @args)
37
- subjobs = records.collect do |id, record|
37
+ records = records.collect do |id, record|
38
38
  record[:status] = 'initialized'
39
39
  record[:superjob_id] = @superjob_id
40
40
  record[:superworker_class] = @class_name
@@ -48,9 +48,19 @@ module Sidekiq
48
48
  end
49
49
  record
50
50
  end
51
- # Perform the inserts in a single transaction to improve the performance of large mass inserts
52
- Sidekiq::Superworker::Subjob.transaction do
53
- Sidekiq::Superworker::Subjob.create(subjobs)
51
+
52
+ insert_subjobs(records)
53
+ end
54
+
55
+ def insert_subjobs(records)
56
+ if Sidekiq::Superworker.options[:insert_method] == :multiple
57
+ subjobs = records.collect { |record| Sidekiq::Superworker::Subjob.new(record) }
58
+ Sidekiq::Superworker::Subjob.import(subjobs)
59
+ Sidekiq::Superworker::Subjob.where(superjob_id: @superjob_id).order(:subjob_id)
60
+ else
61
+ Sidekiq::Superworker::Subjob.transaction do
62
+ Sidekiq::Superworker::Subjob.create(records)
63
+ end
54
64
  end
55
65
  end
56
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-superworker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-11 00:00:00.000000000 Z
12
+ date: 2013-09-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 2.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: activerecord-import
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rails
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -120,7 +136,8 @@ files:
120
136
  - Rakefile
121
137
  - README.md
122
138
  homepage: https://github.com/socialpandas/sidekiq-superworker
123
- licenses: []
139
+ licenses:
140
+ - MIT
124
141
  post_install_message:
125
142
  rdoc_options: []
126
143
  require_paths: