sidekiq_publisher 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +15 -0
- data/lib/sidekiq_publisher.rb +6 -1
- data/lib/sidekiq_publisher/job.rb +2 -17
- data/lib/sidekiq_publisher/publisher.rb +17 -3
- data/lib/sidekiq_publisher/version.rb +1 -1
- data/sidekiq_publisher.gemspec +1 -3
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a5c547481b5ced12b2104fae37180f6e69afb53e56e33c63aa3ab5341c17cde
|
4
|
+
data.tar.gz: 8726552f9f5e2713e10125763b67210515ca450be70450facbb0d2a0b5d969ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 343cf4ef74e8e0a30be17386f8174976b328ccb842f75203f994af0f1d0a83112214c8f03e6dea00f4aacab50aeef695457203d561e2df596224b16ba9375eea
|
7
|
+
data.tar.gz: 29b3a7ffee99df51593c59786c712ea8af6468baf866879a40a3aaf2404435fcaaa5549cab8b7d2c5575a124d5c57f06c2aa9d7abefee06359b9c80abfaef815
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
# sidekiq_publisher
|
2
2
|
|
3
|
+
## v0.2.0
|
4
|
+
- Add caching for job class constant lookup.
|
5
|
+
- Add metrics for the number of jobs published and purged.
|
6
|
+
- Add ActiveSupport as a runtime dependency.
|
7
|
+
|
8
|
+
## v0.1.1
|
9
|
+
- Publish Sidekiq jobs with the `created_at` value from when the job was inserted
|
10
|
+
into the table.
|
11
|
+
|
3
12
|
## v0.1.0
|
4
13
|
- Initial version
|
data/README.md
CHANGED
@@ -38,11 +38,26 @@ This gem uses the following configuration:
|
|
38
38
|
|
39
39
|
* **logger**: the logger for this gem to use.
|
40
40
|
* **exception_reporter**: a Proc that will be called with an exception
|
41
|
+
* **metrics_reporter**: an optional object to record metrics. See below.
|
41
42
|
* **batch_size**: the maximum number of jobs that will be enqueued to Sidekiq
|
42
43
|
together
|
43
44
|
* **job_retention_period**: the duration that published jobs will be kept in
|
44
45
|
Postgres after they have been enqueued to Sidekiq
|
45
46
|
|
47
|
+
### Metrics Reporter
|
48
|
+
|
49
|
+
The metrics reporter that can be configured with an object that is expected to
|
50
|
+
respond to the following API:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
count(metric_name, count)
|
54
|
+
```
|
55
|
+
|
56
|
+
Metrics will be reported for:
|
57
|
+
|
58
|
+
- the number of jobs published in each batch
|
59
|
+
- the number of jobs purged
|
60
|
+
|
46
61
|
## Usage
|
47
62
|
|
48
63
|
### ActiveJob Adapter
|
data/lib/sidekiq_publisher.rb
CHANGED
@@ -13,9 +13,13 @@ module SidekiqPublisher
|
|
13
13
|
DEFAULT_JOB_RETENTION_PERIOD = 1.day.freeze
|
14
14
|
|
15
15
|
class << self
|
16
|
-
attr_accessor :logger, :exception_reporter
|
16
|
+
attr_accessor :logger, :exception_reporter, :metrics_reporter
|
17
17
|
attr_writer :batch_size, :job_retention_period
|
18
18
|
|
19
|
+
def configure
|
20
|
+
yield self
|
21
|
+
end
|
22
|
+
|
19
23
|
def batch_size
|
20
24
|
@batch_size || DEFAULT_BATCH_SIZE
|
21
25
|
end
|
@@ -29,6 +33,7 @@ module SidekiqPublisher
|
|
29
33
|
@batch_size = nil
|
30
34
|
@job_retention_period = nil
|
31
35
|
@exception_reporter = nil
|
36
|
+
@metrics_reporter = nil
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
@@ -6,7 +6,7 @@ module SidekiqPublisher
|
|
6
6
|
class Job < ActiveRecord::Base
|
7
7
|
self.table_name = "sidekiq_publisher_jobs"
|
8
8
|
|
9
|
-
BATCH_KEYS = %i(id job_id job_class args run_at queue wrapped).freeze
|
9
|
+
BATCH_KEYS = %i(id job_id job_class args run_at queue wrapped created_at).freeze
|
10
10
|
|
11
11
|
before_create :ensure_job_id
|
12
12
|
before_save :ensure_string_job_class
|
@@ -34,6 +34,7 @@ module SidekiqPublisher
|
|
34
34
|
SidekiqPublisher.logger.info("#{name} purging expired published jobs.")
|
35
35
|
count = purgeable.delete_all
|
36
36
|
SidekiqPublisher.logger.info("#{name} purged #{count} expired published jobs.")
|
37
|
+
SidekiqPublisher.metrics_reporter.try(:count, "sidekiq_publisher:purged", count)
|
37
38
|
end
|
38
39
|
|
39
40
|
def self.unpublished_batches(batch_size: SidekiqPublisher.batch_size)
|
@@ -43,22 +44,6 @@ module SidekiqPublisher
|
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
|
-
# TODO: this method was just for testing and may be removed
|
47
|
-
def publish
|
48
|
-
Sidekiq::Client.push(sidekiq_item)
|
49
|
-
end
|
50
|
-
|
51
|
-
def sidekiq_item
|
52
|
-
{
|
53
|
-
"jid" => job_id,
|
54
|
-
"class" => job_class.constantize,
|
55
|
-
"args" => args,
|
56
|
-
"at" => run_at,
|
57
|
-
"queue" => queue,
|
58
|
-
"wrapped" => wrapped,
|
59
|
-
}.tap(&:compact!)
|
60
|
-
end
|
61
|
-
|
62
47
|
private
|
63
48
|
|
64
49
|
def ensure_job_id
|
@@ -1,15 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "sidekiq_publisher/client"
|
4
|
+
require "active_support/core_ext/object/try"
|
4
5
|
|
5
6
|
module SidekiqPublisher
|
6
7
|
class Publisher
|
7
8
|
extend PrivateAttr
|
8
9
|
|
9
|
-
private_attr_reader :client
|
10
|
+
private_attr_reader :client, :job_class_cache
|
10
11
|
|
11
12
|
def initialize
|
12
13
|
@client = SidekiqPublisher::Client.new
|
14
|
+
@job_class_cache = {}
|
13
15
|
end
|
14
16
|
|
15
17
|
def publish
|
@@ -17,11 +19,12 @@ module SidekiqPublisher
|
|
17
19
|
items = batch.map do |job|
|
18
20
|
{
|
19
21
|
"jid" => job[:job_id],
|
20
|
-
"class" => job[:job_class]
|
22
|
+
"class" => lookup_job_class(job[:job_class]),
|
21
23
|
"args" => job[:args],
|
22
24
|
"at" => job[:run_at],
|
23
25
|
"queue" => job[:queue],
|
24
26
|
"wrapped" => job[:wrapped],
|
27
|
+
"created_at" => job[:created_at].to_f,
|
25
28
|
}.tap(&:compact!)
|
26
29
|
end
|
27
30
|
|
@@ -40,7 +43,14 @@ module SidekiqPublisher
|
|
40
43
|
rescue StandardError => ex
|
41
44
|
failure_warning(__method__, ex)
|
42
45
|
ensure
|
43
|
-
update_jobs_as_published!(batch) if pushed_count.present? && published_count.nil?
|
46
|
+
published_count = update_jobs_as_published!(batch) if pushed_count.present? && published_count.nil?
|
47
|
+
metrics_reporter.try(:count, "sidekiq_publisher:published", published_count)
|
48
|
+
end
|
49
|
+
|
50
|
+
def lookup_job_class(name)
|
51
|
+
job_class_cache.fetch(name) do
|
52
|
+
job_class_cache[name] = name.constantize
|
53
|
+
end
|
44
54
|
end
|
45
55
|
|
46
56
|
def update_jobs_as_published!(jobs)
|
@@ -64,5 +74,9 @@ module SidekiqPublisher
|
|
64
74
|
def logger
|
65
75
|
SidekiqPublisher.logger
|
66
76
|
end
|
77
|
+
|
78
|
+
def metrics_reporter
|
79
|
+
SidekiqPublisher.metrics_reporter
|
80
|
+
end
|
67
81
|
end
|
68
82
|
end
|
data/sidekiq_publisher.gemspec
CHANGED
@@ -9,11 +9,9 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.version = SidekiqPublisher::VERSION
|
10
10
|
spec.authors = ["ezCater, Inc"]
|
11
11
|
spec.email = ["engineering@ezcater.com"]
|
12
|
-
|
13
12
|
spec.summary = "Publisher for enqueuing jobs to Sidekiq"
|
14
13
|
spec.description = spec.summary
|
15
14
|
spec.homepage = "https://github.com/ezcater/sidekiq_publisher"
|
16
|
-
|
17
15
|
spec.license = "MIT"
|
18
16
|
|
19
17
|
# Set "allowed_push_post" to control where this gem can be published.
|
@@ -23,7 +21,6 @@ Gem::Specification.new do |spec|
|
|
23
21
|
else
|
24
22
|
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
25
23
|
end
|
26
|
-
# rubocop:enable Style/GuardClause
|
27
24
|
|
28
25
|
excluded_files = %w(.circleci/config.yml
|
29
26
|
.github/PULL_REQUEST_TEMPLATE.md
|
@@ -59,6 +56,7 @@ Gem::Specification.new do |spec|
|
|
59
56
|
spec.add_development_dependency "simplecov"
|
60
57
|
|
61
58
|
spec.add_runtime_dependency "activerecord-postgres_pub_sub"
|
59
|
+
spec.add_runtime_dependency "activesupport", "~> 5.1.4"
|
62
60
|
spec.add_runtime_dependency "private_attr"
|
63
61
|
spec.add_runtime_dependency "sidekiq", "~> 5.0.4"
|
64
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq_publisher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ezCater, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -206,6 +206,20 @@ dependencies:
|
|
206
206
|
- - ">="
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: activesupport
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - "~>"
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: 5.1.4
|
216
|
+
type: :runtime
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - "~>"
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 5.1.4
|
209
223
|
- !ruby/object:Gem::Dependency
|
210
224
|
name: private_attr
|
211
225
|
requirement: !ruby/object:Gem::Requirement
|