Skip to content

Commit

Permalink
First release of River Ruby bindings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brandur committed Apr 26, 2024
1 parent 7437932 commit f96c103
Show file tree
Hide file tree
Showing 42 changed files with 2,358 additions and 12 deletions.
158 changes: 158 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: CI

env:
# Database to connect to that can create other databases with `CREATE DATABASE`.
ADMIN_DATABASE_URL: postgres://postgres:postgres@localhost:5432

# Just a common place for steps to put binaries they need and which is added
# to GITHUB_PATH/PATH.
BIN_PATH: /home/runner/bin

# A suitable URL for a test database.
TEST_DATABASE_URL: postgres://postgres:postgres@127.0.0.1:5432/riverqueue_ruby_test?sslmode=disable

on:
- push

jobs:
gem_build:
runs-on: ubuntu-latest
timeout-minutes: 3

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Ruby + `bundle install`
uses: ruby/setup-ruby@v1
with:
ruby-version: "head"
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Build gem (riverqueue-ruby)
run: gem build riverqueue.gemspec
working-directory: .

- name: Build gem (riverqueue-activerecord)
run: gem build riverqueue-activerecord.gemspec
working-directory: ./drivers/riverqueue-activerecord

- name: Build gem (riverqueue-sequel)
run: gem build riverqueue-sequel.gemspec
working-directory: ./drivers/riverqueue-sequel

lint:
runs-on: ubuntu-latest
timeout-minutes: 3

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Ruby + `bundle install`
uses: ruby/setup-ruby@v1
with:
ruby-version: "head"
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Standard Ruby (riverqueue-ruby)
run: bundle exec standardrb
working-directory: .

- name: bundle install (riverqueue-activerecord)
run: bundle install
working-directory: ./drivers/riverqueue-activerecord

- name: Standard Ruby (riverqueue-activerecord)
run: bundle exec standardrb
working-directory: ./drivers/riverqueue-activerecord

- name: bundle install (riverqueue-sequel)
run: bundle install
working-directory: ./drivers/riverqueue-sequel

- name: Standard Ruby (riverqueue-sequel)
run: bundle exec standardrb
working-directory: ./drivers/riverqueue-sequel

type_check:
runs-on: ubuntu-latest
timeout-minutes: 3

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Ruby + `bundle install`
uses: ruby/setup-ruby@v1
with:
ruby-version: "head"
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Steep (riverqueue-ruby)
run: bundle exec steep check
working-directory: .

spec:
runs-on: ubuntu-latest
timeout-minutes: 3

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 2s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Ruby + `bundle install`
uses: ruby/setup-ruby@v1
with:
ruby-version: "head"
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

# There is a version of Go on Actions' base image, but it's old and can't
# read modern `go.mod` annotations correctly.
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: "stable"
check-latest: true

- name: Create database
run: psql --echo-errors --quiet -c '\timing off' -c "CREATE DATABASE riverqueue_ruby_test;" ${ADMIN_DATABASE_URL}

- name: Install River CLI
run: go install github.com/riverqueue/river/cmd/river@latest

- name: river migrate-up
run: river migrate-up --database-url "$TEST_DATABASE_URL"

- name: Rspec (riverqueue-ruby)
run: bundle exec rspec
working-directory: .

- name: bundle install (riverqueue-activerecord)
run: bundle install
working-directory: ./drivers/riverqueue-activerecord

- name: Rspec (riverqueue-activerecord)
run: bundle exec rspec
working-directory: ./drivers/riverqueue-activerecord

- name: bundle install (riverqueue-sequel)
run: bundle install
working-directory: ./drivers/riverqueue-sequel

- name: Rspec (riverqueue-sequel)
run: bundle exec rspec
working-directory: ./drivers/riverqueue-sequel
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.gem
coverage/
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Initial implementation that supports inserting jobs using either ActiveRecord or Sequel. [PR #1](https://github.com/riverqueue/riverqueue-ruby/pull/1).
15 changes: 15 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
source "https://rubygems.org"

gemspec

group :development, :test do
gem "standard"
gem "steep"
end

group :test do
gem "debug"
gem "rspec-core"
gem "rspec-expectations"
gem "simplecov", require: false
end
147 changes: 147 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
PATH
remote: .
specs:
riverqueue (0.0.1)

GEM
remote: https://rubygems.org/
specs:
abbrev (0.1.2)
activesupport (7.1.3.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.7)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
csv (3.3.0)
debug (1.9.1)
irb (~> 1.10)
reline (>= 0.3.8)
diff-lcs (1.5.0)
docile (1.4.0)
drb (2.2.1)
ffi (1.16.3)
fileutils (1.7.2)
i18n (1.14.4)
concurrent-ruby (~> 1.0)
io-console (0.7.2)
irb (1.11.2)
rdoc
reline (>= 0.4.2)
json (2.7.1)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.0)
minitest (5.22.3)
mutex_m (0.2.0)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
psych (5.1.2)
stringio
racc (1.7.3)
rainbow (3.1.1)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rbs (3.4.4)
abbrev
rdoc (6.6.2)
psych (>= 4.0.0)
regexp_parser (2.9.0)
reline (0.4.3)
io-console (~> 0.5)
rexml (3.2.6)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.61.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.1)
parser (>= 3.3.0.4)
rubocop-performance (1.20.2)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (1.13.0)
securerandom (0.3.1)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
standard (1.34.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.60)
standard-custom (~> 1.0.0)
standard-performance (~> 1.3)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.3.1)
lint_roller (~> 1.1)
rubocop-performance (~> 1.20.2)
steep (1.6.0)
activesupport (>= 5.1)
concurrent-ruby (>= 1.1.10)
csv (>= 3.0.9)
fileutils (>= 1.1.0)
json (>= 2.1.0)
language_server-protocol (>= 3.15, < 4.0)
listen (~> 3.0)
logger (>= 1.3.0)
parser (>= 3.1)
rainbow (>= 2.2.2, < 4.0)
rbs (>= 3.1.0)
securerandom (>= 0.1)
strscan (>= 1.0.0)
terminal-table (>= 2, < 4)
stringio (3.1.0)
strscan (3.1.0)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)

PLATFORMS
arm64-darwin-22
x86_64-linux

DEPENDENCIES
debug
riverqueue!
rspec-core
rspec-expectations
simplecov
standard
steep

BUNDLED WITH
2.4.20
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.PHONY: lint
lint: standardrb

.PHONY: rspec
rspec: spec

.PHONY: spec
spec:
bundle exec rspec
cd drivers/riverqueue-activerecord && bundle exec rspec
cd drivers/riverqueue-sequel && bundle exec rspec

.PHONY: standardrb
standardrb:
bundle exec standardrb --fix
cd drivers/riverqueue-activerecord && bundle exec standardrb --fix
cd drivers/riverqueue-sequel && bundle exec standardrb --fix
11 changes: 11 additions & 0 deletions Steepfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
D = Steep::Diagnostic

target :lib do
check "lib"

library "json"

signature "sig"

configure_code_diagnostics(D::Ruby.strict)
end
Loading

0 comments on commit f96c103

Please sign in to comment.