rocketjob 4.1.0 → 4.1.1

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: d14befce83747b072cf398356d5a5a798630d65c9aa50ec5f5de1e1f4d0e8d69
4
- data.tar.gz: 17c5e295968836458ef1b998d1ffb79228ab6b5971c6339ec1bdc74d429d2511
3
+ metadata.gz: a88179130b3f8b1570a98c02b22b1daa93d1cfff9e91231f12c08af3eb47c750
4
+ data.tar.gz: e6fc5a6cf000dc9faa61b61bb232aaef6bf77dec144959e6bfb2114e193845db
5
5
  SHA512:
6
- metadata.gz: 07b25f25ca1fd804e6c3d98ebcf3724acb8bcb564281f1b5ffd21bd815e8a05d7a99988721c5e3a25063da44f800ea3c998fcbecd7751a8b10755b214804feab
7
- data.tar.gz: 48093ed5e152571a097e07f8e606df99fc48fcf1f8364e78b77d371e5e668acf384c972a002c078930b1af809dd7e34483ba28194fbcd52a9ae06bfb60f2dfce
6
+ metadata.gz: cef575bafd6e780beb0c235bfae3efab3c79ae456cf907c1335372f664ccab1ea125cfd9cbcca17a7791b328b97f78750bc039adf80786bf48834d9d1e6079af
7
+ data.tar.gz: dd88230b68ecf82433c641f903fcec276b0e873c8849dd1873ed4ee14cd88d3e99fe93ca4ffaf3f973efca16d6837bb1daf3cb91202176ec909a8c19bf28fc08
@@ -65,6 +65,18 @@ module RocketJob
65
65
  count
66
66
  end
67
67
 
68
+ def upload_arel(arel, *column_names, category: :main, &block)
69
+ count = input(category).upload_arel(arel, *column_names, &block)
70
+ self.record_count = (record_count || 0) + count
71
+ count
72
+ end
73
+
74
+ def upload_mongo_query(criteria, *column_names, category: :main, &block)
75
+ count = input(category).upload_mongo_query(criteria, *column_names, &block)
76
+ self.record_count = (record_count || 0) + count
77
+ count
78
+ end
79
+
68
80
  # Upload the supplied slices for processing by workers
69
81
  #
70
82
  # Updates the record_count after adding the records
@@ -1,4 +1,4 @@
1
- # Generalized Batch Job.
1
+ # Job to dynamically perform ruby code on demand as a Batch,
2
2
  #
3
3
  # Often used for data correction or cleansing.
4
4
  #
@@ -1,4 +1,4 @@
1
- # Generalized Job.
1
+ # Job to dynamically perform ruby code on demand,
2
2
  #
3
3
  # Create or schedule a generalized job for one off fixes or cleanups.
4
4
  #
@@ -1,4 +1,6 @@
1
1
  require 'fileutils'
2
+ require 'uri'
3
+
2
4
  begin
3
5
  require 'iostreams'
4
6
  rescue LoadError
@@ -91,9 +93,12 @@ module RocketJob
91
93
  end
92
94
 
93
95
  def file_exists
94
- return if upload_file_name.nil? || File.exist?(upload_file_name)
96
+ return if upload_file_name.nil?
97
+ uri = URI.parse(upload_file_name)
98
+ return unless uri.scheme.nil? || uri.scheme == 'file'
99
+ return if File.exist?(upload_file_name)
95
100
  errors.add(:upload_file_name, "Upload file: #{upload_file_name} does not exist.")
96
101
  end
97
- end
102
+ end
98
103
  end
99
104
  end
@@ -4,27 +4,12 @@ module RocketJob
4
4
  module Plugins
5
5
  # Automatically retry the job on failure.
6
6
  #
7
- # The following retry algorithm is used to automatically retry a job when it fails:
8
- # Failed jobs are aborted so that they cannot be restarted since a new instance has there are workers
9
- # available to run. For example if workers are busy working on higher priority jobs, then the job
10
- # will only run once those jobs have completed, or their priority lowered. Additionally, while the
11
- # job is queued no additional instances will be enqueued, even if the next cron interval has been reached.
12
- #
13
- # Note:
14
- # - After failure the job is scheduled to run again in the future.
15
- # - The job will not be retried if:
16
- # - The job has expired.
17
- # - The job fails validations.
18
- # - The number of retry counts has been exceeded.
19
- # - To see the number of times a job has failed so far:
20
- # job.failure_count
21
- #
22
7
  # Example:
23
8
  #
24
9
  # class MyJob < RocketJob::Job
25
10
  # include RocketJob::Plugins::Retry
26
11
  #
27
- # # Set the default retry_count
12
+ # # Set the maximum number of times a job should be retried before giving up.
28
13
  # self.retry_limit = 3
29
14
  #
30
15
  # def perform
@@ -35,10 +20,10 @@ module RocketJob
35
20
  # # Queue the job for processing using the default cron_schedule specified above
36
21
  # MyJob.create!
37
22
  #
38
- # # Replace the default retry_count
23
+ # # Override the default retry_limit for a specific job instance.
39
24
  # MyCronJob.create!(retry_limit: 10)
40
25
  #
41
- # # Disable retries for this job instance
26
+ # # Disable retries for this job instance.
42
27
  # MyCronJob.create!(retry_limit: 0)
43
28
  #
44
29
  module Retry
@@ -107,7 +107,6 @@ module RocketJob
107
107
  IOStreams.public_send(iterator, file_name_or_io, encoding: encoding, **args) { |line| io << line }
108
108
  end
109
109
 
110
- create_indexes
111
110
  Writer::Input.collect(self, on_first: on_first, &block)
112
111
  end
113
112
 
@@ -141,7 +140,6 @@ module RocketJob
141
140
  # criteria = User.where(state: 'FL')
142
141
  # job.record_count = job.upload_mongo_query(criteria, :zip_code)
143
142
  def upload_mongo_query(criteria, *column_names, &block)
144
- create_indexes
145
143
  options = criteria.options
146
144
 
147
145
  # Without a block extract the fields from the supplied criteria
@@ -198,7 +196,6 @@ module RocketJob
198
196
  # arel = User.where(country_code: 'US')
199
197
  # job.record_count = job.upload_arel(arel, :user_name, :zip_code)
200
198
  def upload_arel(arel, *column_names, &block)
201
- create_indexes
202
199
  unless block
203
200
  column_names = column_names.collect(&:to_sym)
204
201
  column_names << :id if column_names.size.zero?
@@ -21,7 +21,9 @@ module RocketJob
21
21
  @slice_class = slice_class
22
22
  @slice_size = slice_size
23
23
  @collection_name = collection_name
24
- @all = slice_class.with_collection(collection_name)
24
+
25
+ # Using `Sliced::Slice` avoids having to add `_type` as an index when all slices are the same type anyway.
26
+ @all = Sliced::Slice.with_collection(collection_name)
25
27
  end
26
28
 
27
29
  def new(params = {})
@@ -14,6 +14,8 @@ module RocketJob
14
14
  # Default: nil
15
15
  def self.collect(input, **args, &block)
16
16
  writer = new(input, **args)
17
+ # Create indexes before uploading
18
+ input.create_indexes if input.respond_to?(:create_indexes)
17
19
  block.call(writer)
18
20
  writer.record_count
19
21
  rescue Exception => exc
@@ -41,7 +41,7 @@ module RocketJob
41
41
  Thread.new do
42
42
  shutdown!
43
43
  message = 'Shutdown signal (SIGTERM) received. Will shutdown as soon as active jobs/slices have completed.'
44
- logger.warn(message)
44
+ logger.info(message)
45
45
  end
46
46
  end
47
47
 
@@ -49,7 +49,7 @@ module RocketJob
49
49
  Thread.new do
50
50
  shutdown!
51
51
  message = 'Shutdown signal (INT) received. Will shutdown as soon as active jobs/slices have completed.'
52
- logger.warn(message)
52
+ logger.info(message)
53
53
  end
54
54
  end
55
55
  rescue StandardError
@@ -1,3 +1,3 @@
1
1
  module RocketJob
2
- VERSION = '4.1.0'.freeze
2
+ VERSION = '4.1.1'.freeze
3
3
  end
@@ -78,7 +78,7 @@ module RocketJob
78
78
  true
79
79
  end
80
80
 
81
- # Returns [Fixnum] number of workers (threads) that are alive
81
+ # Returns [Integer] number of workers (threads) that are alive
82
82
  def living_count
83
83
  workers.count(&:alive?)
84
84
  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: 4.1.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-08 00:00:00.000000000 Z
11
+ date: 2019-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  requirements: []
196
- rubygems_version: 3.0.2
196
+ rubygems_version: 3.0.3
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: Ruby's missing batch system.