sidekiq-amigo 1.0.0 → 1.1.0

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: b5204accb28834a6d5cb0baf274aa92e96f8ab2480316d6578c1e35e31075f44
4
- data.tar.gz: c397ff5a38053be56726310f8b5e4e1b934c85c84f17fa60bb636e6d4b477252
3
+ metadata.gz: 8980dca10a4706347222badd39dbd267466d6b5add00eaba00e25181467b4964
4
+ data.tar.gz: 48f7d54c1d104fdafbcc1eb27367084d89c6b77dbf71c1256f30faf88f3b0a10
5
5
  SHA512:
6
- metadata.gz: 04ce08ea274cf3132db350ecf826787e594faa47e1905fbc61307156d6b87f6a33b5301c05acf2b88b21aff52d600e52ae7cc31dd83f53e72ac972c5c2b56e0e
7
- data.tar.gz: e46d7aab0d27953b1d16903cb98d77e8b8ddcbe56ea091950c76bdf60c18e3207cc085dc2c87e3f0e78c2f7e310325d4de8492c3d73f04babdcbf0a53be2a3f9
6
+ metadata.gz: 5660f11c1f9f76603e61fdc2f3dbbd16031c32871dce14f587990a5ab076e4573311483d322d58bea4cef392764ae4a6bf663945a23356782c04a8b805075417
7
+ data.tar.gz: fd2303da8f7c9c9cd0ea279b4ab2913a1e4ae4c817bad60c2ef9c7541213d7783b8843843a3112b68dab5a1c99d107fc870b86db29bd8c6598b0f095cf6e1b37
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "amigo/job"
3
+ require "amigo"
4
4
 
5
5
  class Amigo
6
6
  class AuditLogger
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "amigo"
3
4
  require "amigo/job"
4
5
 
5
6
  # Put jobs here to die. If you just remove a job in Sidekiq, it may be queued up
data/lib/amigo/job.rb CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  require "sidekiq"
4
4
 
5
+ require "amigo"
6
+
5
7
  class Amigo
6
8
  module Job
7
9
  def self.extended(cls)
8
- Amigo.registered_jobs << cls
9
-
10
10
  cls.include(Sidekiq::Worker)
11
11
  cls.extend(ClassMethods)
12
12
  cls.pattern = ""
data/lib/amigo/router.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "amigo/job"
3
+ require "sidekiq"
4
+
5
+ require "amigo"
4
6
 
5
7
  class Amigo
6
8
  class Router
@@ -8,8 +8,6 @@ require "amigo"
8
8
  class Amigo
9
9
  module ScheduledJob
10
10
  def self.extended(cls)
11
- Amigo.registered_jobs << cls
12
-
13
11
  cls.include(Sidekiq::Worker)
14
12
  cls.sidekiq_options(retry: false)
15
13
  cls.extend(ClassMethods)
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "sidekiq/testing"
4
4
 
5
+ require "amigo"
6
+
5
7
  class Amigo
6
8
  module SpecHelpers
7
9
  def self.included(context)
data/lib/amigo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Amigo
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
data/lib/amigo.rb CHANGED
@@ -98,10 +98,9 @@ require "sidekiq-cron"
98
98
  # Splay defaults to 30s; you may wish to always provide splay, whatever you think for your job.
99
99
  #
100
100
  class Amigo
101
- require "amigo/job"
102
- require "amigo/scheduled_job"
103
- require "amigo/audit_logger"
104
- require "amigo/router"
101
+ class Error < StandardError; end
102
+
103
+ class StartSchedulerFailed < Error; end
105
104
 
106
105
  class << self
107
106
  attr_accessor :structured_logging
@@ -180,6 +179,8 @@ class Amigo
180
179
  # Install Amigo so that every publish will be sent to the AuditLogger job
181
180
  # and will invoke the relevant jobs in registered_jobs via the Router job.
182
181
  def install_amigo_jobs
182
+ require "amigo/audit_logger"
183
+ require "amigo/router"
183
184
  return self.register_subscriber do |ev|
184
185
  self._subscriber(ev)
185
186
  end
@@ -190,21 +191,25 @@ class Amigo
190
191
  Amigo::AuditLogger.perform_async(event_json)
191
192
  Amigo::Router.perform_async(event_json)
192
193
  end
193
- #
194
- # # Start the scheduler.
195
- # # This should generally be run in the Sidekiq worker process,
196
- # # not a webserver process.
197
- # def self.start_scheduler
198
- # hash = self.scheduled_jobs.each_with_object({}) do |job, memo|
199
- # self.logger.info "Scheduling %s every %p" % [job.name, job.cron_expr]
200
- # memo[job.name] = {
201
- # "class" => job.name,
202
- # "cron" => job.cron_expr,
203
- # }
204
- # end
205
- # load_errs = Sidekiq::Cron::Job.load_from_hash hash
206
- # raise "Errors loading sidekiq-cron jobs: %p" % [load_errs] if load_errs.present?
207
- # end
194
+
195
+ def register_job(job)
196
+ self.registered_jobs << job
197
+ end
198
+
199
+ # Start the scheduler.
200
+ # This should generally be run in the Sidekiq worker process,
201
+ # not a webserver process.
202
+ def start_scheduler(load_from_hash=Sidekiq::Cron::Job.method(:load_from_hash))
203
+ hash = self.registered_scheduled_jobs.each_with_object({}) do |job, memo|
204
+ self.log(nil, :info, "scheduling_job_cron", {job_name: job.name, job_cron: job.cron_expr})
205
+ memo[job.name] = {
206
+ "class" => job.name,
207
+ "cron" => job.cron_expr,
208
+ }
209
+ end
210
+ load_errs = load_from_hash.call(hash) || {}
211
+ raise StartSchedulerFailed, "Errors loading sidekiq-cron jobs: %p" % [load_errs] unless load_errs.empty?
212
+ end
208
213
  end
209
214
 
210
215
  class Event
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-amigo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lithic Technology
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-04 00:00:00.000000000 Z
11
+ date: 2022-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq