rocketjob 5.2.0 → 5.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6715f9b19c04ee07962197db8e635e9e5e74b1e1dbd9e3add5239d235c5dd218
4
- data.tar.gz: 5c501260e0e328691f668325ff48e88ea5da86f49f6a739343b5bf24569aee75
3
+ metadata.gz: fe39da29017eca601c104ca9d7c4fa90f903c32cbf3822e064cbd4a7f0780272
4
+ data.tar.gz: ce81cfb0d3a0ac4dbfe4ebe7c549077e56ca52d19ca41a2fda150561ecfeedd7
5
5
  SHA512:
6
- metadata.gz: db9890e678c9e2cb97c6f8faf25e8115f5946017ed3dc0fc3f208a62c2765fabb2c5f7673c9850b6202c61bd312c0e535944609e21e3dbbfd514eff2a50ffa0a
7
- data.tar.gz: ede6fbe558cb428c3291bba1584d32dffcc65c6889ab90753e1a79ce33713410b071e2db44bf5007119ba0a83867e2d42485f1b16bfa4070b0a36e7ca89bbf13
6
+ metadata.gz: fa49046d738a5064da99363e0d854253d17c375ab1e75b095c118139d9081781b9e4177bc03cf70abd4edb906b43cdc033b96234bd5864b5f9959e81f1421074
7
+ data.tar.gz: 5e67742618a4ec874a1c43649d8619cec007380f8db84a3a81f584ec6f9896be0e14e062e69955158732b32e419a8ac7bfab9eef394c983a9f484a9c5c04c934
data/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
 
4
4
  Ruby's missing batch system
5
5
 
6
- Checkout http://rocketjob.io/
6
+ Checkout https://rocketjob.io/
7
7
 
8
- ![Rocket Job](http://rocketjob.io/images/rocket/rocket-icon-512x512.png)
8
+ ![Rocket Job](https://rocketjob.io/images/rocket/rocket-icon-512x512.png)
9
9
 
10
10
  ## Documentation
11
11
 
@@ -24,6 +24,7 @@ module RocketJob
24
24
  autoload :LowerPriority, "rocket_job/batch/lower_priority"
25
25
  autoload :Performance, "rocket_job/batch/performance"
26
26
  autoload :Statistics, "rocket_job/batch/statistics"
27
+ autoload :ThrottleWindows, "rocket_job/batch/throttle_windows"
27
28
  autoload :Result, "rocket_job/batch/result"
28
29
  autoload :Results, "rocket_job/batch/results"
29
30
  autoload :Tabular, "rocket_job/batch/tabular"
@@ -18,7 +18,7 @@ module RocketJob
18
18
  raise "Category #{category.inspect}, must be registered in input_categories: #{input_categories.inspect}"
19
19
  end
20
20
 
21
- (@inputs ||= {})[category] ||= RocketJob::Sliced::Input.new(rocket_job_io_slice_arguments("inputs", category))
21
+ (@inputs ||= {})[category] ||= RocketJob::Sliced::Input.new(**rocket_job_io_slice_arguments("inputs", category))
22
22
  end
23
23
 
24
24
  # Returns [RocketJob::Sliced::Output] output collection for holding output slices
@@ -34,7 +34,7 @@ module RocketJob
34
34
  raise "Category #{category.inspect}, must be registered in output_categories: #{output_categories.inspect}"
35
35
  end
36
36
 
37
- (@outputs ||= {})[category] ||= RocketJob::Sliced::Output.new(rocket_job_io_slice_arguments("outputs", category))
37
+ (@outputs ||= {})[category] ||= RocketJob::Sliced::Output.new(**rocket_job_io_slice_arguments("outputs", category))
38
38
  end
39
39
 
40
40
  # Upload the supplied file, io, IOStreams::Path, or IOStreams::Stream.
@@ -6,7 +6,7 @@ module RocketJob
6
6
  #
7
7
  # Example:
8
8
  # # Do not run any slices for this job when the MySQL slave delay exceeds 5 minutes.
9
- # class MyJob < RocketJob
9
+ # class MyJob < RocketJob::Job
10
10
  # include RocketJob::Batch
11
11
  #
12
12
  # # Define a custom mysql throttle
@@ -5,7 +5,7 @@ module RocketJob
5
5
  # Throttle the number of slices of a specific batch job that are processed at the same time.
6
6
  #
7
7
  # Example:
8
- # class MyJob < RocketJob
8
+ # class MyJob < RocketJob::Job
9
9
  # include RocketJob::Batch
10
10
  #
11
11
  # # Maximum number of slices to process at the same time for each running instance.
@@ -0,0 +1,67 @@
1
+ require "active_support/concern"
2
+
3
+ module RocketJob
4
+ module Batch
5
+ # For a batch job that can run over a long period of time it can be useful
6
+ # to prevent its slices from being processed outside a predefined processing window.
7
+ #
8
+ # This plugin supports up to 2 different processing windows.
9
+ #
10
+ # For example, do not run this job during business hours.
11
+ # Allow it to run from 5pm until 8am the following day Mon through Fri.
12
+ #
13
+ # class AfterHoursJob < RocketJob::Job
14
+ # include RocketJob::Batch
15
+ # include RocketJob::Batch::ThrottleWindows
16
+ #
17
+ # # Monday through Thursday the job can start processing at 5pm Eastern.
18
+ # self.primary_schedule = "0 17 * * 1-4 America/New_York"
19
+ # # Slices are allowed to run until 8am the following day, which is 15 hours long:
20
+ # self.primary_duration = 15.hours
21
+ #
22
+ # # The slices for this job can run all weekend long, starting Friday at 5pm Eastern.
23
+ # self.secondary_schedule = "0 17 * * 5 America/New_York"
24
+ # # Slices are allowed to run until 8am on Monday morning, which is 63 hours long:
25
+ # self.secondary_duration = 63.hours
26
+ # end
27
+ #
28
+ # Notes:
29
+ # * These schedules do not affect when the job is started, completed, or when `before_batch` or
30
+ # `after_batch` processing is performed. It only limits when individual slices are processed.
31
+ module ThrottleWindows
32
+ extend ActiveSupport::Concern
33
+
34
+ included do
35
+ # Beginning of the primary schedule. In cron format, see Scheduled Jobs `cron_schedule` for examples.
36
+ field :primary_schedule, type: String, class_attribute: true, user_editable: true, copy_on_restart: true
37
+ # Duration in seconds of the primary window.
38
+ field :primary_duration, type: Integer, class_attribute: true, user_editable: true, copy_on_restart: true
39
+
40
+ # Beginning of the secondary schedule. In cron format, see Scheduled Jobs `cron_schedule` for examples.
41
+ field :secondary_schedule, type: String, class_attribute: true, user_editable: true, copy_on_restart: true
42
+ # Duration in seconds of the secondary window.
43
+ field :secondary_duration, type: Integer, class_attribute: true, user_editable: true, copy_on_restart: true
44
+
45
+ define_batch_throttle :throttle_windows_exceeded?, filter: :throttle_filter_id
46
+ end
47
+
48
+ private
49
+
50
+ def throttle_windows_exceeded?
51
+ exceeded = primary_schedule && primary_duration && throttle_outside_window?(primary_schedule, primary_duration)
52
+ if exceeded && secondary_schedule && secondary_duration
53
+ exceeded = throttle_outside_window?(secondary_schedule, secondary_duration)
54
+ end
55
+ exceeded
56
+ end
57
+
58
+ def throttle_outside_window?(schedule, duration)
59
+ cron = Plugins::Rufus::CronLine.new(schedule)
60
+ time = Time.now + 1
61
+ # Add 1 second since right now could be the very beginning of the processing window.
62
+ previous_time = cron.previous_time(time).to_time
63
+ previous_time + duration < time
64
+ end
65
+ end
66
+ end
67
+ end
@@ -28,10 +28,6 @@ module RocketJob
28
28
  #
29
29
  # If an exception was thrown the entire slice of records is marked as failed.
30
30
  #
31
- # If the mongo_ha gem has been loaded, then the connection to mongo is
32
- # automatically re-established and the job will resume anytime a
33
- # Mongo connection failure occurs.
34
- #
35
31
  # Thread-safe, can be called by multiple threads at the same time
36
32
  def rocket_job_work(worker, re_raise_exceptions = false)
37
33
  raise "Job must be started before calling #rocket_job_work" unless running?
@@ -7,7 +7,7 @@ module RocketJob
7
7
  #
8
8
  # Example:
9
9
  # # Do not run this job when the MySQL slave delay exceeds 5 minutes.
10
- # class MyJob < RocketJob
10
+ # class MyJob < RocketJob::Job
11
11
  # # Define a custom mysql throttle
12
12
  # # Prevents all jobs of this class from running on the current server.
13
13
  # define_throttle :mysql_throttle_exceeded?
@@ -6,7 +6,7 @@ module RocketJob
6
6
  # Throttle the number of jobs of a specific class that are processed at the same time.
7
7
  #
8
8
  # Example:
9
- # class MyJob < RocketJob
9
+ # class MyJob < RocketJob::Job
10
10
  # # Maximum number of jobs of this class to process at the same time.
11
11
  # self.throttle_running_jobs = 25
12
12
  #
@@ -1,3 +1,3 @@
1
1
  module RocketJob
2
- VERSION = "5.2.0".freeze
2
+ VERSION = "5.3.0".freeze
3
3
  end
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: 5.2.0
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2020-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm
@@ -124,6 +124,7 @@ files:
124
124
  - lib/rocket_job/batch/tabular/output.rb
125
125
  - lib/rocket_job/batch/throttle.rb
126
126
  - lib/rocket_job/batch/throttle_running_workers.rb
127
+ - lib/rocket_job/batch/throttle_windows.rb
127
128
  - lib/rocket_job/batch/worker.rb
128
129
  - lib/rocket_job/cli.rb
129
130
  - lib/rocket_job/config.rb
@@ -211,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
212
  - !ruby/object:Gem::Version
212
213
  version: '0'
213
214
  requirements: []
214
- rubygems_version: 3.0.8
215
+ rubygems_version: 3.1.2
215
216
  signing_key:
216
217
  specification_version: 4
217
218
  summary: Ruby's missing batch processing system.