dj_split 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/dj_split.gemspec +3 -3
- data/lib/dj_split/split.rb +15 -20
- data/lib/dj_split/version.rb +1 -1
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e4fe039dd8c959184e603089140121b8b271f6173427817fe54c78989afba57
|
4
|
+
data.tar.gz: d18389f1d0c76235d6b937b7e65de15e7fdb883530f86b3557c30f32fe79c9d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6393267924205a39bd92412ab52cc843694fb54bdb6dac8d08bf83fc80098c8eac91d658b708209085d84ac80d889e68bbecb9cd0a2e0e3fef4b859df7e52b0a
|
7
|
+
data.tar.gz: af50d3434ac9ea3790ab6d4cf927fc7bafc01bdc9fb16f8d9e30e90c982229af72872a34b5484554afd24487a40acd7b65b798137ca21cf99bc54bfa000bd4c0
|
data/README.md
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
-
|
1
|
+
**If you're viewing this at https://github.com/nehalamin93/dj_split,
|
2
|
+
you're reading the documentation for the master branch.
|
3
|
+
[View documentation for the latest release
|
4
|
+
(1.0.1).](https://github.com/nehalamin93/dj_split/tree/v1.0.1)**
|
5
|
+
|
6
|
+
Delayed Job Split Feature
|
7
|
+
=========================
|
8
|
+
[][gem]
|
9
|
+
|
10
|
+
[gem]: https://rubygems.org/gems/dj_split
|
2
11
|
|
3
12
|
Class [**"DjSplit::Split"**](https://github.com/nehalamin93/dj_split/blob/master/lib/dj_split/split.rb) is designed to **Split Time Taking Delayed Jobs, Crons, Bulk Operations, etc** into **smaller size multiple Delayed Jobs**.
|
4
13
|
These **Sub-Jobs** should be **mutually exclusive** of each other and should be able to run **concurrently**.
|
data/dj_split.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["nehalamin93@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{Parallelise Time Taking Job across Multiple Processes in Single or Multiple Servers by Splitting into Delayed Jobs.}
|
13
|
-
spec.description = %q{Gem is designed to "Split or Break" Time Taking Jobs(Delayed Jobs, Crons, Bulk Operations, etc.) into smaller size Mutually Exclusive Delayed Jobs. These Sub-Jobs can be picked by
|
13
|
+
spec.description = %q{Gem is designed to "Split or Break" Time Taking Jobs(Delayed Jobs, Crons, Bulk Operations, etc.) into smaller size Mutually Exclusive Delayed Jobs. These Sub-Jobs can be picked by "Multiple Workers" in "Single" or "Multiple Servers". After splitting and enqueuing, the process will wait for the sub-jobs to complete and also processes sub-jobs instead of blocking. "Parallelism" can be achieved across multiple servers through Delayed Jobs which can directly impact performance. "Performance" can improve up to "n+1" times, where n = number of workers picking the jobs.}
|
14
14
|
spec.homepage = ""
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -25,12 +25,12 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", ">= 1.11"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
-
spec.add_development_dependency "minitest", "5.11
|
28
|
+
spec.add_development_dependency "minitest", "~> 5.11"
|
29
29
|
spec.add_development_dependency 'rspec', '~> 3.6'
|
30
30
|
spec.add_development_dependency "mocha", "~> 1.2"
|
31
31
|
|
32
32
|
spec.add_dependency 'delayed_job', '>= 3.0'
|
33
33
|
spec.add_dependency 'sqlite3'
|
34
|
-
spec.add_dependency 'delayed_job_active_record', '>= 0
|
34
|
+
spec.add_dependency 'delayed_job_active_record', '>= 4.0'
|
35
35
|
spec.add_development_dependency 'rails'
|
36
36
|
end
|
data/lib/dj_split/split.rb
CHANGED
@@ -3,6 +3,8 @@ module DjSplit
|
|
3
3
|
|
4
4
|
OPTIMAL_SPLIT_SIZE = 200
|
5
5
|
DEFAULT_SPLIT_INDEX = 2
|
6
|
+
STALE_JOBS_TIMEOUT = 900 # Seconds. Can be passed in options.
|
7
|
+
SLEEP_TIME = 0.2 # Seconds.
|
6
8
|
|
7
9
|
def initialize(options)
|
8
10
|
@queue_options = options[:queue_options] || {}
|
@@ -49,32 +51,21 @@ module DjSplit
|
|
49
51
|
count = 0
|
50
52
|
while(jobs_processed_by_other_workers_currently?)
|
51
53
|
count += 1
|
52
|
-
sleep(
|
53
|
-
handle_stale_jobs if
|
54
|
+
sleep(SLEEP_TIME)
|
55
|
+
handle_stale_jobs if check_for_timeout?(count)
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
|
-
#
|
59
|
+
# Raise an error in scenario such as: Job is locked by a worker and worker got killed
|
58
60
|
def handle_stale_jobs
|
59
|
-
stale_jobs = get_processing_jobs_by_other_workers
|
60
|
-
raise "Stale Delayed Jobs of Group Id(#{@split_group_id}): #{stale_jobs.pluck(:id)}"
|
61
|
+
stale_jobs = get_processing_jobs_by_other_workers
|
62
|
+
raise "Stale Delayed Jobs of Group Id(#{@split_group_id}): #{stale_jobs.pluck(:id)}"
|
61
63
|
end
|
62
64
|
|
63
65
|
def get_processing_jobs_by_other_workers
|
64
66
|
Delayed::Job.where(split_group_id: @split_group_id, failed_at: nil).where.not(locked_by: nil)
|
65
67
|
end
|
66
68
|
|
67
|
-
def get_delayed_jobs_pids
|
68
|
-
bash_op = `ps aux | grep delayed_job | grep -v 'grep' | grep -v 'bin/sh' | grep -v 'tail' | grep -v 'ruby' | grep -v 'trace'`
|
69
|
-
processes = bash_op.split("\n")
|
70
|
-
pid_array = []
|
71
|
-
processes.each do |process|
|
72
|
-
split_process = process.split(" ")
|
73
|
-
pid_array << split_process[1]
|
74
|
-
end
|
75
|
-
pid_array
|
76
|
-
end
|
77
|
-
|
78
69
|
def handle_failed_jobs
|
79
70
|
failed_jobs = Delayed::Job.where(split_group_id: @split_group_id).where.not(failed_at: nil)
|
80
71
|
raise "Failed Delayed Jobs of Group Id(#{@split_group_id}): #{failed_jobs.pluck(:id)}" if failed_jobs.exists?
|
@@ -88,7 +79,11 @@ module DjSplit
|
|
88
79
|
@split_options[:size] || OPTIMAL_SPLIT_SIZE
|
89
80
|
end
|
90
81
|
|
91
|
-
def
|
82
|
+
def get_stale_job_timeout_value
|
83
|
+
@split_options[:timeout] || STALE_JOBS_TIMEOUT
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_sliced_ids(ids)
|
92
87
|
ids.each_slice(get_split_size)
|
93
88
|
end
|
94
89
|
|
@@ -101,9 +96,9 @@ module DjSplit
|
|
101
96
|
Time.now.to_i.to_s[5..-1] + rand(1000000000).to_s
|
102
97
|
end
|
103
98
|
|
104
|
-
# Check
|
105
|
-
def
|
106
|
-
(
|
99
|
+
# Check whether the timeout is reached?
|
100
|
+
def check_for_timeout?(count)
|
101
|
+
(SLEEP_TIME * count) > get_stale_job_timeout_value
|
107
102
|
end
|
108
103
|
end
|
109
104
|
end
|
data/lib/dj_split/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dj_split
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Md Nehal Amin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 5.11
|
47
|
+
version: '5.11'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 5.11
|
54
|
+
version: '5.11'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0
|
117
|
+
version: '4.0'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0
|
124
|
+
version: '4.0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rails
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,10 +138,10 @@ dependencies:
|
|
138
138
|
version: '0'
|
139
139
|
description: Gem is designed to "Split or Break" Time Taking Jobs(Delayed Jobs, Crons,
|
140
140
|
Bulk Operations, etc.) into smaller size Mutually Exclusive Delayed Jobs. These
|
141
|
-
Sub-Jobs can be picked by
|
142
|
-
splitting and enqueuing, the process will wait for the sub-jobs to complete
|
143
|
-
also processes sub-jobs instead of blocking. Parallelism can be achieved across
|
144
|
-
multiple servers through Delayed Jobs which can directly impact performance. Performance
|
141
|
+
Sub-Jobs can be picked by "Multiple Workers" in "Single" or "Multiple Servers".
|
142
|
+
After splitting and enqueuing, the process will wait for the sub-jobs to complete
|
143
|
+
and also processes sub-jobs instead of blocking. "Parallelism" can be achieved across
|
144
|
+
multiple servers through Delayed Jobs which can directly impact performance. "Performance"
|
145
145
|
can improve up to "n+1" times, where n = number of workers picking the jobs.
|
146
146
|
email:
|
147
147
|
- nehalamin93@gmail.com
|