-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement backend configuration and lifecycle management #488
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 19 commits into
main
from
feat/backend-configuration-wiring-and-runtime-backend-bootstrapping
May 5, 2026
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
da65624
feat: implement backend configuration and lifecycle management
niteshpurohit 9023ef7
feat: enhance backend configuration and lifecycle management
niteshpurohit 4960e22
refactor: update validate_backend_instance signature
niteshpurohit 1d76307
feat: enhance backend configuration validation and lifecycle
niteshpurohit 26c0757
feat: enhance backend configuration and worker settings
niteshpurohit e9863d6
feat: enhance backend configuration validation
niteshpurohit e04973a
feat: enhance backend configuration and immutability
niteshpurohit 20c9b76
feat: enhance backend validation and immutability
niteshpurohit ec7b508
feat: enhance backend option validation
niteshpurohit b36bacc
feat: enhance backend bootstrapping and error handling
niteshpurohit e225d16
feat: validate backend options and improve error handling
niteshpurohit 50bcc7c
feat: enhance backend configuration and validation
niteshpurohit 7a82d40
feat: enhance backend option validation and error handling
niteshpurohit b401776
feat: enhance queue store factory option validation
niteshpurohit de0e5f1
feat: improve backend bootstrapping and error handling
niteshpurohit 0d1251b
feat: enhance backend option validation and configuration
niteshpurohit 7df0378
feat: enhance backend configuration and validation
niteshpurohit 8159947
feat: enhance queue store class validation
niteshpurohit 418b7d6
feat: enhance backend configuration and class interface
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # 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 'English' | ||
|
|
||
| module Karya | ||
| class CLI < Thor | ||
| # Resolves configured backend settings into a queue store and wraps backend | ||
| # lifecycle hooks around worker boot. | ||
| class BackendBoot | ||
| class << self | ||
| def resolve | ||
| return [nil, Karya.queue_store] unless Karya.backend_class | ||
|
|
||
| backend = instantiate | ||
| [backend, build_queue_store(backend)] | ||
| end | ||
|
|
||
| def run_with_lifecycle(backend, queue_store, &) | ||
| return yield unless backend | ||
|
|
||
| execute_with_lifecycle(backend, queue_store, &) | ||
| end | ||
|
niteshpurohit marked this conversation as resolved.
|
||
|
|
||
| private | ||
|
|
||
| def instantiate | ||
| backend_class = Karya.backend_class | ||
| backend = backend_class.new(**Karya.backend_options) | ||
| return backend if backend.is_a?(Karya::Backend::Base) | ||
|
|
||
| raise Karya::InvalidBackendConfigurationError, | ||
| "#{backend_class} must instantiate a backend including Karya::Backend::Base" | ||
| rescue ArgumentError, TypeError => e | ||
| raise Karya::InvalidBackendConfigurationError, | ||
| "configured backend class #{backend_class} could not be initialized: #{e.message}" | ||
| end | ||
|
|
||
| def build_queue_store(backend) | ||
| queue_store = backend.build_queue_store | ||
| return queue_store if queue_store.is_a?(Karya::QueueStore::Base) | ||
|
|
||
| raise Karya::InvalidBackendConfigurationError, | ||
| "#{backend.class} must build a Karya::QueueStore::Base" | ||
| end | ||
|
|
||
| def execute_with_lifecycle(backend, queue_store) | ||
| started = false | ||
| suppress_cleanup_error = false | ||
| result = nil | ||
|
|
||
| begin | ||
| backend.before_start(queue_store:) | ||
| started = true | ||
| result = yield | ||
| rescue StandardError, SignalException, SystemExit | ||
| suppress_cleanup_error = true | ||
| raise | ||
| ensure | ||
| suppress_cleanup_error ||= $ERROR_INFO.is_a?(Exception) | ||
| finish_lifecycle(backend, queue_store, started:, suppress_cleanup_error:, result:) | ||
|
niteshpurohit marked this conversation as resolved.
|
||
| end | ||
|
niteshpurohit marked this conversation as resolved.
|
||
|
|
||
| result | ||
| end | ||
|
|
||
| def finish_lifecycle(backend, queue_store, started:, suppress_cleanup_error:, result:) | ||
| return unless started | ||
|
|
||
| backend.after_stop(queue_store:) | ||
| rescue StandardError | ||
| raise unless suppress_cleanup_error || positive_status_result?(result) | ||
| end | ||
|
|
||
| def positive_status_result?(result) | ||
| result.is_a?(Numeric) && result.positive? | ||
| end | ||
| 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
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.