Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["3.0", "3.1", "3.2", "3.3"]
ruby: ["3.3", "3.4"]

name: ${{ matrix.ruby }}

Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ inherit_gem:

AllCops:
DisplayCopNames: true
TargetRubyVersion: 3.0
TargetRubyVersion: 3.3

Naming/FileName:
Exclude:
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gemspec

gem "async"
gem "money"
gem "opentelemetry-api"
gem "pg"
gem "pry"
gem "rake"
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
umbrellio-sequel-plugins (0.18.0)
umbrellio-sequel-plugins (0.18.1)
concurrent-ruby
sequel

Expand Down Expand Up @@ -41,12 +41,15 @@ GEM
concurrent-ruby (~> 1.0)
json (2.7.2)
language_server-protocol (3.17.0.3)
logger (1.7.0)
method_source (1.1.0)
minitest (5.25.1)
money (6.19.0)
i18n (>= 0.6.4, <= 2)
mutex_m (0.2.0)
nio4r (2.7.3)
opentelemetry-api (1.10.0)
logger
parallel (1.26.3)
parser (3.3.5.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -140,6 +143,7 @@ PLATFORMS
DEPENDENCIES
async
money
opentelemetry-api
pg
pry
rake
Expand Down
4 changes: 2 additions & 2 deletions lib/clickhouse/migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def rollback(to: nil)
migrator(target: target.to_i).run
end

def migrator(**opts)
def migrator(**)
Sequel::TimestampMigrator.new(
DB,
Rails.root.join("db/migrate/clickhouse"),
table: :clickhouse_migrations,
use_transactions: false,
**opts,
**,
)
end
end
Expand Down
24 changes: 18 additions & 6 deletions lib/sequel/extensions/concurrent_thread_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def method_missing(...)
__value.public_send(...)
end

def respond_to_missing?(*args)
__value.respond_to?(*args)
def respond_to_missing?(*)
__value.respond_to?(*)
end

[:!, :==, :!=, :instance_eval, :instance_exec].each do |method|
Expand All @@ -24,10 +24,10 @@ def respond_to_missing?(*args)

# Default proxy: schedules block via Concurrent::Future, blocks on first access.
class Proxy < BaseProxy
def initialize(executor, &block)
def initialize(executor, &)
super()

@future = Concurrent::Promises.future_on(executor, &block)
@future = Concurrent::Promises.future_on(executor, &)
end

def __value
Expand Down Expand Up @@ -119,8 +119,20 @@ def choose_executor(opts)
end
end

def async_run(&block)
async_job_class.new(async_thread_executor, &block)
def async_run(&)
if defined?(OpenTelemetry)
Comment thread
tycooon marked this conversation as resolved.
Outdated
otel_context = OpenTelemetry::Context.current
Comment thread
tycooon marked this conversation as resolved.
Outdated
async_job_class.new(async_thread_executor) do
token = OpenTelemetry::Context.attach(otel_context)
Comment thread
tycooon marked this conversation as resolved.
Outdated
begin
yield
ensure
OpenTelemetry::Context.detach(token)
end
end
else
async_job_class.new(async_thread_executor, &)
Comment thread
KirIgor marked this conversation as resolved.
end
end
end

Expand Down
10 changes: 5 additions & 5 deletions lib/sequel/extensions/migration_transaction_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ module SimpleMigrationExtension
end

module MigratorExtension
def checked_transaction(migration, &block)
def checked_transaction(migration, &)
if _use_transaction?(migration)
_transaction(migration, &block)
_transaction(migration, &)
else
yield
end
Expand All @@ -38,11 +38,11 @@ def _use_transaction?(migration)
end
end

def _transaction(migration, &block)
def _transaction(migration, &)
if migration.transaction_opts.nil?
db.transaction(&block)
db.transaction(&)
else
db.transaction(migration.transaction_opts, &block)
db.transaction(migration.transaction_opts, &)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/sequel/extensions/synchronize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ module Synchronize
def synchronize_with(*args, timeout: 10, savepoint: false, skip_if_locked: false)
key = lock_key_for(args)

transaction(savepoint: savepoint) do
transaction(savepoint:) do
hash = key_hash(key)
if get_lock(key, hash, timeout: timeout, skip_if_locked: skip_if_locked)
if get_lock(key, hash, timeout:, skip_if_locked:)
log_info("locked with #{key} (#{hash})")
yield
end
Expand Down
10 changes: 5 additions & 5 deletions lib/sequel/plugins/upsert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def upsert_dataset(target: primary_key)
where_spec = cols.map { |x| Sequel::Plugins::Upsert.distinct_expr(table_name, x) }.reduce(:|)

dataset.insert_conflict(
target: target,
target:,
update: update_spec,
update_where: where_spec,
)
Expand All @@ -30,16 +30,16 @@ def upsert_dataset(target: primary_key)
# @example
# User.upsert(name: "John", email: "jd@test.com", target: :email)
# @return [Sequel::Model]
def upsert(row, **options)
upsert_dataset(**options).insert(sequel_values(row))
def upsert(row, **)
Comment thread
tycooon marked this conversation as resolved.
upsert_dataset(**).insert(sequel_values(row))
end

# Executes the upsert request for multiple rows
# @see #upsert
# @see #upsert_dataset
def multi_upsert(rows, **options)
def multi_upsert(rows, **)
rows = rows.map { |row| sequel_values(row) }
upsert_dataset(**options).multi_insert(rows)
upsert_dataset(**).multi_insert(rows)
end

# Returns formatted row values
Expand Down
2 changes: 1 addition & 1 deletion lib/sequel/plugins/with_lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def with_lock(mode = "FOR NO KEY UPDATE", savepoint: true)
@__locked = true

begin
db.transaction(savepoint: savepoint) do
db.transaction(savepoint:) do
lock!(mode)
yield
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/sequel/archive_migrations.rake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace :sequel do

migrations = Rails.root.glob(migrations_path).map do |file|
filename = file.basename.to_s
{ version: filename.to_i, filename: filename, source: file.read }
{ version: filename.to_i, filename:, source: file.read }
end

conflict_options = {
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/sequel/rollback_archived_migrations.rake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace :sequel do

migrator_args = {
table: args[:migration_table],
use_transactions: use_transactions,
use_transactions:,
allow_missing_migration_files: false,
}.compact
migrator = Sequel::TimestampMigrator.new(DB, tmpdir, migrator_args)
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/sequel/rollback_missing_migrations.rake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace :sequel do
path = Rails.root.join("db/migrate")
migrator_args = {
table: args[:table],
use_transactions: use_transactions,
use_transactions:,
allow_missing_migration_files: false,
}.compact
migrator = Sequel::TimestampMigrator.new(DB, path, migrator_args)
Expand Down
55 changes: 55 additions & 0 deletions spec/extensions/concurrent_thread_pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,61 @@ def make_concurrent_db(**opts)
end
end

describe "OpenTelemetry context propagation" do
require "opentelemetry-api"
Comment thread
tycooon marked this conversation as resolved.
Outdated

let(:otel_key) { OpenTelemetry::Context.create_key("sequel-test") }

after do
# ensure no context leak between examples
OpenTelemetry::Context.detach(OpenTelemetry::Context.attach(OpenTelemetry::Context::ROOT))
Comment thread
tycooon marked this conversation as resolved.
Outdated
end

it "propagates calling-thread context to worker thread" do
ctx = OpenTelemetry::Context.current.set_value(otel_key, "sentinel")
token = OpenTelemetry::Context.attach(ctx)
captured = nil

db.send(:async_run) { captured = OpenTelemetry::Context.current.value(otel_key) }.__value

expect(captured).to eq("sentinel")
ensure
OpenTelemetry::Context.detach(token)
end

it "restores context in worker thread after block completes" do
Comment thread
tycooon marked this conversation as resolved.
Outdated
ctx = OpenTelemetry::Context.current.set_value(otel_key, "sentinel")
token = OpenTelemetry::Context.attach(ctx)
value_after = :not_set

db.send(:async_run) do
inner_token = OpenTelemetry::Context.attach(OpenTelemetry::Context::ROOT)
OpenTelemetry::Context.detach(inner_token)
value_after = OpenTelemetry::Context.current.value(otel_key)
end.__value

expect(value_after).to eq("sentinel")
ensure
OpenTelemetry::Context.detach(token)
end

it "propagates context even when block raises" do
ctx = OpenTelemetry::Context.current.set_value(otel_key, "sentinel")
token = OpenTelemetry::Context.attach(ctx)
captured = nil

result = db.send(:async_run) do
captured = OpenTelemetry::Context.current.value(otel_key)
raise "boom"
end

expect { result.__value }.to raise_error(RuntimeError, "boom")
expect(captured).to eq("sentinel")
ensure
OpenTelemetry::Context.detach(token)
end
end

describe "async_job_class" do
it "is Proxy by default" do
expect(db.async_job_class).to eq(Sequel::Database::ConcurrentThreadPool::Proxy)
Expand Down
8 changes: 4 additions & 4 deletions spec/extensions/deferrable_foreign_keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def foreign_keys_deferrable?(*tables)

RSpec.describe "deferrable_foreign_keys" do
before do
create_table_with_foreign_key(:books, :author_id, :authors, deferrable: deferrable)
create_table_with_foreign_key(:journals, :author_id, :authors, deferrable: deferrable)
create_table_with_foreign_key(:books, :author_id, :authors, deferrable:)
create_table_with_foreign_key(:journals, :author_id, :authors, deferrable:)
end

let(:deferrable) { true }
Expand All @@ -58,8 +58,8 @@ def foreign_keys_deferrable?(*tables)

context "when table is altered" do
before do
alter_table_add_foreign_key(:books, :publisher_id, :publishers, deferrable: deferrable)
alter_table_add_foreign_key(:journals, :publisher_id, :publishers, deferrable: deferrable)
alter_table_add_foreign_key(:books, :publisher_id, :publishers, deferrable:)
alter_table_add_foreign_key(:journals, :publisher_id, :publishers, deferrable:)
end

after do
Expand Down
2 changes: 1 addition & 1 deletion spec/plugins/attr_encrypted_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
end

RSpec.describe Sequel::Plugins::AttrEncrypted do
subject(:order) { order_model.create(name: name, secret_data: secret_data) }
subject(:order) { order_model.create(name:, secret_data:) }

let(:name) { "Ivan" }
let(:secret_data) { { "some_key" => "Some Value" } }
Expand Down
2 changes: 1 addition & 1 deletion spec/plugins/with_lock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def locks_count
context "with outer transaction" do
def update_model!
DB.transaction do
model.with_lock(savepoint: savepoint) do
model.with_lock(savepoint:) do
model.update(count: 1)
raise
end
Expand Down
4 changes: 2 additions & 2 deletions umbrellio-sequel-plugins.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = "umbrellio-sequel-plugins"
spec.version = "0.18.0"
spec.required_ruby_version = ">= 3.0"
spec.version = "0.18.1"
Comment thread
tycooon marked this conversation as resolved.
Outdated
spec.required_ruby_version = ">= 3.3"

spec.authors = ["Team Umbrellio"]
spec.email = ["oss@umbrellio.biz"]
Expand Down
Loading