sidekiq-staged_push 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +30 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +30 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Dockerfile +7 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +134 -0
- data/LICENSE.txt +21 -0
- data/Makefile +14 -0
- data/README.md +68 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +12 -0
- data/lib/generators/sidekiq/staged_push/install_generator.rb +26 -0
- data/lib/generators/sidekiq/staged_push/templates/migration.rb.tt +8 -0
- data/lib/sidekiq/staged_push/client.rb +13 -0
- data/lib/sidekiq/staged_push/enqueuer/process_batch.rb +30 -0
- data/lib/sidekiq/staged_push/enqueuer.rb +40 -0
- data/lib/sidekiq/staged_push/staged_job.rb +11 -0
- data/lib/sidekiq/staged_push/version.rb +7 -0
- data/lib/sidekiq/staged_push/worker.rb +17 -0
- data/lib/sidekiq/staged_push.rb +25 -0
- data/sidekiq-staged_push.gemspec +42 -0
- metadata +209 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 37af89ddd13da59d4000725ed7384e4ee138ed3c431d1115f34ef5537bcef2bf
|
4
|
+
data.tar.gz: 29771d9f0af6495ebe4e55dda4b19124c7370c22a60514b091a73a79904704bd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 060bd2f9d221603333a1a9904f00ea351212a6bf4f39a2bfd967134dc77d2bc1932137bcc622ae7f01d895744aba0580186ec18bcc21254409d2a78d1ab7a8f7
|
7
|
+
data.tar.gz: 1458c6bb4d56bdc0b33bfa0ff79389fe377579bcd7353044f88f044c5903fc94c9f7db0d4fa5b55d6357d4d78ad32a4bf157c58d7d46bddd57ae3b232f1b2e59
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: Main
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [main]
|
6
|
+
pull_request:
|
7
|
+
branches: [main]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
strategy:
|
12
|
+
fail-fast: false
|
13
|
+
matrix:
|
14
|
+
ruby:
|
15
|
+
- "2.7"
|
16
|
+
- "3.0"
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
bundler-cache: true
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
- name: Run Rubocop
|
26
|
+
run: |
|
27
|
+
bundle exec rubocop
|
28
|
+
- name: Run tests
|
29
|
+
run: |
|
30
|
+
bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
NewCops: enable
|
6
|
+
TargetRubyVersion: 2.7
|
7
|
+
SuggestExtensions:
|
8
|
+
rubocop-rake: false
|
9
|
+
Exclude:
|
10
|
+
- "db/**/*"
|
11
|
+
- "vendor/**/*"
|
12
|
+
|
13
|
+
Style/StringLiterals:
|
14
|
+
EnforcedStyle: double_quotes
|
15
|
+
Style/Documentation:
|
16
|
+
Enabled: false
|
17
|
+
Bundler/OrderedGems:
|
18
|
+
Enabled: false
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Max: 20
|
21
|
+
RSpec/MessageChain:
|
22
|
+
Enabled: false
|
23
|
+
RSpec/ExampleLength:
|
24
|
+
Max: 50
|
25
|
+
RSpec/MultipleExpectations:
|
26
|
+
Enabled: false
|
27
|
+
Metrics/BlockLength:
|
28
|
+
Exclude:
|
29
|
+
- "spec/**/*"
|
30
|
+
- "*.gemspec"
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at adamsunday@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Dockerfile
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sidekiq-staged_push (0.1.0)
|
5
|
+
activerecord (>= 5.2.0)
|
6
|
+
sidekiq (>= 6.3.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionpack (7.0.0)
|
12
|
+
actionview (= 7.0.0)
|
13
|
+
activesupport (= 7.0.0)
|
14
|
+
rack (~> 2.0, >= 2.2.0)
|
15
|
+
rack-test (>= 0.6.3)
|
16
|
+
rails-dom-testing (~> 2.0)
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
18
|
+
actionview (7.0.0)
|
19
|
+
activesupport (= 7.0.0)
|
20
|
+
builder (~> 3.1)
|
21
|
+
erubi (~> 1.4)
|
22
|
+
rails-dom-testing (~> 2.0)
|
23
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
24
|
+
activemodel (7.0.0)
|
25
|
+
activesupport (= 7.0.0)
|
26
|
+
activerecord (7.0.0)
|
27
|
+
activemodel (= 7.0.0)
|
28
|
+
activesupport (= 7.0.0)
|
29
|
+
activesupport (7.0.0)
|
30
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
31
|
+
i18n (>= 1.6, < 2)
|
32
|
+
minitest (>= 5.1)
|
33
|
+
tzinfo (~> 2.0)
|
34
|
+
ast (2.4.2)
|
35
|
+
builder (3.2.4)
|
36
|
+
concurrent-ruby (1.1.9)
|
37
|
+
connection_pool (2.2.5)
|
38
|
+
crass (1.0.6)
|
39
|
+
database_cleaner-active_record (2.0.1)
|
40
|
+
activerecord (>= 5.a)
|
41
|
+
database_cleaner-core (~> 2.0.0)
|
42
|
+
database_cleaner-core (2.0.1)
|
43
|
+
diff-lcs (1.5.0)
|
44
|
+
erubi (1.10.0)
|
45
|
+
i18n (1.8.11)
|
46
|
+
concurrent-ruby (~> 1.0)
|
47
|
+
loofah (2.13.0)
|
48
|
+
crass (~> 1.0.2)
|
49
|
+
nokogiri (>= 1.5.9)
|
50
|
+
method_source (1.0.0)
|
51
|
+
minitest (5.15.0)
|
52
|
+
nokogiri (1.12.5-x86_64-darwin)
|
53
|
+
racc (~> 1.4)
|
54
|
+
nokogiri (1.12.5-x86_64-linux)
|
55
|
+
racc (~> 1.4)
|
56
|
+
parallel (1.21.0)
|
57
|
+
parser (3.0.3.2)
|
58
|
+
ast (~> 2.4.1)
|
59
|
+
racc (1.6.0)
|
60
|
+
rack (2.2.3)
|
61
|
+
rack-test (1.1.0)
|
62
|
+
rack (>= 1.0, < 3)
|
63
|
+
rails-dom-testing (2.0.3)
|
64
|
+
activesupport (>= 4.2.0)
|
65
|
+
nokogiri (>= 1.6)
|
66
|
+
rails-html-sanitizer (1.4.2)
|
67
|
+
loofah (~> 2.3)
|
68
|
+
railties (7.0.0)
|
69
|
+
actionpack (= 7.0.0)
|
70
|
+
activesupport (= 7.0.0)
|
71
|
+
method_source
|
72
|
+
rake (>= 12.2)
|
73
|
+
thor (~> 1.0)
|
74
|
+
zeitwerk (~> 2.5)
|
75
|
+
rainbow (3.0.0)
|
76
|
+
rake (13.0.6)
|
77
|
+
redis (4.5.1)
|
78
|
+
regexp_parser (2.2.0)
|
79
|
+
rexml (3.2.5)
|
80
|
+
rspec (3.10.0)
|
81
|
+
rspec-core (~> 3.10.0)
|
82
|
+
rspec-expectations (~> 3.10.0)
|
83
|
+
rspec-mocks (~> 3.10.0)
|
84
|
+
rspec-core (3.10.1)
|
85
|
+
rspec-support (~> 3.10.0)
|
86
|
+
rspec-expectations (3.10.1)
|
87
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
88
|
+
rspec-support (~> 3.10.0)
|
89
|
+
rspec-mocks (3.10.2)
|
90
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
91
|
+
rspec-support (~> 3.10.0)
|
92
|
+
rspec-support (3.10.3)
|
93
|
+
rubocop (1.24.0)
|
94
|
+
parallel (~> 1.10)
|
95
|
+
parser (>= 3.0.0.0)
|
96
|
+
rainbow (>= 2.2.2, < 4.0)
|
97
|
+
regexp_parser (>= 1.8, < 3.0)
|
98
|
+
rexml
|
99
|
+
rubocop-ast (>= 1.15.0, < 2.0)
|
100
|
+
ruby-progressbar (~> 1.7)
|
101
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
102
|
+
rubocop-ast (1.15.0)
|
103
|
+
parser (>= 3.0.1.1)
|
104
|
+
rubocop-rspec (2.7.0)
|
105
|
+
rubocop (~> 1.19)
|
106
|
+
ruby-progressbar (1.11.0)
|
107
|
+
sidekiq (6.3.1)
|
108
|
+
connection_pool (>= 2.2.2)
|
109
|
+
rack (~> 2.0)
|
110
|
+
redis (>= 4.2.0)
|
111
|
+
sqlite3 (1.4.2)
|
112
|
+
thor (1.1.0)
|
113
|
+
tzinfo (2.0.4)
|
114
|
+
concurrent-ruby (~> 1.0)
|
115
|
+
unicode-display_width (2.1.0)
|
116
|
+
zeitwerk (2.5.2)
|
117
|
+
|
118
|
+
PLATFORMS
|
119
|
+
x86_64-darwin-20
|
120
|
+
x86_64-linux
|
121
|
+
|
122
|
+
DEPENDENCIES
|
123
|
+
bundler
|
124
|
+
database_cleaner-active_record
|
125
|
+
railties
|
126
|
+
rake
|
127
|
+
rspec
|
128
|
+
rubocop
|
129
|
+
rubocop-rspec
|
130
|
+
sidekiq-staged_push!
|
131
|
+
sqlite3
|
132
|
+
|
133
|
+
BUNDLED WITH
|
134
|
+
2.2.32
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Adam Niedzielski
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Makefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
build:
|
2
|
+
docker-compose build
|
3
|
+
|
4
|
+
bundle:
|
5
|
+
docker-compose run --rm library bundle install
|
6
|
+
|
7
|
+
test:
|
8
|
+
docker-compose run --rm library bundle exec rake
|
9
|
+
|
10
|
+
rubocop:
|
11
|
+
docker-compose run --rm library bundle exec rubocop
|
12
|
+
|
13
|
+
bash:
|
14
|
+
docker-compose run --rm library bash
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# `sidekiq-staged_push`
|
2
|
+
|
3
|
+
`sidekiq-staged_push` is an extension to [Sidekiq](http://github.com/mperham/sidekiq) that
|
4
|
+
implements a strategy of pushing jobs to Redis that involves an intermediary database table.
|
5
|
+
It is developed based on the approach described in [Transactionally Staged Job Drains in Postgres](https://brandur.org/job-drain). Quoting the author:
|
6
|
+
|
7
|
+
> With this pattern, jobs aren’t immediately sent to the job queue. Instead, they’re staged in
|
8
|
+
> a table within the relational database itself, and the ACID properties of the running
|
9
|
+
> transaction keep them invisible until they’re ready to be worked. A secondary enqueuer
|
10
|
+
> process reads the table and sends any jobs it finds to the job queue before removing their
|
11
|
+
> rows.
|
12
|
+
|
13
|
+
This allows you to leverage the power of Sidekiq while still treating your jobs as if they
|
14
|
+
were stored in the database for the purpose of transactions.
|
15
|
+
[See the demo app](https://github.com/adamniedzielski/sidekiq-staged_push-demo).
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'sidekiq-staged_push'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
In `config/initializers/sidekiq.rb`:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Sidekiq::StagedPush.enable!
|
33
|
+
```
|
34
|
+
|
35
|
+
## Gotchas
|
36
|
+
|
37
|
+
1. The gem currently assumes that you're running only one Sidekiq process or using Sidekiq
|
38
|
+
Enterprise. Jobs may be processed multiple times if this is not true.
|
39
|
+
2. `SomeWorker.perform_bulk([[1], [2], [3]])` is inconsistent with other methods, because it
|
40
|
+
schedules to Redis immediately.
|
41
|
+
|
42
|
+
## Development
|
43
|
+
|
44
|
+
You need Docker with Docker Compose.
|
45
|
+
|
46
|
+
```
|
47
|
+
make build
|
48
|
+
make bundle
|
49
|
+
```
|
50
|
+
|
51
|
+
Then you can run:
|
52
|
+
|
53
|
+
```
|
54
|
+
make test
|
55
|
+
make rubocop
|
56
|
+
```
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/adamniedzielski/sidekiq-staged_push. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
65
|
+
|
66
|
+
## Code of Conduct
|
67
|
+
|
68
|
+
Everyone interacting in the `sidekiq-staged_push` project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/adamniedzielski/sidekiq-staged_push/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "sidekiq/staged_push"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/docker-compose.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators/active_record"
|
4
|
+
|
5
|
+
module Sidekiq
|
6
|
+
module StagedPush
|
7
|
+
module Generators
|
8
|
+
class InstallGenerator < ::Rails::Generators::Base
|
9
|
+
include ActiveRecord::Generators::Migration
|
10
|
+
source_root File.join(__dir__, "templates")
|
11
|
+
|
12
|
+
def copy_migration
|
13
|
+
migration_template(
|
14
|
+
"migration.rb",
|
15
|
+
"db/migrate/install_sidekiq_staged_push.rb",
|
16
|
+
migration_version: migration_version
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def migration_version
|
21
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sidekiq/staged_push/staged_job"
|
4
|
+
require "sidekiq/client"
|
5
|
+
|
6
|
+
module Sidekiq
|
7
|
+
module StagedPush
|
8
|
+
class Enqueuer
|
9
|
+
class ProcessBatch
|
10
|
+
BATCH_SIZE = 500
|
11
|
+
|
12
|
+
def call
|
13
|
+
StagedJob.transaction do
|
14
|
+
jobs = StagedJob.order(:id).limit(BATCH_SIZE).to_a
|
15
|
+
|
16
|
+
if jobs.present?
|
17
|
+
client = Sidekiq::Client.new
|
18
|
+
jobs.each do |job|
|
19
|
+
client.push(job.payload)
|
20
|
+
end
|
21
|
+
StagedJob.where(id: jobs.map(&:id)).delete_all
|
22
|
+
end
|
23
|
+
|
24
|
+
jobs.size
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sidekiq/staged_push/enqueuer/process_batch"
|
4
|
+
|
5
|
+
module Sidekiq
|
6
|
+
module StagedPush
|
7
|
+
class Enqueuer
|
8
|
+
def initialize
|
9
|
+
@done = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def start
|
13
|
+
@thread = Thread.new(&method(:process))
|
14
|
+
end
|
15
|
+
|
16
|
+
def stop
|
17
|
+
@done = true
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def process
|
23
|
+
until @done
|
24
|
+
if primary_process?
|
25
|
+
jobs_processed = ProcessBatch.new.call
|
26
|
+
sleep 0.2 if jobs_processed.zero?
|
27
|
+
else
|
28
|
+
sleep 30
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def primary_process?
|
34
|
+
return true unless defined?(Sidekiq::Enterprise)
|
35
|
+
|
36
|
+
Sidekiq::Senate.leader?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sidekiq/staged_push/client"
|
4
|
+
|
5
|
+
module Sidekiq
|
6
|
+
module StagedPush
|
7
|
+
module Worker
|
8
|
+
module ClassMethods
|
9
|
+
def client_push(item)
|
10
|
+
stringified_item = item.transform_keys(&:to_s)
|
11
|
+
|
12
|
+
Sidekiq::StagedPush::Client.new.push(stringified_item)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sidekiq"
|
4
|
+
require "sidekiq/worker"
|
5
|
+
require "sidekiq/staged_push/enqueuer"
|
6
|
+
require "sidekiq/staged_push/worker"
|
7
|
+
require "sidekiq/staged_push/version"
|
8
|
+
|
9
|
+
module Sidekiq
|
10
|
+
module StagedPush
|
11
|
+
def self.enable!
|
12
|
+
Sidekiq::Worker::ClassMethods.prepend Sidekiq::StagedPush::Worker::ClassMethods
|
13
|
+
|
14
|
+
enqueuer = Enqueuer.new
|
15
|
+
Sidekiq.configure_server do |config|
|
16
|
+
config.on(:startup) do
|
17
|
+
enqueuer.start
|
18
|
+
end
|
19
|
+
config.on(:quiet) do
|
20
|
+
enqueuer.stop
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "sidekiq/staged_push/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "sidekiq-staged_push"
|
9
|
+
spec.version = Sidekiq::StagedPush::VERSION
|
10
|
+
spec.authors = ["Adam Niedzielski"]
|
11
|
+
spec.email = ["adamsunday@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = "Transactional job push for Sidekiq with jobs staged in the database"
|
14
|
+
spec.homepage = "https://github.com/adamniedzielski/sidekiq-staged_push"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.metadata = {
|
27
|
+
"rubygems_mfa_required" => "true"
|
28
|
+
}
|
29
|
+
|
30
|
+
spec.required_ruby_version = ">= 2.7.5"
|
31
|
+
|
32
|
+
spec.add_dependency "activerecord", ">= 5.2.0"
|
33
|
+
spec.add_dependency "sidekiq", ">= 6.3.1"
|
34
|
+
spec.add_development_dependency "bundler"
|
35
|
+
spec.add_development_dependency "database_cleaner-active_record"
|
36
|
+
spec.add_development_dependency "railties"
|
37
|
+
spec.add_development_dependency "rake"
|
38
|
+
spec.add_development_dependency "rspec"
|
39
|
+
spec.add_development_dependency "rubocop"
|
40
|
+
spec.add_development_dependency "rubocop-rspec"
|
41
|
+
spec.add_development_dependency "sqlite3"
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-staged_push
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Niedzielski
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sidekiq
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 6.3.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 6.3.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: database_cleaner-active_record
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: railties
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: sqlite3
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description:
|
154
|
+
email:
|
155
|
+
- adamsunday@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".github/workflows/main.yml"
|
161
|
+
- ".gitignore"
|
162
|
+
- ".rspec"
|
163
|
+
- ".rubocop.yml"
|
164
|
+
- CODE_OF_CONDUCT.md
|
165
|
+
- Dockerfile
|
166
|
+
- Gemfile
|
167
|
+
- Gemfile.lock
|
168
|
+
- LICENSE.txt
|
169
|
+
- Makefile
|
170
|
+
- README.md
|
171
|
+
- Rakefile
|
172
|
+
- bin/console
|
173
|
+
- bin/setup
|
174
|
+
- docker-compose.yml
|
175
|
+
- lib/generators/sidekiq/staged_push/install_generator.rb
|
176
|
+
- lib/generators/sidekiq/staged_push/templates/migration.rb.tt
|
177
|
+
- lib/sidekiq/staged_push.rb
|
178
|
+
- lib/sidekiq/staged_push/client.rb
|
179
|
+
- lib/sidekiq/staged_push/enqueuer.rb
|
180
|
+
- lib/sidekiq/staged_push/enqueuer/process_batch.rb
|
181
|
+
- lib/sidekiq/staged_push/staged_job.rb
|
182
|
+
- lib/sidekiq/staged_push/version.rb
|
183
|
+
- lib/sidekiq/staged_push/worker.rb
|
184
|
+
- sidekiq-staged_push.gemspec
|
185
|
+
homepage: https://github.com/adamniedzielski/sidekiq-staged_push
|
186
|
+
licenses:
|
187
|
+
- MIT
|
188
|
+
metadata:
|
189
|
+
rubygems_mfa_required: 'true'
|
190
|
+
post_install_message:
|
191
|
+
rdoc_options: []
|
192
|
+
require_paths:
|
193
|
+
- lib
|
194
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: 2.7.5
|
199
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - ">="
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
requirements: []
|
205
|
+
rubygems_version: 3.3.4
|
206
|
+
signing_key:
|
207
|
+
specification_version: 4
|
208
|
+
summary: Transactional job push for Sidekiq with jobs staged in the database
|
209
|
+
test_files: []
|