-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement shared backend interface and selection model #487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
niteshpurohit
merged 13 commits into
main
from
feat/implement-the-shared-backend-interface-and-backend-selection-model
May 3, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ce16c7a
feat: implement shared backend interface and selection model
niteshpurohit 3fda5e6
feat: refine backend selection model and identifiers
niteshpurohit f305c5a
feat: enhance backend identifier normalization
niteshpurohit e4295fc
feat: enhance backend capabilities and descriptor validation
niteshpurohit e357611
feat: enhance backend capabilities and descriptor validation
niteshpurohit 8dd46f4
feat: enhance backend identifier handling and classifications
niteshpurohit 9c646d1
feat: implement shared backend interface and selection model
niteshpurohit f096844
feat: enhance shutdown signal handling and testing
niteshpurohit c85f161
feat: refactor backend interface and capabilities
niteshpurohit 2c57b28
feat: enhance backend interface and signal handling
niteshpurohit 4e70de7
feat: enhance backend interface and error handling
niteshpurohit f2b2707
feat: implement shared backend interface and model
niteshpurohit d2827df
refactor: clean up backend interface methods
niteshpurohit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright Codevedas Inc. 2025-present | ||
| # | ||
| # This source code is licensed under the MIT license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| module Karya | ||
| # Raised when backend configuration is invalid. | ||
| class InvalidBackendConfigurationError < Error; end | ||
|
|
||
| # Namespace for backend interface and lifecycle contracts. | ||
| module Backend | ||
| autoload :Base, 'karya/backend/base' | ||
| autoload :InMemory, 'karya/backend/in_memory' | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright Codevedas Inc. 2025-present | ||
| # | ||
| # This source code is licensed under the MIT license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| module Karya | ||
| module Backend | ||
| # Shared backend contract above the queue-store persistence API. | ||
| module Base | ||
| def identifier | ||
| raise NotImplementedError, "#{self.class} must implement ##{__method__}" | ||
| end | ||
|
|
||
| def build_queue_store | ||
| raise NotImplementedError, "#{self.class} must implement ##{__method__}" | ||
| end | ||
|
|
||
| def before_start(queue_store:) | ||
| _queue_store = queue_store | ||
| nil | ||
| end | ||
|
|
||
| def after_stop(queue_store:) | ||
|
niteshpurohit marked this conversation as resolved.
|
||
| _queue_store = queue_store | ||
| nil | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright Codevedas Inc. 2025-present | ||
| # | ||
| # This source code is licensed under the MIT license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| require_relative '../base' | ||
| require_relative '../backend' | ||
| require_relative '../queue_store/in_memory' | ||
|
|
||
| module Karya | ||
| module Backend | ||
| # Quick-start backend wrapper around the single-process reference queue store. | ||
| class InMemory | ||
| include Base | ||
|
|
||
| UNSET = Object.new.freeze | ||
|
niteshpurohit marked this conversation as resolved.
|
||
| private_constant :UNSET | ||
|
|
||
| def initialize(queue_store_class: QueueStore::InMemory) | ||
| @identifier = 'in_memory' | ||
| @queue_store_class = queue_store_class | ||
| end | ||
|
|
||
| attr_reader :identifier | ||
|
|
||
| def build_queue_store( | ||
| token_generator: UNSET, | ||
| expired_tombstone_limit: UNSET, | ||
| completed_batch_retention_limit: UNSET, | ||
| max_batch_size: UNSET, | ||
| policy_set: UNSET, | ||
| circuit_breaker_policy_set: UNSET, | ||
| fairness_policy: UNSET | ||
| ) | ||
| queue_store = queue_store_class.new(**{ | ||
| token_generator:, | ||
| expired_tombstone_limit:, | ||
| completed_batch_retention_limit:, | ||
| max_batch_size:, | ||
| policy_set:, | ||
| circuit_breaker_policy_set:, | ||
| fairness_policy: | ||
| }.reject { |_name, value| value.equal?(UNSET) }) | ||
| return queue_store if queue_store.is_a?(QueueStore::Base) | ||
|
|
||
| raise InvalidBackendConfigurationError, 'queue_store_class must build a Karya::QueueStore::Base' | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :queue_store_class | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Copyright Codevedas Inc. 2025-present | ||
| # | ||
| # This source code is licensed under the MIT license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| module Karya | ||
| class InvalidBackendConfigurationError < Error | ||
| end | ||
|
|
||
| module Backend | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| module Karya | ||
| module Backend | ||
| module Base | ||
| def identifier: () -> String | ||
| def build_queue_store: () -> QueueStore::Base | ||
| def before_start: (queue_store: QueueStore::Base) -> nil | ||
| def after_stop: (queue_store: QueueStore::Base) -> nil | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| module Karya | ||
| module Backend | ||
| interface _QueueStoreFactoryInput | ||
| def new: ( | ||
| ?token_generator: Karya::callable_value?, | ||
| ?expired_tombstone_limit: Integer?, | ||
| ?completed_batch_retention_limit: Integer?, | ||
| ?max_batch_size: Integer?, | ||
| ?policy_set: Backpressure::PolicySet?, | ||
| ?circuit_breaker_policy_set: CircuitBreaker::PolicySet?, | ||
| ?fairness_policy: Fairness::Policy? | ||
| ) -> QueueStore::Base | ||
|
niteshpurohit marked this conversation as resolved.
|
||
| end | ||
|
|
||
| class InMemory | ||
| include Base | ||
|
|
||
| def initialize: (?queue_store_class: _QueueStoreFactoryInput) -> void | ||
| def identifier: () -> "in_memory" | ||
| def build_queue_store: ( | ||
| ?token_generator: Karya::callable_value?, | ||
| ?expired_tombstone_limit: Integer?, | ||
| ?completed_batch_retention_limit: Integer?, | ||
| ?max_batch_size: Integer?, | ||
| ?policy_set: Backpressure::PolicySet?, | ||
| ?circuit_breaker_policy_set: CircuitBreaker::PolicySet?, | ||
| ?fairness_policy: Fairness::Policy? | ||
| ) -> QueueStore::Base | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe Karya::Backend::Base do | ||
| subject(:backend) { implementation.new } | ||
|
|
||
| let(:implementation) do | ||
| Class.new do | ||
| include Karya::Backend::Base | ||
| end | ||
| end | ||
|
|
||
| it 'requires identifier to be implemented' do | ||
| expect { backend.identifier }.to raise_error(NotImplementedError, /implement #identifier/) | ||
| end | ||
|
|
||
| it 'requires build_queue_store to be implemented' do | ||
| expect { backend.build_queue_store }.to raise_error(NotImplementedError, /implement #build_queue_store/) | ||
| end | ||
|
|
||
| it 'provides no-op lifecycle hooks by default' do | ||
| queue_store = instance_double(Karya::QueueStore::Base) | ||
|
|
||
| expect(backend.before_start(queue_store:)).to be_nil | ||
| expect(backend.after_stop(queue_store:)).to be_nil | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.