background_worker 0.3.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92739c3cd6034d467914e25cacf4a240e38c046b6e388cec4f9af9679b97d9a6
4
- data.tar.gz: 89f898f9989bcf29e5db58bf9bd23f189aa9e87702d145309c072a3a501ff2a1
3
+ metadata.gz: 21cc4f8353107acd3a07a1dbb33709a5f5629e266c64ec66eee2a558d61e6614
4
+ data.tar.gz: 9499f710d1e056be82da09af4c28a8229ac43e6aada29725a1d766f4638fc136
5
5
  SHA512:
6
- metadata.gz: ce83fb384503d92765da69f1daec6f11eeff92fc8c9792ed5e4a8e770aa67224e0fd63ad7783d02b692ba38c75b7623785e2df22457ab58b5ae5fa8d4ca3b78b
7
- data.tar.gz: '091732c22801dc033d91957cba5a3d4a84776414ca4f09d5f09dd02205b8c54ef243d462f7e2092e3249554c4f58e6ff00996efaa1c6bf1a50794737fa5a00e0'
6
+ metadata.gz: f869b9563b92e17c75632b3de27946ac87939033c068c093e3060b8f062bb26abab31a3559def9fe06a6291016a9c26e764c25a6c96fe7f789e886e934aec709
7
+ data.tar.gz: fc67495315f925f92ff8e00fe4c8e3babffd1b9c6e608ae274cfa26e72364fa83ea76ea1903b636e979ef9100dd26edd8422a3b64149e6ff726bdc6c0c87a503
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_PATH: "vendor"
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "bundler"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "daily"
@@ -0,0 +1,59 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ build:
10
+ name: Build
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v2
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ bundler-cache: true
18
+ - run: bundle exec rake
19
+
20
+ release:
21
+ needs: build
22
+ name: Release
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - name: Checkout
26
+ uses: actions/checkout@v2
27
+
28
+ - name: Generate Changelog
29
+ run: |
30
+ # Get version from github ref (remove 'refs/tags/' and prefix 'v')
31
+ version="${GITHUB_REF#refs/tags/v}"
32
+ npx changelog-parser CHANGELOG.md | jq -cr ".versions | .[] | select(.version == \"$version\") | .body" > ${{ github.workflow }}-CHANGELOG.txt
33
+
34
+ - name: Release
35
+ uses: softprops/action-gh-release@v1
36
+ with:
37
+ body_path: ${{ github.workflow }}-CHANGELOG.txt
38
+ env:
39
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40
+
41
+ publish:
42
+ needs: [build, release]
43
+ name: Publish
44
+ runs-on: ubuntu-latest
45
+
46
+ steps:
47
+ - uses: actions/checkout@v2
48
+ - uses: ruby/setup-ruby@v1
49
+
50
+ - name: Publish to RubyGems
51
+ run: |
52
+ mkdir -p $HOME/.gem
53
+ touch $HOME/.gem/credentials
54
+ chmod 0600 $HOME/.gem/credentials
55
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
56
+ gem build *.gemspec
57
+ gem push *.gem
58
+ env:
59
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -0,0 +1,24 @@
1
+ name: Build and Test
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ gemfile: [rails60, rails61, rails70]
9
+ ruby: ["2.7", "3.0", "3.1"]
10
+ runs-on: ubuntu-latest
11
+ env:
12
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ bundler-cache: true
19
+ - run: bundle exec rake
20
+ - name: Coveralls
21
+ uses: coverallsapp/github-action@master
22
+ with:
23
+ github-token: ${{ secrets.GITHUB_TOKEN }}
24
+ path-to-lcov: coverage/lcov.info
data/.gitignore CHANGED
@@ -1,2 +1,4 @@
1
1
  Gemfile.lock
2
2
  coverage
3
+ vendor
4
+ tmp
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.5
1
+ 3.1.0
data/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@ 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.6.0
7
+
8
+ - [PLAT-664] Align interface to ActiveJob
9
+
10
+ ## 0.5.0
11
+
12
+ - [PLAT-183] Ruby 3.1, Rails 7.0 and push coverage with github action
13
+
14
+ ## 0.4.0
15
+
16
+ - [TT-8623] Update to build with github actions / ruby 3.0 / rails 6.1
17
+
6
18
  ## 0.3.0
7
19
 
8
20
  - [TT-6292] Support Rails 5.2 built-in redis cache, remove legacy supports
data/README.md CHANGED
@@ -1,10 +1,14 @@
1
- Background Worker
2
- =================
1
+ # Background Worker
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/background_worker.svg)](http://badge.fury.io/rb/background_worker)
4
+ [![Build Status](https://github.com/sealink/background_worker/workflows/Build%20and%20Test/badge.svg?branch=master)](https://github.com/sealink/background_worker/actions)
5
+ [![Coverage Status](https://coveralls.io/repos/sealink/background_worker/badge.png)](https://coveralls.io/r/sealink/background_worker)
3
6
 
4
7
  Provides a worker abstraction with an additional status channel.
5
8
 
6
9
  Start by making a worker class which extends from BackgroundWorker::Base
7
10
 
11
+ ```ruby
8
12
  class MyWorker < BackgroundWorker::Base
9
13
  def my_task(options={})
10
14
  report_progress('Starting')
@@ -17,22 +21,27 @@ Start by making a worker class which extends from BackgroundWorker::Base
17
21
  {original_message: message}
18
22
  end
19
23
  end
24
+ ```
20
25
 
21
26
  Then, when you want to perform a task in the background, use
22
27
  klass#perform_in_background which exists in Base:
23
28
 
29
+ ```ruby
24
30
  worker_id = MyWorker.perform_in_background(:my_task, message: "hello!")
31
+ ```
25
32
 
26
33
  # Backgrounded
27
34
 
28
35
  By default this will call your instance method in the foreground -- you have to
29
36
  provide an #enqueue_with configuration like so:
30
37
 
38
+ ```ruby
31
39
  BackgroundWorker.configure(
32
40
  enqueue_with: -> klass, method_name, options {
33
41
  Resque.enqueue(klass, method_name, options)
34
42
  }
35
43
  )
44
+ ```
36
45
 
37
46
  This is independent of the status reporting which (currently) always uses Redis.
38
47
 
@@ -41,23 +50,40 @@ This is independent of the status reporting which (currently) always uses Redis.
41
50
  The worker_id you are returned can be used to get the status and
42
51
  whether the worker has finished successfully, failed, or is still in progress:
43
52
 
53
+ ```ruby
44
54
  state = BackgroundWorker.get_state_of(worker_id)
55
+ ```
45
56
 
46
57
  The state is represented by a hash with the following keys:
47
58
 
48
- message: Reported message
49
- detailed_message: Detailed version of above when provided
50
- status: :successful, :failed, or null if still processing
51
- completed: True if report_failed, report_successful called (or worker
52
- finished without exception -- which calls report_successful)
53
- data: Arbitrary data returned by worker method on success or report_failed
59
+ | key | description |
60
+ | ------------------------------------------------------------ | -------------------------------------------------------------------- |
61
+ | message | Reported message |
62
+ | detailed_message | Detailed version of above when provided |
63
+ | status | :successful, :failed, or null if still processing |
64
+ | completed | True if report_failed, report_successful called (or worker |
65
+ | finished without exception -- which calls report_successful) |
66
+ | data | Arbitrary data returned by worker method on success or report_failed |
54
67
 
55
68
  If an exception is raised, the worker will call #report_failed with the
56
69
  details. You can provide a callback with #after_exception in the config.
57
70
 
58
- # INSTALLATION
71
+ # Installation
59
72
 
60
73
  Add to your Gemfile:
61
74
 
75
+ ```ruby
62
76
  gem 'background_worker'
77
+ ```
78
+
79
+ # Release
80
+
81
+ To publish a new version of this gem the following steps must be taken.
63
82
 
83
+ - Update the version in the following files
84
+ ```
85
+ CHANGELOG.md
86
+ lib/background_worker/version.rb
87
+ ```
88
+ - Create a tag using the format v0.1.0
89
+ - Follow build progress in GitHub actions
@@ -19,14 +19,13 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
20
20
  spec.test_files = spec.files.grep(/^(test|spec|features)\//)
21
21
  spec.require_paths = ['lib']
22
+ spec.required_ruby_version = '>= 2.7'
22
23
 
23
24
  spec.add_development_dependency 'activesupport'
24
25
  spec.add_development_dependency 'bundler'
25
26
  spec.add_development_dependency 'rake'
26
27
  spec.add_development_dependency 'rspec'
27
28
  spec.add_development_dependency 'coverage-kit'
28
- spec.add_development_dependency 'coveralls'
29
- spec.add_development_dependency 'simplecov-rcov'
30
29
  spec.add_development_dependency 'rubocop'
31
30
 
32
31
  spec.add_development_dependency 'activerecord'
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gemspec path: '../'
5
+
6
+ group :development, :test do
7
+ gem 'activerecord', '~> 6.0'
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gemspec path: '../'
5
+
6
+ group :development, :test do
7
+ gem 'activerecord', '~> 6.1'
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gemspec path: '../'
5
+
6
+ group :development, :test do
7
+ gem 'activerecord', '~> 7.0'
8
+ end
@@ -58,7 +58,7 @@ module BackgroundWorker
58
58
  end
59
59
 
60
60
  # Public method to do in background...
61
- def perform_in_background(method_name, options = {})
61
+ def perform_later(method_name, options = {})
62
62
  opts = options.symbolize_keys
63
63
 
64
64
  method_name = method_name.to_sym
@@ -76,7 +76,7 @@ module BackgroundWorker
76
76
  # This method is called by the job runner
77
77
  #
78
78
  # It will just call your preferred method in the worker.
79
- def perform(method_name, options = {})
79
+ def perform_now(method_name, options = {})
80
80
  BackgroundWorker.verify_active_connections! if BackgroundWorker.config.backgrounded
81
81
 
82
82
  worker = new(options)
@@ -28,7 +28,7 @@ module BackgroundWorker
28
28
  end
29
29
 
30
30
  def foreground_enqueue(klass, method_name, opts)
31
- klass.perform(method_name, opts)
31
+ klass.perform_now(method_name, opts)
32
32
  end
33
33
 
34
34
  def default_after_exception(e)
@@ -1,3 +1,3 @@
1
1
  module BackgroundWorker
2
- VERSION = '0.3.0'
2
+ VERSION = '0.6.0'
3
3
  end
data/spec/base_spec.rb CHANGED
@@ -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_in_background(:store_in_cache, value: 42)
35
+ worker_class.perform_later(:store_in_cache, value: 42)
36
36
  end
37
37
  expect(cache).to have_received(:store).with(42)
38
38
  end
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  require 'rubygems'
9
9
  require 'bundler/setup'
10
+ require 'active_support'
10
11
  require 'active_support/core_ext/string/inflections' #underscore
11
12
 
12
13
  require 'support/coverage_loader'
@@ -1,4 +1,3 @@
1
- require 'simplecov-rcov'
2
- require 'coveralls'
3
1
  require 'coverage/kit'
2
+
4
3
  Coverage::Kit.setup(minimum_coverage: 82.75)
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.3.0
4
+ version: 0.6.0
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: 2019-11-20 00:00:00.000000000 Z
13
+ date: 2022-09-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -82,34 +82,6 @@ dependencies:
82
82
  - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
- - !ruby/object:Gem::Dependency
86
- name: coveralls
87
- requirement: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: '0'
92
- type: :development
93
- prerelease: false
94
- version_requirements: !ruby/object:Gem::Requirement
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
- - !ruby/object:Gem::Dependency
100
- name: simplecov-rcov
101
- requirement: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: '0'
106
- type: :development
107
- prerelease: false
108
- version_requirements: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: '0'
113
85
  - !ruby/object:Gem::Dependency
114
86
  name: rubocop
115
87
  requirement: !ruby/object:Gem::Requirement
@@ -161,17 +133,22 @@ executables: []
161
133
  extensions: []
162
134
  extra_rdoc_files: []
163
135
  files:
136
+ - ".bundle/config"
137
+ - ".github/dependabot.yml"
138
+ - ".github/workflows/release.yml"
139
+ - ".github/workflows/ruby.yml"
164
140
  - ".gitignore"
165
141
  - ".rubocop.yml"
166
142
  - ".ruby-version"
167
- - ".travis.yml"
168
143
  - CHANGELOG.md
169
144
  - Gemfile
170
145
  - LICENSE.txt
171
146
  - README.md
172
147
  - Rakefile
173
148
  - background_worker.gemspec
174
- - gemfiles/rails5_2.gemfile
149
+ - gemfiles/rails60.gemfile
150
+ - gemfiles/rails61.gemfile
151
+ - gemfiles/rails70.gemfile
175
152
  - lib/background_worker.rb
176
153
  - lib/background_worker/base.rb
177
154
  - lib/background_worker/config.rb
@@ -196,14 +173,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
173
  requirements:
197
174
  - - ">="
198
175
  - !ruby/object:Gem::Version
199
- version: '0'
176
+ version: '2.7'
200
177
  required_rubygems_version: !ruby/object:Gem::Requirement
201
178
  requirements:
202
179
  - - ">="
203
180
  - !ruby/object:Gem::Version
204
181
  version: '0'
205
182
  requirements: []
206
- rubygems_version: 3.0.3
183
+ rubygems_version: 3.3.3
207
184
  signing_key:
208
185
  specification_version: 4
209
186
  summary: Background worker abstraction with status updates
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.6.5
4
- script: bundle exec rake spec
5
- gemfile:
6
- - gemfiles/rails5_2.gemfile
7
- notifications:
8
- email:
9
- - support@travellink.com.au
10
- sudo: false
11
- cache: bundler
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec :path => '../'
3
-
4
- group :development, :test do
5
- gem 'activerecord', '~> 5.2.0'
6
- end