weixin_39844590 2020-11-21 18:25
浏览 0

Concept: Configurable behavior on event dispatching

How could we override what will happen on Love event will be dispatched?

This question was raised many times before. Each time I've returned to it a new ideas come into my mind but all of them have their pros and cons. Finally I've got all pieces together and ready to share with my vision.

Thanks to Pavel Volkov for helping me out with better solution.

First, we should encapsulate increment & decrement logic in jobs. Because we will be able to run those jobs from any place in any time without dispatching an event (which may be listened by many listeners at moment). Listeners will become very simple and synchronous but they will dispatch queued jobs.

Second, we should have more control over the queue. Because developers should be able to choose if they want to use stock package behavior or they want to modify it to their application requirements.

I've designed 4 different implementations of the second part. Each implementation will be described in separate comment.

Spoiler: 4th solution will be implemented https://github.com/cybercog/laravel-love/issues/145#issuecomment-583730266

该提问来源于开源项目:cybercog/laravel-love

  • 写回答

5条回答 默认 最新

  • weixin_39844590 2020-11-21 18:25
    关注

    1. Love global jobs connection

    Add love.jobs_connection config value which will affect on all jobs.

    php
    return [
        // ...other config fields
    
        'jobs_connection' => null,
    ];
    

    Right now its fine because we have only 2 listeners, but later it might be an issue when only some jobs will require to work synchronously.

    Pros:

    • Simple

    Cons:

    • Not extendable
    评论

报告相同问题?