Skip to content

Commit

Permalink
Share behaviour between async jobs
Browse files Browse the repository at this point in the history
- custom queue
- retry behaviour
  • Loading branch information
duncanjbrown committed Jun 24, 2022
1 parent 5ed5867 commit 7f61a28
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-06-21 14:28:17 UTC using RuboCop version 1.26.1.
# on 2022-06-24 12:31:36 UTC using RuboCop version 1.26.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -14,13 +14,14 @@ Naming/FileName:
Exclude:
- 'spec/dummy/config/initializers/dfe-analytics.rb'

# Offense count: 14
# Offense count: 15
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/dfe/analytics.rb'
- 'lib/dfe/analytics/analytics_job.rb'
- 'lib/dfe/analytics/entities.rb'
- 'lib/dfe/analytics/event.rb'
- 'lib/dfe/analytics/event_schema.rb'
Expand Down
1 change: 1 addition & 0 deletions lib/dfe/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'dfe/analytics/fields'
require 'dfe/analytics/entities'
require 'dfe/analytics/event'
require 'dfe/analytics/analytics_job'
require 'dfe/analytics/send_events'
require 'dfe/analytics/load_entities'
require 'dfe/analytics/load_entity_batch'
Expand Down
8 changes: 8 additions & 0 deletions lib/dfe/analytics/analytics_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module DfE
module Analytics
class AnalyticsJob < ActiveJob::Base
queue_as { DfE::Analytics.config.queue }
retry_on StandardError, wait: :exponentially_longer, attempts: 5
end
end
end
2 changes: 1 addition & 1 deletion lib/dfe/analytics/load_entity_batch.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module DfE
module Analytics
class LoadEntityBatch < ActiveJob::Base
class LoadEntityBatch < AnalyticsJob
def perform(model_name, ids, batch_number)
model_class = Object.const_get(model_name)

Expand Down
5 changes: 1 addition & 4 deletions lib/dfe/analytics/send_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

module DfE
module Analytics
class SendEvents < ActiveJob::Base
queue_as { DfE::Analytics.config.queue }
retry_on StandardError, wait: :exponentially_longer, attempts: 5

class SendEvents < AnalyticsJob
def self.do(events)
if DfE::Analytics.async?
perform_later(events)
Expand Down

0 comments on commit 7f61a28

Please sign in to comment.