background_worker 0.7.0 → 0.8.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: 37f371795b57bf7461a9f02c9f74195daf9d3cb61328fd0eca5f69a2c61447b6
4
- data.tar.gz: 393896f93efac8a56c0806a8664ea381fff12ff31a2e0e31c210d6a3480694b8
3
+ metadata.gz: 061e6c0338c031523b85a90f084aaf996c00cbe9e668428931a98ae3b5a12f36
4
+ data.tar.gz: 36304e141265bc21d2d756d2af7aab6645fbfa9596d5ab5bfe2c115132f685a8
5
5
  SHA512:
6
- metadata.gz: dae022eecbd54ce73185739df605b3fa5ffd1efc12e411d86bd76f6bfac03f4e20616ac20ffdda04d7c3ef3c3d3d403dac69754a45b5ca9d6fb57daab2444acc
7
- data.tar.gz: 0f9f04c606150a637744facdc4c9d9bb02ff1918d52b24fd92f5ebb47ec3606aab2e59567355422b485924352cc471f29e18d4be6438378e3ead11e0aeff3c96
6
+ metadata.gz: f799063ea369646eea2956427aa7bc0cd551229649e9e3cb1b324a8bd1edec162c7d0852dbf0c7ce724d0332c702208097c5a975827d050742c0df11e5e3709a
7
+ data.tar.gz: 6d4487e464251517e318fe59be864d87da48f324aabce3b6d8964971f55fa1a4a3b5dc7f66913fe6ee5654614a72d6fb978887a84829e0afe656313b6d693ca6
data/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
  This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).
5
5
 
6
+ ## 0.8.1
7
+
8
+ - Fix version
9
+
10
+ ## 0.8.0
11
+
12
+ - [PLAT-747] Remove the ability to pass through `method_name`
13
+
6
14
  ## 0.7.0
7
15
 
8
16
  - [PLAT-670] Add queue_as method
data/README.md CHANGED
@@ -10,7 +10,7 @@ Start by making a worker class which extends from BackgroundWorker::Base
10
10
 
11
11
  ```ruby
12
12
  class MyWorker < BackgroundWorker::Base
13
- def my_task(options={})
13
+ def perform(options={})
14
14
  report_progress('Starting')
15
15
  if options[:message].blank?
16
16
  report_failed("No message provided")
@@ -27,7 +27,7 @@ Then, when you want to perform a task in the background, use
27
27
  klass#perform_in_background which exists in Base:
28
28
 
29
29
  ```ruby
30
- worker_id = MyWorker.perform_in_background(:my_task, message: "hello!")
30
+ worker_id = MyWorker.perform_later(message: "hello!")
31
31
  ```
32
32
 
33
33
  # Backgrounded
@@ -37,8 +37,8 @@ provide an #enqueue_with configuration like so:
37
37
 
38
38
  ```ruby
39
39
  BackgroundWorker.configure(
40
- enqueue_with: -> klass, method_name, options {
41
- Resque.enqueue(klass, method_name, options)
40
+ enqueue_with: -> klass, options {
41
+ Resque.enqueue(klass, options)
42
42
  }
43
43
  )
44
44
  ```
@@ -15,6 +15,10 @@ module BackgroundWorker
15
15
  log("Options are: #{options.inspect}")
16
16
  end
17
17
 
18
+ def perform
19
+ raise AbstractError, 'Must be implemented in Job Class'
20
+ end
21
+
18
22
  # Report progress...
19
23
  def report_progress(message)
20
24
  state.message = message
@@ -59,17 +63,16 @@ module BackgroundWorker
59
63
  end
60
64
 
61
65
  # Public method to do in background...
62
- def perform_later(method_name, options = {})
66
+ def perform_later(options = {})
63
67
  opts = options.symbolize_keys
64
68
 
65
- method_name = method_name.to_sym
66
- opts[:uid] ||= BackgroundWorker::Uid.new(to_s, method_name).generate
69
+ opts[:uid] ||= BackgroundWorker::Uid.new(to_s).generate
67
70
 
68
71
  # Store into shared-cache before kicking job off
69
72
  BackgroundWorker::PersistentState.new(opts[:uid], opts.except(:uid))
70
73
 
71
74
  # Enqueue to the background queue
72
- BackgroundWorker.enqueue(self, method_name, opts)
75
+ BackgroundWorker.enqueue(self, opts)
73
76
 
74
77
  opts[:uid]
75
78
  end
@@ -77,11 +80,11 @@ module BackgroundWorker
77
80
  # This method is called by the job runner
78
81
  #
79
82
  # It will just call your preferred method in the worker.
80
- def perform_now(method_name, options = {})
83
+ def perform_now(options = {})
81
84
  BackgroundWorker.verify_active_connections! if BackgroundWorker.config.backgrounded
82
85
 
83
86
  worker = new(options)
84
- execution = WorkerExecution.new(worker, method_name, options)
87
+ execution = WorkerExecution.new(worker, options)
85
88
  execution.call
86
89
  ensure
87
90
  BackgroundWorker.release_connections! if BackgroundWorker.config.backgrounded
@@ -27,8 +27,8 @@ module BackgroundWorker
27
27
  @after_exception.call(e)
28
28
  end
29
29
 
30
- def foreground_enqueue(klass, method_name, opts)
31
- klass.perform_now(method_name, opts)
30
+ def foreground_enqueue(klass, opts)
31
+ klass.perform_now(opts)
32
32
  end
33
33
 
34
34
  def default_after_exception(e)
@@ -1,11 +1,10 @@
1
1
  # Generates a unique identifier for a particular job identified by class_name/method
2
2
  module BackgroundWorker
3
3
  class Uid
4
- attr_reader :class_name, :method
4
+ attr_reader :class_name
5
5
 
6
- def initialize(class_name, method)
6
+ def initialize(class_name)
7
7
  @class_name = class_name
8
- @method = method
9
8
  end
10
9
 
11
10
  def generate
@@ -15,11 +14,11 @@ module BackgroundWorker
15
14
  private
16
15
 
17
16
  def generate_uid_hash
18
- ::Digest::MD5.hexdigest("#{class_name}:#{method}:#{rand(1 << 64)}:#{Time.now}")
17
+ ::Digest::MD5.hexdigest("#{class_name}:#{rand(1 << 64)}:#{Time.now}")
19
18
  end
20
19
 
21
20
  def generate_uid_name
22
- "#{class_name.underscore}/#{method}".split('/').join(':')
21
+ "#{class_name.underscore}".split('/').join(':')
23
22
  end
24
23
  end
25
24
  end
@@ -1,3 +1,3 @@
1
1
  module BackgroundWorker
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.1'
3
3
  end
@@ -2,15 +2,14 @@ module BackgroundWorker
2
2
  class WorkerExecution
3
3
  attr_reader :worker, :method_name, :options
4
4
 
5
- def initialize(worker, method_name, options)
5
+ def initialize(worker, options)
6
6
  fail ArgumentError, "'uid' is required to identify worker" unless options[:uid].present?
7
7
  @worker = worker
8
- @method_name = method_name
9
8
  @options = options
10
9
  end
11
10
 
12
11
  def call
13
- worker.send(method_name, options)
12
+ worker.perform(options)
14
13
  report_implicitly_successful unless completed?
15
14
 
16
15
  rescue StandardError => e
@@ -8,15 +8,15 @@ module BackgroundWorker
8
8
  # eg:
9
9
  # BackgroundWorker.configure(
10
10
  # logger: Rails.logger,
11
- # enqueue_with: -> klass, method_name, opts { Resque.enqueue(klass, method_name, opts) },
11
+ # enqueue_with: -> klass, opts { Resque.enqueue(klass, opts) },
12
12
  # after_exception: -> e { Airbrake.notify(e) }
13
13
  # )
14
14
  def self.configure(options)
15
15
  @config = Config.new(options)
16
16
  end
17
17
 
18
- def self.enqueue(klass, method_name, options)
19
- config.enqueue_with.call(klass, method_name, options)
18
+ def self.enqueue(klass, options)
19
+ config.enqueue_with.call(klass, options)
20
20
  end
21
21
 
22
22
  def self.logger
data/spec/base_spec.rb CHANGED
@@ -18,7 +18,7 @@ describe BackgroundWorker::Base do
18
18
  let(:model_class) { Model = Class.new(ActiveRecord::Base) }
19
19
  let(:worker_class) {
20
20
  Class.new(BackgroundWorker::Base) do
21
- def store_in_cache(opts)
21
+ def perform(opts)
22
22
  Rails.cache.store(opts[:value])
23
23
  end
24
24
  end
@@ -32,7 +32,7 @@ describe BackgroundWorker::Base do
32
32
 
33
33
  it 'should perform action and handle transactions/connections appropriately' do
34
34
  Model.transaction do
35
- worker_class.perform_later(:store_in_cache, value: 42)
35
+ worker_class.perform_later(value: 42)
36
36
  end
37
37
  expect(cache).to have_received(:store).with(42)
38
38
  end
@@ -1,3 +1,3 @@
1
1
  require 'coverage/kit'
2
2
 
3
- Coverage::Kit.setup(minimum_coverage: 82.75)
3
+ Coverage::Kit.setup(minimum_coverage: 82.30)
data/spec/uid_spec.rb CHANGED
@@ -2,11 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe BackgroundWorker::Uid do
4
4
  let(:class_name) { 'CopyWorker' }
5
- let(:method) { 'make_copy' }
6
- let(:uid_object) { BackgroundWorker::Uid.new(class_name, method) }
5
+ let(:uid_object) { BackgroundWorker::Uid.new(class_name) }
7
6
 
8
7
  context '#generate' do
9
8
  subject(:uid) { uid_object.generate }
10
- it { is_expected.to match(/copy_worker:make_copy:[0-9a-f]{16}/) }
9
+ it { is_expected.to match(/copy_worker:[0-9a-f]{16}/) }
11
10
  end
12
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: background_worker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Noack
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-09-07 00:00:00.000000000 Z
13
+ date: 2022-09-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport