ruby_job 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: 821db9053dac5262bc2a34f6bdf8f4b3ff71e7d2dca2e857068f69707aa30602
4
- data.tar.gz: 0ec3c26d522afdc40261a9a028daf51335223ceae8ec98fd431b0f9ec19521e7
3
+ metadata.gz: e009f73864ad315c45ebbb3d85d1c06ef6e60753f592b79e0256af8b1ce11c2c
4
+ data.tar.gz: f7b6559ed2d8ba30b2aaf7736622d9bd7c2fe2710d743b09c3167765cea8c35b
5
5
  SHA512:
6
- metadata.gz: 8ccde94161aee53d05f78174c6456fe62e7508cadab821e8f5fc65780ce608a54f086e02250e7e4c0e9028d9010b9fd3fae4c2474d7466de6adf4db359369708
7
- data.tar.gz: ad087c00ad272865d782267d69f03d766eeacfd698aa848022c48b20e938b80fa7329e91eec0362d929af7382e8d3ccbc0e354959795049b3a644cb3f96e40bb
6
+ metadata.gz: f7a4091bc07e2834818a8014a217fdd2621697218bde9eb8212e9c46d383611d6d11998f18e6964d98aa5fca25a191b8dad1403137f541ada0d3ed0b85d48001
7
+ data.tar.gz: dbb80928d879c59b35c595b5d2d1230987d25a43b1617dad210871aed8513871f24dc86ecb0febb0d0114101725bc8f29f1f0af6f0b7022b478cf01bdc6a9ed3
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.0
1
+ 2.5.7
data/.travis.yml CHANGED
@@ -10,6 +10,8 @@ language: ruby
10
10
  os: linux
11
11
 
12
12
  rvm:
13
+ - 2.5.7
14
+ - 2.6.5
13
15
  - 2.7.0
14
16
 
15
17
  before_install:
data/README.md CHANGED
@@ -11,7 +11,7 @@ only supports an [In-Memory Job Store](https://github.com/mimperatore/ruby_job/b
11
11
  implemented through a fast [Fibonacci Heap](https://github.com/mudge/fibonacci_heap).
12
12
 
13
13
  The initial version, which supports only a single queue, runs **200% faster than Sucker Punch**, capable of processing **1,000,000** simple jobs in **28 seconds**
14
- vs. Sucker Punch's 59 seconds (measured on on a MacBook Pro 2.3GHz with 16GB of RAM).
14
+ vs. Sucker Punch's 59 seconds (measured on a MacBook Pro 2.3GHz with 16GB of RAM).
15
15
 
16
16
  Additional features are in the works, including:
17
17
  - Support for multiple queues & queue priorities
@@ -102,6 +102,27 @@ To do so:
102
102
  job.dequeue
103
103
  ```
104
104
 
105
+ ### Job arguments
106
+ Your Job class' `#perform` method signature is:
107
+ ```ruby
108
+ def perform(*args)
109
+ end
110
+ ```
111
+
112
+ When you invoke `#perform_async` (or similar methods), the arguments passed in will get sent to `#perform`.
113
+
114
+ For example, `MyWorker.perform_async(1, 'hello world!', x: 7)` will end up calling `perform(1, 'hello world!', x: 7)` when the job runs.
115
+
116
+ **Note**: Whether and how the arguments are serialized depends on the JobStore being used. `RubyJob::InMemoryJobStore`, the only JobStore
117
+ currently shipped out of the box with this gem, has no need to serialize the arguments, given that everything runs in a single operating system
118
+ process. However, keep in mind that the `Job` class, which is used to represent instances of jobs to run, defines methods `#to_json` and
119
+ `.json_create(hash)` which use `JSON.dump` and `JSON.parse`, respectively, to marshall the arguments. If you're going to implement
120
+ your own JobStore, feel free to avail yourself of these methods.
121
+
122
+ **Pro Tip**: In order to ensure your job code is portable across different JobStore implementations (e.g. in case at some point you think
123
+ you'll need a persistent backing store such as Redis or Cassandra to keep track of your mission critical jobs), ensure the arguments
124
+ you pass serialize and deserialize as you'd expect.
125
+
105
126
  ### Schedule a Job for execution (asynchronously)
106
127
 
107
128
  **Note:** Jobs are scheduled to nearest **millisecond** of the specified start time.
@@ -135,12 +156,13 @@ server = RubyJob::ThreadedServer.new(num_threads: 10, jobstore: MyWorker.jobstor
135
156
 
136
157
  #### Server options
137
158
  ```ruby
138
- server.set(wait: true)
159
+ server.set(wait: true, wait_delay: 0.5)
139
160
  ```
140
161
 
141
- - `wait`[boolean]: determines whether the server should exit when there aren't any processable jobs in the queue. Defaults to `true`.
142
- - `wait_delay`[float]: number of seconds to wait (sleep). Defaults to `0.5`.
162
+ - `wait`[boolean]: determines whether the server should wait or exit when there aren't any processable jobs in the queue. Defaults to `true`.
163
+ - `wait_delay`[float]: if the server is going to wait, the number of seconds to delay before looking for jobs again. Defaults to `0.5`.
143
164
 
165
+ **Note:** The `wait`/`wait_delay` parameters apply independently to each worker thread.
144
166
 
145
167
  #### Starting the server
146
168
  Queued jobs will only run when a Server, attached to the JobStore the jobs have been enqueued to, has been started.
@@ -180,15 +202,15 @@ that's been halted for a significant amount of time will pick up old jobs that m
180
202
  ensure you take that into account in your job processing code if you care about this situation.
181
203
 
182
204
  ### Retries
183
- Jobs will be not be retried by default. To have jobs retry, the worker class must define a `retry?` method that
184
- returns a tuple indicating whether the job should be retried, and how long the retry delay should be: [do_retry, retry_delay]
205
+ By default, jobs that raise errors will be not be retried by default. To have jobs retry, the worker class must define a `retry?` method that
206
+ returns a tuple indicating whether the job should be retried, and how long the retry delay should be: `[do_retry, retry_delay]`
185
207
  ```ruby
186
208
  MAX_RETRIES = 5
187
209
  INITIAL_RETRY_DELAY = 0.5
188
210
 
189
211
  def retry?(attempt:, error:)
190
212
  # determine whether a retry is required, based on the attempt number and error passed in
191
- do_retry = error.is_a?(RetriableError) && (attempt < MAX_RETRIES)
213
+ do_retry = error.is_a?(MyRetriableError) && (attempt < MAX_RETRIES)
192
214
 
193
215
  [do_retry, INITIAL_RETRY_DELAY * 2**(attempt-1)] # exponential backoff
194
216
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyJob
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
data/ruby_job.gemspec CHANGED
@@ -5,6 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'ruby_job/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
+ spec.required_ruby_version = '>= 2.5.7'
8
9
  spec.name = 'ruby_job'
9
10
  spec.version = RubyJob::VERSION
10
11
  spec.authors = ['Marco Imperatore']
@@ -26,8 +27,9 @@ Gem::Specification.new do |spec|
26
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
28
  spec.require_paths = ['lib']
28
29
 
30
+ spec.add_dependency 'fibonacci_heap'
31
+
29
32
  spec.add_development_dependency 'bundler', '~> 2.1'
30
- spec.add_development_dependency 'byebug', '~> 11.0'
31
33
  spec.add_development_dependency 'codecov', '~> 0.1'
32
34
  spec.add_development_dependency 'guard', '~> 2.16'
33
35
  spec.add_development_dependency 'guard-rspec', '~> 4.7'
@@ -35,5 +37,4 @@ Gem::Specification.new do |spec|
35
37
  spec.add_development_dependency 'rspec', '~> 3.9'
36
38
  spec.add_development_dependency 'rubocop', '~> 0.78'
37
39
  spec.add_development_dependency 'timecop', '~> 0.9'
38
- spec.add_dependency 'fibonacci_heap'
39
40
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Imperatore
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-10 00:00:00.000000000 Z
11
+ date: 2020-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: fibonacci_heap
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
20
- type: :development
19
+ version: '0'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.1'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: byebug
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '11.0'
33
+ version: '2.1'
34
34
  type: :development
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: '11.0'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: codecov
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -136,20 +136,6 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.9'
139
- - !ruby/object:Gem::Dependency
140
- name: fibonacci_heap
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
139
  description: 'RubyJob is a framework for running jobs.
154
140
 
155
141
  '
@@ -198,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
198
184
  requirements:
199
185
  - - ">="
200
186
  - !ruby/object:Gem::Version
201
- version: '0'
187
+ version: 2.5.7
202
188
  required_rubygems_version: !ruby/object:Gem::Requirement
203
189
  requirements:
204
190
  - - ">="