-
-
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 11 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,22 @@ | ||
| # 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 selection input cannot be normalized into a supported identifier. | ||
| class InvalidBackendSelectionError < Error; end | ||
|
|
||
| # Raised when a caller refers to a backend outside the supported backend set. | ||
| class UnsupportedBackendError < Error; end | ||
|
|
||
| # Namespace for backend selection and lifecycle contracts. | ||
| module Backend | ||
| autoload :Base, 'karya/backend/base' | ||
| autoload :Descriptor, 'karya/backend/descriptor' | ||
| autoload :InMemory, 'karya/backend/in_memory' | ||
| autoload :Selection, 'karya/backend/selection' | ||
|
niteshpurohit marked this conversation as resolved.
Outdated
|
||
| 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,35 @@ | ||
| # 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 | ||
| descriptor.identifier | ||
| end | ||
|
|
||
| def descriptor | ||
| 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,22 @@ | ||
| # 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 '../primitives/identifier' | ||
|
|
||
|
niteshpurohit marked this conversation as resolved.
Outdated
|
||
| module Karya | ||
| module Backend | ||
| # Immutable backend identity description. | ||
| class Descriptor | ||
| attr_reader :identifier | ||
|
|
||
| def initialize(identifier:) | ||
| @identifier = Selection.normalize_identifier(identifier) | ||
|
niteshpurohit marked this conversation as resolved.
Outdated
|
||
| freeze | ||
| 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,66 @@ | ||
| # 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 '../queue_store/in_memory' | ||
|
|
||
| module Karya | ||
| module Backend | ||
| # Quick-start backend wrapper around the single-process reference queue store. | ||
| class InMemory | ||
| include Base | ||
|
|
||
| DESCRIPTOR = Descriptor.new(identifier: :in_memory) | ||
|
niteshpurohit marked this conversation as resolved.
Outdated
|
||
| UNSET = Object.new.freeze | ||
|
niteshpurohit marked this conversation as resolved.
|
||
| private_constant :UNSET | ||
|
|
||
| def initialize(queue_store_class: QueueStore::InMemory) | ||
| @queue_store_class = queue_store_class | ||
| end | ||
|
|
||
| def descriptor | ||
| DESCRIPTOR | ||
| end | ||
|
|
||
| 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 InvalidBackendSelectionError, 'queue_store_class must build a Karya::QueueStore::Base' | ||
| end | ||
|
|
||
| def before_start(queue_store:) | ||
| _queue_store = queue_store | ||
| nil | ||
| end | ||
|
|
||
| def after_stop(queue_store:) | ||
| _queue_store = queue_store | ||
| nil | ||
| end | ||
|
|
||
|
niteshpurohit marked this conversation as resolved.
Outdated
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # 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 '../primitives/identifier' | ||
|
|
||
| module Karya | ||
| module Backend | ||
| # Normalized backend selection without runtime boot wiring. | ||
| class Selection | ||
| KNOWN_IDENTIFIERS = %w[in_memory sqlite redis postgres mysql].freeze | ||
|
|
||
| IDENTIFIER_ALIASES = { | ||
| 'InMemory' => 'in_memory', | ||
| 'inmemory' => 'in_memory', | ||
| 'in_memory' => 'in_memory', | ||
| 'sqlite' => 'sqlite', | ||
| 'redis' => 'redis', | ||
| 'postgres' => 'postgres', | ||
| 'postgresql' => 'postgres', | ||
| 'mysql' => 'mysql', | ||
| 'my_sql' => 'mysql' | ||
| }.freeze | ||
|
niteshpurohit marked this conversation as resolved.
Outdated
|
||
|
|
||
| attr_reader :identifier | ||
|
|
||
| def self.normalize_identifier(value) | ||
| normalized_input = normalize_identifier_input(value) | ||
| normalized_alias = IDENTIFIER_ALIASES[normalized_input] | ||
| return normalized_alias.freeze if normalized_alias | ||
|
|
||
| raise UnsupportedBackendError, | ||
| "unsupported backend #{normalized_input.inspect}; known backends: #{KNOWN_IDENTIFIERS.join(', ')}" | ||
| end | ||
|
|
||
| def self.known_identifier?(value) | ||
| KNOWN_IDENTIFIERS.include?(normalize_identifier(value)) | ||
| rescue InvalidBackendSelectionError, UnsupportedBackendError | ||
| false | ||
| end | ||
|
|
||
| def initialize(value) | ||
| @identifier = self.class.normalize_identifier(value) | ||
| end | ||
|
|
||
| def self.normalize_identifier_input(value) | ||
| if [NilClass, String, Symbol].any? { |klass| value.is_a?(klass) } | ||
| return Primitives::Identifier.new(:backend, value, error_class: InvalidBackendSelectionError).normalize | ||
| end | ||
|
|
||
| raise InvalidBackendSelectionError, 'backend must be a String or Symbol' | ||
| end | ||
| private_class_method :normalize_identifier_input | ||
| 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,15 @@ | ||
| # 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 InvalidBackendSelectionError < Error | ||
| end | ||
|
|
||
| class UnsupportedBackendError < 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,11 @@ | ||
| module Karya | ||
| module Backend | ||
| module Base | ||
| def identifier: () -> backend_identifier | ||
| def descriptor: () -> Descriptor | ||
| 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,11 @@ | ||
| module Karya | ||
| module Backend | ||
| class Descriptor | ||
| @identifier: backend_identifier | ||
|
|
||
| def initialize: (identifier: backend_identifier_input) -> void | ||
|
|
||
| attr_reader identifier: backend_identifier | ||
| end | ||
| 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.