Queue
pdf-optimizer introduces a powerful feature that allows you to queue the optimization of your files seamlessly within the Laravel framework. Queueing files provides a convenient and efficient way to handle optimization tasks asynchronously, improving the responsiveness and performance of your application.
Key Benefits
Asynchronous Processing: Queueing enables the optimization of files in the background, preventing long processing times from affecting the user experience.
Scalability: Easily handle large batches of files by distributing optimization tasks across multiple workers, ensuring optimal resource utilization.
Improved Performance: By offloading optimization to the queue, your application remains responsive, providing a smoother user experience.
There are two ways to enable the queue for optimizing processes. You can enable it globally through the configuration
file or selectively using onQueue
wherever you want to optimize a file.
Usage
The onQueue
method accepts four optional arguments:
enabled (boolean): Responsible for enabling or disabling the queue. It is set to true by default.
name (string): Customizes the queue name, which is set to the
default
value by default.connection (string): Customizes the connection of the queue process. It defaults to null.
timeout (int): Sets the timeout for processes during the queue job.
The PdfOptimizer
class returns an OptimizeResult
object that contains two properties:
isQueued (boolean): Indicates whether the optimization process has been queued. Defaults to false.
queueId (string): Provides an
orderedUuid
for the queued optimization job.
You can store the queueId
in your database and monitor the optimization's result by listening to the PdfOptimizerJobFinished
event.
Job Completion Event
pdf-optimizer
provides an event that fires when an optimization job finishes processing in the queue. This event can be used to perform additional actions once the job is complete, such as sending a notification to a user or updating a database record. The event can be listened to using Laravel's built-in event system, and it provides access to the ID
of optimization job, status of the optimization process, and the message of executed command.
To utilize this feature, you need to create an event listener and register it. Once the job is completed, pdf-optimizer
will notify your listener and provide the necessary information.
Craete a Listener
Register Listener
Listen to Notification
Last updated