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

[PLA-1975] Add custom queue #285

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

enjinabner
Copy link
Contributor

@enjinabner enjinabner commented Nov 6, 2024

PR Type

enhancement


Description

  • Added a new configuration section in enjin-platform.php to set a dedicated queue for the package.
  • Integrated HasCustomQueue trait across multiple event classes to support custom queue functionality.
  • Enhanced PlatformBroadcastEvent and PlatformEvent classes with Queueable trait and implemented setQueue method.
  • Updated job classes (HotSync, ParseChainData, SyncMetadata) to use the custom queue configuration.
  • Introduced a new trait HasCustomQueue to encapsulate the logic for setting a custom queue.

Changes walkthrough 📝

Relevant files
Configuration changes
1 files
enjin-platform.php
Add configuration for custom queue                                             

config/enjin-platform.php

  • Added a new configuration section for setting a dedicated queue.
+10/-0   
Enhancement
14 files
TransactionCreated.php
Integrate custom queue in TransactionCreated event             

src/Events/Global/TransactionCreated.php

  • Added HasCustomQueue trait to use custom queue functionality.
+3/-0     
TransactionUpdated.php
Integrate custom queue in TransactionUpdated event             

src/Events/Global/TransactionUpdated.php

  • Added HasCustomQueue trait to use custom queue functionality.
+3/-0     
PlatformBroadcastEvent.php
Enhance PlatformBroadcastEvent with custom queue support 

src/Events/PlatformBroadcastEvent.php

  • Added Queueable trait.
  • Implemented setQueue method for custom queue setting.
  • +5/-0     
    PlatformEvent.php
    Enhance PlatformEvent with custom queue support                   

    src/Events/PlatformEvent.php

  • Added Queueable trait.
  • Implemented setQueue method for custom queue setting.
  • +5/-0     
    BalanceSet.php
    Integrate custom queue in BalanceSet event                             

    src/Events/Substrate/Balances/BalanceSet.php

    • Added HasCustomQueue trait to use custom queue functionality.
    +3/-0     
    Deposit.php
    Integrate custom queue in Deposit event                                   

    src/Events/Substrate/Balances/Deposit.php

    • Added HasCustomQueue trait to use custom queue functionality.
    +3/-0     
    DustLost.php
    Integrate custom queue in DustLost event                                 

    src/Events/Substrate/Balances/DustLost.php

    • Added HasCustomQueue trait to use custom queue functionality.
    +3/-0     
    Endowed.php
    Integrate custom queue in Endowed event                                   

    src/Events/Substrate/Balances/Endowed.php

    • Added HasCustomQueue trait to use custom queue functionality.
    +3/-0     
    ReserveRepatriated.php
    Integrate custom queue in ReserveRepatriated event             

    src/Events/Substrate/Balances/ReserveRepatriated.php

    • Added HasCustomQueue trait to use custom queue functionality.
    +3/-0     
    Reserved.php
    Integrate custom queue in Reserved event                                 

    src/Events/Substrate/Balances/Reserved.php

    • Added HasCustomQueue trait to use custom queue functionality.
    +3/-0     
    Slashed.php
    Integrate custom queue in Slashed event                                   

    src/Events/Substrate/Balances/Slashed.php

    • Added HasCustomQueue trait to use custom queue functionality.
    +3/-0     
    Teleport.php
    Integrate custom queue in Teleport event                                 

    src/Events/Substrate/Balances/Teleport.php

    • Added HasCustomQueue trait to use custom queue functionality.
    +3/-0     
    Transfer.php
    Integrate custom queue in Transfer event                                 

    src/Events/Substrate/Balances/Transfer.php

    • Added HasCustomQueue trait to use custom queue functionality.
    +3/-0     
    Unreserved.php
    Integrate custom queue in Unreserved event                             

    src/Events/Substrate/Balances/Unreserved.php

    • Added HasCustomQueue trait to use custom queue functionality.
    +3/-0     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    github-actions bot commented Nov 6, 2024

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Missing Implementation
    The setQueue method in PlatformBroadcastEvent is declared but lacks implementation, which could lead to runtime errors if the method is called.

    Missing Implementation
    The setQueue method in PlatformEvent is declared but lacks implementation, which could lead to runtime errors if the method is called.

    Copy link

    github-actions bot commented Nov 6, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Add a null check for the queue configuration before setting the queue

    Implement a check to ensure that the setQueue method is only called if the queue
    configuration is not null to avoid potential issues with null queue names.

    src/Events/PlatformBroadcastEvent.php [59]

    -$this->setQueue();
    +if (config('enjin-platform.queue') !== null) {
    +    $this->setQueue();
    +}
    Suggestion importance[1-10]: 7

    Why: Adding a null check before setting the queue configuration can prevent runtime errors if the configuration is not set, enhancing the robustness of the code.

    7
    Enhancement
    Add validation for the queue environment variable to prevent empty values

    Validate the environment variables for queue settings to ensure they are not empty
    or malformed, which could lead to runtime errors.

    config/enjin-platform.php [317]

    -'queue' => env('PLATFORM_CORE_QUEUE', 'default'),
    +'queue' => env('PLATFORM_CORE_QUEUE', 'default') ?: 'default',
    Suggestion importance[1-10]: 6

    Why: Validating the environment variable for the queue setting ensures that it does not get set to an empty or malformed value, which could cause issues during runtime.

    6
    Add logging to the queue setting process for better traceability

    Add logging inside the setQueue method to trace queue setting operations, which can
    help in debugging and monitoring.

    src/Traits/HasCustomQueue.php [9]

     $this->onQueue(config('enjin-platform.queue'));
    +Log::info("Queue set to: " . config('enjin-platform.queue'));
    Suggestion importance[1-10]: 5

    Why: Logging the queue setting operations can aid in debugging and monitoring the application, providing insights into the queue configurations at runtime.

    5
    Best practice
    Implement error handling for setting the queue to enhance robustness

    Add error handling for the onQueue method to manage exceptions when the queue is
    unavailable or misconfigured.

    src/Jobs/HotSync.php [26]

    -$this->onQueue(config('enjin-platform.queue'));
    +try {
    +    $this->onQueue(config('enjin-platform.queue'));
    +} catch (Exception $e) {
    +    // Handle exception
    +}
    Suggestion importance[1-10]: 6

    Why: Adding error handling for the queue setting operation in job classes can prevent unhandled exceptions and improve the reliability of the job execution process.

    6

    @enjinabner enjinabner merged commit fb7a777 into master Nov 7, 2024
    7 checks passed
    @enjinabner enjinabner deleted the feature/pla-1975/package-custom-queue branch November 7, 2024 00:04
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Development

    Successfully merging this pull request may close these issues.

    2 participants