Skip to content

Commit 353f746

Browse files
authored
First release of River Ruby bindings (#1)
A first push of Ruby bindings for River, providing insert-only client to work jobs that are implemented in Go. Includes two initial drivers in the `drivers/` directory, one for ActiveRecord and one for Sequel, which should cover the vast majority of Ruby applications making use of Postgres. The drivers are kept in the main gem's GitHub repository for convenience, but ship as separate gems so that programs including them can minimize their dependencies. Overall, I'm happy at how close I was able to keep the API to the Go version. A lot of syntax in Go just isn't needed due to the more dynamic and implicit nature of Ruby, but the parts that came through are quite close. e.g. We have a job args concept, along with `InsertOpts` that can be added to both jobs and at insert time, just like Go. Purposely not implemented on this first push (I'll follow up with these later on): * Unique jobs. * Batch insert. Try to maintain high Ruby quality standards with: * Full spec suite that requires 100.0% branch coverage. * Use standardrb for lint. * Include RBS files with type and run Steep against the project to verify correctness.
1 parent 7437932 commit 353f746

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2365
-12
lines changed

.github/workflows/ci.yml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
name: CI
2+
3+
env:
4+
# Database to connect to that can create other databases with `CREATE DATABASE`.
5+
ADMIN_DATABASE_URL: postgres://postgres:postgres@localhost:5432
6+
7+
# Just a common place for steps to put binaries they need and which is added
8+
# to GITHUB_PATH/PATH.
9+
BIN_PATH: /home/runner/bin
10+
11+
# A suitable URL for a test database.
12+
TEST_DATABASE_URL: postgres://postgres:postgres@127.0.0.1:5432/riverqueue_ruby_test?sslmode=disable
13+
14+
on:
15+
- push
16+
17+
jobs:
18+
gem_build:
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 3
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Install Ruby + `bundle install`
27+
uses: ruby/setup-ruby@v1
28+
with:
29+
ruby-version: "head"
30+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
31+
32+
- name: Build gem (riverqueue-ruby)
33+
run: gem build riverqueue.gemspec
34+
working-directory: .
35+
36+
- name: Build gem (riverqueue-activerecord)
37+
run: gem build riverqueue-activerecord.gemspec
38+
working-directory: ./drivers/riverqueue-activerecord
39+
40+
- name: Build gem (riverqueue-sequel)
41+
run: gem build riverqueue-sequel.gemspec
42+
working-directory: ./drivers/riverqueue-sequel
43+
44+
lint:
45+
runs-on: ubuntu-latest
46+
timeout-minutes: 3
47+
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v4
51+
52+
- name: Install Ruby + `bundle install`
53+
uses: ruby/setup-ruby@v1
54+
with:
55+
ruby-version: "head"
56+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
57+
58+
- name: Standard Ruby (riverqueue-ruby)
59+
run: bundle exec standardrb
60+
working-directory: .
61+
62+
- name: bundle install (riverqueue-activerecord)
63+
run: bundle install
64+
working-directory: ./drivers/riverqueue-activerecord
65+
66+
- name: Standard Ruby (riverqueue-activerecord)
67+
run: bundle exec standardrb
68+
working-directory: ./drivers/riverqueue-activerecord
69+
70+
- name: bundle install (riverqueue-sequel)
71+
run: bundle install
72+
working-directory: ./drivers/riverqueue-sequel
73+
74+
- name: Standard Ruby (riverqueue-sequel)
75+
run: bundle exec standardrb
76+
working-directory: ./drivers/riverqueue-sequel
77+
78+
type_check:
79+
runs-on: ubuntu-latest
80+
timeout-minutes: 3
81+
82+
steps:
83+
- name: Checkout
84+
uses: actions/checkout@v4
85+
86+
- name: Install Ruby + `bundle install`
87+
uses: ruby/setup-ruby@v1
88+
with:
89+
ruby-version: "head"
90+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
91+
92+
- name: Steep (riverqueue-ruby)
93+
run: bundle exec steep check
94+
working-directory: .
95+
96+
spec:
97+
runs-on: ubuntu-latest
98+
timeout-minutes: 3
99+
100+
services:
101+
postgres:
102+
image: postgres
103+
env:
104+
POSTGRES_PASSWORD: postgres
105+
options: >-
106+
--health-cmd pg_isready
107+
--health-interval 2s
108+
--health-timeout 5s
109+
--health-retries 5
110+
ports:
111+
- 5432:5432
112+
113+
steps:
114+
- name: Checkout
115+
uses: actions/checkout@v4
116+
117+
- name: Install Ruby + `bundle install`
118+
uses: ruby/setup-ruby@v1
119+
with:
120+
ruby-version: "head"
121+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
122+
123+
# There is a version of Go on Actions' base image, but it's old and can't
124+
# read modern `go.mod` annotations correctly.
125+
- name: Install Go
126+
uses: actions/setup-go@v4
127+
with:
128+
go-version: "stable"
129+
check-latest: true
130+
131+
- name: Create database
132+
run: psql --echo-errors --quiet -c '\timing off' -c "CREATE DATABASE riverqueue_ruby_test;" ${ADMIN_DATABASE_URL}
133+
134+
- name: Install River CLI
135+
run: go install github.com/riverqueue/river/cmd/river@latest
136+
137+
- name: river migrate-up
138+
run: river migrate-up --database-url "$TEST_DATABASE_URL"
139+
140+
- name: Rspec (riverqueue-ruby)
141+
run: bundle exec rspec
142+
working-directory: .
143+
144+
- name: bundle install (riverqueue-activerecord)
145+
run: bundle install
146+
working-directory: ./drivers/riverqueue-activerecord
147+
148+
- name: Rspec (riverqueue-activerecord)
149+
run: bundle exec rspec
150+
working-directory: ./drivers/riverqueue-activerecord
151+
152+
- name: bundle install (riverqueue-sequel)
153+
run: bundle install
154+
working-directory: ./drivers/riverqueue-sequel
155+
156+
- name: Rspec (riverqueue-sequel)
157+
run: bundle exec rspec
158+
working-directory: ./drivers/riverqueue-sequel

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.gem
2+
coverage/

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Initial implementation that supports inserting jobs using either ActiveRecord or Sequel. [PR #1](https://github.com/riverqueue/riverqueue-ruby/pull/1).

Gemfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
source "https://rubygems.org"
2+
3+
gemspec
4+
5+
group :development, :test do
6+
gem "standard"
7+
gem "steep"
8+
end
9+
10+
group :test do
11+
gem "debug"
12+
gem "rspec-core"
13+
gem "rspec-expectations"
14+
gem "simplecov", require: false
15+
end

Gemfile.lock

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
PATH
2+
remote: .
3+
specs:
4+
riverqueue (0.0.1)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
abbrev (0.1.2)
10+
activesupport (7.1.3.2)
11+
base64
12+
bigdecimal
13+
concurrent-ruby (~> 1.0, >= 1.0.2)
14+
connection_pool (>= 2.2.5)
15+
drb
16+
i18n (>= 1.6, < 2)
17+
minitest (>= 5.1)
18+
mutex_m
19+
tzinfo (~> 2.0)
20+
ast (2.4.2)
21+
base64 (0.2.0)
22+
bigdecimal (3.1.7)
23+
concurrent-ruby (1.2.3)
24+
connection_pool (2.4.1)
25+
csv (3.3.0)
26+
debug (1.9.1)
27+
irb (~> 1.10)
28+
reline (>= 0.3.8)
29+
diff-lcs (1.5.0)
30+
docile (1.4.0)
31+
drb (2.2.1)
32+
ffi (1.16.3)
33+
fileutils (1.7.2)
34+
i18n (1.14.4)
35+
concurrent-ruby (~> 1.0)
36+
io-console (0.7.2)
37+
irb (1.11.2)
38+
rdoc
39+
reline (>= 0.4.2)
40+
json (2.7.1)
41+
language_server-protocol (3.17.0.3)
42+
lint_roller (1.1.0)
43+
listen (3.9.0)
44+
rb-fsevent (~> 0.10, >= 0.10.3)
45+
rb-inotify (~> 0.9, >= 0.9.10)
46+
logger (1.6.0)
47+
minitest (5.22.3)
48+
mutex_m (0.2.0)
49+
parallel (1.24.0)
50+
parser (3.3.0.5)
51+
ast (~> 2.4.1)
52+
racc
53+
psych (5.1.2)
54+
stringio
55+
racc (1.7.3)
56+
rainbow (3.1.1)
57+
rb-fsevent (0.11.2)
58+
rb-inotify (0.10.1)
59+
ffi (~> 1.0)
60+
rbs (3.4.4)
61+
abbrev
62+
rdoc (6.6.2)
63+
psych (>= 4.0.0)
64+
regexp_parser (2.9.0)
65+
reline (0.4.3)
66+
io-console (~> 0.5)
67+
rexml (3.2.6)
68+
rspec-core (3.12.2)
69+
rspec-support (~> 3.12.0)
70+
rspec-expectations (3.12.3)
71+
diff-lcs (>= 1.2.0, < 2.0)
72+
rspec-support (~> 3.12.0)
73+
rspec-support (3.12.1)
74+
rubocop (1.61.0)
75+
json (~> 2.3)
76+
language_server-protocol (>= 3.17.0)
77+
parallel (~> 1.10)
78+
parser (>= 3.3.0.2)
79+
rainbow (>= 2.2.2, < 4.0)
80+
regexp_parser (>= 1.8, < 3.0)
81+
rexml (>= 3.2.5, < 4.0)
82+
rubocop-ast (>= 1.30.0, < 2.0)
83+
ruby-progressbar (~> 1.7)
84+
unicode-display_width (>= 2.4.0, < 3.0)
85+
rubocop-ast (1.31.1)
86+
parser (>= 3.3.0.4)
87+
rubocop-performance (1.20.2)
88+
rubocop (>= 1.48.1, < 2.0)
89+
rubocop-ast (>= 1.30.0, < 2.0)
90+
ruby-progressbar (1.13.0)
91+
securerandom (0.3.1)
92+
simplecov (0.22.0)
93+
docile (~> 1.1)
94+
simplecov-html (~> 0.11)
95+
simplecov_json_formatter (~> 0.1)
96+
simplecov-html (0.12.3)
97+
simplecov_json_formatter (0.1.4)
98+
standard (1.34.0)
99+
language_server-protocol (~> 3.17.0.2)
100+
lint_roller (~> 1.0)
101+
rubocop (~> 1.60)
102+
standard-custom (~> 1.0.0)
103+
standard-performance (~> 1.3)
104+
standard-custom (1.0.2)
105+
lint_roller (~> 1.0)
106+
rubocop (~> 1.50)
107+
standard-performance (1.3.1)
108+
lint_roller (~> 1.1)
109+
rubocop-performance (~> 1.20.2)
110+
steep (1.6.0)
111+
activesupport (>= 5.1)
112+
concurrent-ruby (>= 1.1.10)
113+
csv (>= 3.0.9)
114+
fileutils (>= 1.1.0)
115+
json (>= 2.1.0)
116+
language_server-protocol (>= 3.15, < 4.0)
117+
listen (~> 3.0)
118+
logger (>= 1.3.0)
119+
parser (>= 3.1)
120+
rainbow (>= 2.2.2, < 4.0)
121+
rbs (>= 3.1.0)
122+
securerandom (>= 0.1)
123+
strscan (>= 1.0.0)
124+
terminal-table (>= 2, < 4)
125+
stringio (3.1.0)
126+
strscan (3.1.0)
127+
terminal-table (3.0.2)
128+
unicode-display_width (>= 1.1.1, < 3)
129+
tzinfo (2.0.6)
130+
concurrent-ruby (~> 1.0)
131+
unicode-display_width (2.5.0)
132+
133+
PLATFORMS
134+
arm64-darwin-22
135+
x86_64-linux
136+
137+
DEPENDENCIES
138+
debug
139+
riverqueue!
140+
rspec-core
141+
rspec-expectations
142+
simplecov
143+
standard
144+
steep
145+
146+
BUNDLED WITH
147+
2.4.20

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.PHONY: lint
2+
lint: standardrb
3+
4+
.PHONY: rspec
5+
rspec: spec
6+
7+
.PHONY: spec
8+
spec:
9+
bundle exec rspec
10+
cd drivers/riverqueue-activerecord && bundle exec rspec
11+
cd drivers/riverqueue-sequel && bundle exec rspec
12+
13+
.PHONY: standardrb
14+
standardrb:
15+
bundle exec standardrb --fix
16+
cd drivers/riverqueue-activerecord && bundle exec standardrb --fix
17+
cd drivers/riverqueue-sequel && bundle exec standardrb --fix
18+
19+
.PHONY: steep
20+
steep:
21+
bundle exec steep check
22+
23+
.PHONY: type-check
24+
type-check: steep

Steepfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
D = Steep::Diagnostic
2+
3+
target :lib do
4+
check "lib"
5+
6+
library "json"
7+
8+
signature "sig"
9+
10+
configure_code_diagnostics(D::Ruby.strict)
11+
end

0 commit comments

Comments
 (0)