Queues
Kanvas provides two backends to handle queues, Rabbitmq or AWS SQS. These queues will allow you to move time-consuming tasks, such as sending push notifications, to a later time in the app.
One of the key differences when using our queue manager is that it runs asynchronous thanks to Swoole. This means that even if you send multiple tasks to it, it won't slow down because it has to wait until one process ends to process the other one.
#
Creating a JobAll our jobs are stored in _cli/jobs_
, we follow the same flow as a laravel Job where the logic is located on the handle function.
As you can see, we use the constructor to pass the information needed on this queue, and you can process it using your own logic on the handle function.
In order to call this job, we need to run the dispatch function and pass the information the job is expecting on its constructor.
Note: All logs of the jobs running are stored on storage/logs/api.log
#
Available Queue TypesKanvas runs 3 different queues: Events, Notifications and Jobs. If you need to define another queue, you can do so by writing your queue process action on the QueueTask located in cli/tasks/QueueTask
.
We hope you don't have to, since our jobs are async, you won't run into many FIFO issues where you have slow jobs halting your progress.
#
Firing EventsKanvas events serve as a simpler interface to Phalcon own Event Manager, by providing a way to handle them.
Note: If you still don't know how events work please read phalcon documentation.
Events Listeners are located in library/Listeners
. Listeners provide you an easy way to handle multiple events.
First, you have to register them on the EventManagerProvider
Then, you can call them from within your app by firing them
In order to use this simple fire function you must specify the trait EventManagerAwareTrait when using events, if not you can call them directly from the DI
Note: Again we are just using normal phalcon events
#
Firing Events to Queues:We allow you to send the events to background process, this will help with slow tasks like sending emails and so on.
In order to do so, you just need to call fireToQueue instead of fire
This process will run on the events queue