Skip to content
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

chore(cli): flags to run each mode individually #207

Merged
merged 1 commit into from
Jan 24, 2025
Merged

Conversation

debuggerpk
Copy link
Collaborator

This PR introduces significant changes to the application's configuration and mode handling, aiming for better flexibility and clarity.

Key Changes

1. Configuration Loading:

  • The Config struct now includes a Mode field to represent the application's operational mode.
  • Configuration loading is enhanced to use koanf for merging configurations from struct defaults and environment variables.
  • Logging now includes the full application configuration at startup.

2. Command-Line Flags and Mode Selection:

  • Introduces flags to select the application mode: migrate, webhook, grpc, queues.
  • A Parse method has been implemented to parse command-line flags and determine the operational mode.
  • Only one mode can be selected at a time, enforcing mutual exclusivity.

3. Dependency Injection:

  • The Dependencies method now sets up the application dependencies based on the selected mode.
  • Introduces a map (deps) that allows the app to resolve different dependencies per mode.
  • Provides functions to setup common dependencies, durable dependencies, queues, nomad, and webhook.
  • Provides dedicated handlers for each mode including migrate, webhook, nomad, queues, and all mode.

4. Mode Constants:

  • Defines constants for each mode: ModeMigrate, ModeWebhook, ModeGRPC, ModeQueues, ModeDefault.

5. Logger Configuration:

  • The configure_logger now includes a way to handle debug mode using text handler instead of JSON.

6. Main Entry Point Changes:

  • The main entry point now uses cfg.Parse() and cfg.Dependencies() to configure services.
  • The application's migration logic now checks for cfg.Mode == ModeMigrate instead of just cfg.Migrate.
  • Services are now started and stopped through the graceful service.

7. Durable Configuration:

  • Durable configuration has been modified to ensure that it only gets configured once on startup.
  • Durable configure function returns an error if it cannot configure the client.

8. Queue Configuration:

  • Queues q_core() and q_hooks() are updated to register activities and workflows to the corresponding queues, also including the option to start a session worker.

9. Webhook Service:

  • The webhook service is now implemented using graceful.Service which allows for graceful start and stop.

Benefits

  • Improved Flexibility: The application can be run in different modes, enabling it to function as a migration tool, a webhook receiver, a gRPC server, a queue worker, or a combination of these.
  • Clear Configuration: Configuration loading and merging are now handled more robustly.
  • Testability: By splitting the logic, each mode is more testable.
  • Maintainability: The modular structure makes it easier to maintain and extend the application.

This refactor provides a more structured approach to managing different aspects of the application based on the execution mode.

@debuggerpk debuggerpk merged commit 15678c4 into main Jan 24, 2025
1 check failed
@debuggerpk debuggerpk deleted the cli-flags branch January 24, 2025 11:38
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