Skip to content

Commit

Permalink
Add ruby_event_store-sidekiq_scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
swistak35 committed Jan 23, 2021
1 parent 20d6344 commit b845636
Show file tree
Hide file tree
Showing 15 changed files with 497 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/ruby_event_store-sidekiq_scheduler.yml
@@ -0,0 +1,74 @@
name: ruby_event_store-sidekiq_scheduler
on:
schedule:
- cron: "0 17 * * *"
push:
paths:
- "contrib/ruby_event_store-sidekiq_scheduler/**"
- ".github/workflows/ruby_event_store-sidekiq_scheduler.yml"
- "support/**"
pull_request:
types: [opened, reopened]
paths:
- "contrib/ruby_event_store-sidekiq_scheduler/**"
- ".github/workflows/ruby_event_store-sidekiq_scheduler.yml"
- "support/**"
jobs:
test:
runs-on: ${{ matrix.os }}
env:
WORKING_DIRECTORY: contrib/ruby_event_store-sidekiq_scheduler
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
strategy:
fail-fast: false
matrix:
include:
- ruby: ruby-2.7
gemfile: Gemfile
os: ubuntu-20.04
- ruby: ruby-2.7
gemfile: Gemfile.sidekiq_5
os: ubuntu-20.04
- ruby: ruby-2.6
gemfile: Gemfile
os: ubuntu-20.04
- ruby: ruby-2.5
gemfile: Gemfile
os: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- run: test -e ${{ matrix.gemfile }}.lock
working-directory: ${{ env.WORKING_DIRECTORY }}
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
working-directory: ${{ env.WORKING_DIRECTORY }}
- run: make test
working-directory: ${{ env.WORKING_DIRECTORY }}

mutate:
runs-on: ${{ matrix.os }}
env:
WORKING_DIRECTORY: contrib/ruby_event_store-sidekiq_scheduler
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
strategy:
fail-fast: false
matrix:
include:
- ruby: ruby-2.7
gemfile: Gemfile
os: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- run: test -e ${{ matrix.gemfile }}.lock
working-directory: ${{ env.WORKING_DIRECTORY }}
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
working-directory: ${{ env.WORKING_DIRECTORY }}
- run: make mutate-changes
working-directory: ${{ env.WORKING_DIRECTORY }}
41 changes: 41 additions & 0 deletions .github/workflows/ruby_event_store-sidekiq_scheduler_coverage.yml
@@ -0,0 +1,41 @@
name: ruby_event_store-sidekiq_scheduler_coverage
on:
schedule:
- cron: "0 17 * * *"
workflow_dispatch:
push:
paths:
- "contrib/ruby_event_store-sidekiq_scheduler/**"
- ".github/workflows/ruby_event_store-sidekiq_scheduler.yml"
- "support/**"
pull_request:
types: [ opened, reopened ]
paths:
- "contrib/ruby_event_store-sidekiq_scheduler/**"
- ".github/workflows/ruby_event_store-sidekiq_scheduler.yml"
- "support/**"
jobs:
coverage:
runs-on: ${{ matrix.os }}
timeout-minutes: 120
env:
WORKING_DIRECTORY: contrib/ruby_event_store-sidekiq_scheduler
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
strategy:
fail-fast: false
matrix:
include:
- ruby: ruby-2.7
gemfile: Gemfile
os: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- run: test -e ${{ matrix.gemfile }}.lock
working-directory: ${{ env.WORKING_DIRECTORY }}
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
working-directory: ${{ env.WORKING_DIRECTORY }}
- run: make mutate
working-directory: ${{ env.WORKING_DIRECTORY }}
14 changes: 14 additions & 0 deletions contrib/ruby_event_store-sidekiq_scheduler/.mutant.yml
@@ -0,0 +1,14 @@
# https://github.com/mbj/mutant/blob/master/docs/configuration.md

requires:
- ruby_event_store/sidekiq_scheduler
includes:
- lib
integration: rspec
mutation_timeout: 10.0
coverage_criteria:
timeout: true
process_abort: true
matcher:
subjects:
- RubyEventStore::SidekiqScheduler*
7 changes: 7 additions & 0 deletions contrib/ruby_event_store-sidekiq_scheduler/Gemfile
@@ -0,0 +1,7 @@
source 'https://rubygems.org'
gemspec

eval_gemfile '../../support/bundler/Gemfile.shared'

gem 'sidekiq', '~> 6.0'
gem 'ruby_event_store', path: '../../ruby_event_store'
76 changes: 76 additions & 0 deletions contrib/ruby_event_store-sidekiq_scheduler/Gemfile.lock
@@ -0,0 +1,76 @@
PATH
remote: ../../ruby_event_store
specs:
ruby_event_store (2.1.0)
concurrent-ruby (~> 1.0, >= 1.1.6)

PATH
remote: .
specs:
ruby_event_store-sidekiq_scheduler (0.1.0)
ruby_event_store (>= 2.0.0, < 3.0.0)

GEM
remote: https://rubygems.org/
remote: https://oss:7AXfeZdAfCqL1PvHm2nvDJO6Zd9UW8IK@gem.mutant.dev/
specs:
ast (2.4.1)
concurrent-ruby (1.1.7)
connection_pool (2.2.3)
diff-lcs (1.4.4)
minitest (5.14.2)
mutant (0.10.26)
diff-lcs (~> 1.3)
parser (~> 3.0.0)
regexp_parser (~> 2.0, >= 2.0.3)
unparser (~> 0.6.0)
mutant-license (0.1.1.2.1627430819213747598431630701693729869473.0)
mutant-minitest (0.10.26)
minitest (~> 5.11)
mutant (= 0.10.26)
mutant-rspec (0.10.26)
mutant (= 0.10.26)
rspec-core (>= 3.8.0, < 4.0.0)
parser (3.0.0.0)
ast (~> 2.4.1)
rack (2.2.3)
rake (13.0.3)
redis (4.2.5)
regexp_parser (2.0.3)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.1)
sidekiq (6.1.3)
connection_pool (>= 2.2.2)
rack (~> 2.0)
redis (>= 4.2.0)
unparser (0.6.0)
diff-lcs (~> 1.3)
parser (>= 3.0.0)

PLATFORMS
ruby

DEPENDENCIES
mutant (~> 0.10.26)
mutant-license!
mutant-minitest (~> 0.10.26)
mutant-rspec (~> 0.10.26)
rake (>= 10.0)
rspec (~> 3.6)
ruby_event_store!
ruby_event_store-sidekiq_scheduler!
sidekiq (~> 6.0)

BUNDLED WITH
2.2.6
7 changes: 7 additions & 0 deletions contrib/ruby_event_store-sidekiq_scheduler/Gemfile.sidekiq_5
@@ -0,0 +1,7 @@
source 'https://rubygems.org'
gemspec

eval_gemfile '../../support/bundler/Gemfile.shared'

gem 'sidekiq', '~> 5.0'
gem 'ruby_event_store', path: '../../ruby_event_store'
79 changes: 79 additions & 0 deletions contrib/ruby_event_store-sidekiq_scheduler/Gemfile.sidekiq_5.lock
@@ -0,0 +1,79 @@
PATH
remote: ../../ruby_event_store
specs:
ruby_event_store (2.1.0)
concurrent-ruby (~> 1.0, >= 1.1.6)

PATH
remote: .
specs:
ruby_event_store-sidekiq_scheduler (0.1.0)
ruby_event_store (>= 2.0.0, < 3.0.0)

GEM
remote: https://rubygems.org/
remote: https://oss:7AXfeZdAfCqL1PvHm2nvDJO6Zd9UW8IK@gem.mutant.dev/
specs:
ast (2.4.1)
concurrent-ruby (1.1.8)
connection_pool (2.2.3)
diff-lcs (1.4.4)
minitest (5.14.3)
mutant (0.10.26)
diff-lcs (~> 1.3)
parser (~> 3.0.0)
regexp_parser (~> 2.0, >= 2.0.3)
unparser (~> 0.6.0)
mutant-license (0.1.1.2.1627430819213747598431630701693729869473.0)
mutant-minitest (0.10.26)
minitest (~> 5.11)
mutant (= 0.10.26)
mutant-rspec (0.10.26)
mutant (= 0.10.26)
rspec-core (>= 3.8.0, < 4.0.0)
parser (3.0.0.0)
ast (~> 2.4.1)
rack (2.2.3)
rack-protection (2.1.0)
rack
rake (13.0.3)
redis (4.1.4)
regexp_parser (2.0.3)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.1)
sidekiq (5.2.9)
connection_pool (~> 2.2, >= 2.2.2)
rack (~> 2.0)
rack-protection (>= 1.5.0)
redis (>= 3.3.5, < 4.2)
unparser (0.6.0)
diff-lcs (~> 1.3)
parser (>= 3.0.0)

PLATFORMS
x86_64-linux

DEPENDENCIES
mutant (~> 0.10.26)
mutant-license!
mutant-minitest (~> 0.10.26)
mutant-rspec (~> 0.10.26)
rake (>= 10.0)
rspec (~> 3.6)
ruby_event_store!
ruby_event_store-sidekiq_scheduler!
sidekiq (~> 5.0)

BUNDLED WITH
2.2.6
9 changes: 9 additions & 0 deletions contrib/ruby_event_store-sidekiq_scheduler/Makefile
@@ -0,0 +1,9 @@
GEM_VERSION = $(shell cat lib/ruby_event_store/sidekiq_scheduler/version.rb | grep VERSION | egrep -o '[0-9]+\.[0-9]+\.[0-9]+')
GEM_NAME = ruby_event_store-sidekiq_scheduler
DATABASE_URL ?= sqlite3::memory:

include ../../support/make/install.mk
include ../../support/make/test.mk
include ../../support/make/mutant.mk
include ../../support/make/gem.mk
include ../../support/make/help.mk
28 changes: 28 additions & 0 deletions contrib/ruby_event_store-sidekiq_scheduler/README.md
@@ -0,0 +1,28 @@
# Ruby Event Store Sidekiq Scheduler

A library to schedule Ruby Event Store handlers to sidekiq.

![Ruby Event Store Sidekiq Scheduler](https://github.com/RailsEventStore/rails_event_store/workflows/ruby_event_store-sidekiq_scheduler/badge.svg)

## How to use this gem

Add to your gemfile in application:

```ruby
gem "ruby_event_store-sidekiq_scheduler"
```

Declare the scheduler in your Ruby Event Store configuration. We recommend to use it with `AfterCommitAsyncDispatcher`

```ruby
event_store = RailsEventStore::Client.new(
dispatcher: RailsEventStore::AfterCommitAsyncDispatcher.new(scheduler: RubyEventStore::SidekiqScheduler.new),
)
```

Read more about [using asynchronous handlers](https://railseventstore.org/docs/v2/subscribe/#async-handlers)


## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/RailsEventStore/rails_event_store.
@@ -0,0 +1,20 @@
require 'sidekiq'

module RubyEventStore
class SidekiqScheduler
def initialize(serializer:)
@serializer = serializer
end

def call(klass, record)
klass.perform_async(record.serialize(serializer).to_h)
end

def verify(subscriber)
Class === subscriber && !!(subscriber < Sidekiq::Worker)
end

private
attr_reader :serializer
end
end
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module RubyEventStore
class SidekiqScheduler
VERSION = "0.1.0"
end
end
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require_relative "lib/ruby_event_store/sidekiq_scheduler/version"

Gem::Specification.new do |spec|
spec.name = "ruby_event_store-sidekiq_scheduler"
spec.version = RubyEventStore::SidekiqScheduler::VERSION
spec.license = "MIT"
spec.author = "Arkency"
spec.email = "dev@arkency.com"
spec.summary = "Ruby Event Store scheduler for sidekiq"
spec.homepage = "https://railseventstore.org"
spec.files = Dir["lib/**/*"]
spec.require_paths = %w[lib]
spec.extra_rdoc_files = %w[README.md]

spec.metadata = {
"homepage_uri" => spec.homepage,
"source_code_uri" => "https://github.com/RailsEventStore/rails_event_store",
"bug_tracker_uri" => "https://github.com/RailsEventStore/rails_event_store/issues",
}

spec.required_ruby_version = ">= 2.5"

spec.add_dependency "ruby_event_store", ">= 2.0.0", "< 3.0.0"
end

0 comments on commit b845636

Please sign in to comment.