Skip to content

Ruby reactor locks#18

Draft
arturictus wants to merge 3 commits intomainfrom
ruby_reactor_locks
Draft

Ruby reactor locks#18
arturictus wants to merge 3 commits intomainfrom
ruby_reactor_locks

Conversation

@arturictus
Copy link
Copy Markdown
Owner

This pull request introduces support for distributed exclusive locks and semaphores to the RubyReactor framework, enabling safe concurrent execution and resource limiting for reactors. The changes include a new DSL for configuring locking and semaphore behavior, integration with Redis for lock/semaphore primitives, and Sidekiq worker enhancements to handle lock contention gracefully. Comprehensive integration and unit tests are provided to ensure correct behavior.

Locking and Semaphore DSL:

  • Added Lockable DSL module (ruby_reactor/dsl/lockable.rb) allowing reactors to declare exclusive locks (with_lock) and semaphores (with_semaphore) with customizable keys, TTLs, and limits.
  • Reactors now include Lockable for easy configuration (reactor.rb).

Lock and Semaphore Implementation:

  • Implemented distributed lock (Lock) and semaphore (Semaphore) classes with acquisition/release logic, error handling, and re-entrancy support (lock.rb, semaphore.rb). [1] [2]
  • Integrated Redis-based lock and semaphore primitives via the new RedisLocking module (storage/redis_locking.rb) and included it in the Redis adapter (storage/redis_adapter.rb). [1] [2]

Executor and Worker Integration:

  • Updated Executor to acquire locks/semaphores before execution/resume, raising specific errors on contention, and Sidekiq worker to reschedule jobs when locks are busy instead of failing. [1] [2] [3] [4] [5] [6]

Testing and Examples:

  • Added example reactors demonstrating locking and semaphore usage (spec/examples/locking_reactors.rb).
  • Added integration tests for lock/semaphore behavior and contention handling (spec/ruby_reactor/integration/locking_spec.rb).
  • Added Sidekiq worker unit tests for lock acquisition failures and job rescheduling (spec/ruby_reactor/sidekiq_workers/worker_spec.rb).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant