Queues - Laravel - The PHP Framework For Web Artisans - 0 views
-
Laravel queues provide a unified API across a variety of different queue backends, such as Beanstalk, Amazon SQS, Redis, or even a relational database.
- ...56 more annotations...
-
any given queue connection may have multiple "queues" which may be thought of as different stacks or piles of queued jobs.
-
if you dispatch a job without explicitly defining which queue it should be dispatched to, the job will be placed on the queue that is defined in the queue attribute of the connection configuration
-
pushing jobs to multiple queues can be especially useful for applications that wish to prioritize or segment how jobs are processed
-
Job classes are very simple, normally containing only a handle method which is called when the job is processed by the queue.
-
we were able to pass an Eloquent model directly into the queued job's constructor. Because of the SerializesModels trait that the job is using, Eloquent models will be gracefully serialized and unserialized when the job is processing.
-
When the job is actually handled, the queue system will automatically re-retrieve the full model instance from the database.
-
When using this method, the job will not be queued and will be run immediately within the current process
-
Deleting jobs using the $this->delete() method will not prevent chained jobs from being processed. The chain will only stop executing if a job in the chain fails.
-
this does not push jobs to different queue "connections" as defined by your queue configuration file, but only to specific queues within a single connection.
-
to defining how many times a job may be attempted before it fails, you may define a time at which the job should timeout.
-
using the funnel method, you may limit jobs of a given type to only be processed by one worker at a time
-
using the throttle method, you may throttle a given type of job to only run 10 times every 60 seconds.
-
If an exception is thrown while the job is being processed, the job will automatically be released back onto the queue so it may be attempted again.
-
dispatch a Closure. This is great for quick, simple tasks that need to be executed outside of the current request cycle
-
When dispatching Closures to the queue, the Closure's code contents is cryptographically signed so it can not be modified in transit.
-
once the queue:work command has started, it will continue to run until it is manually stopped or you close your terminal
-
customize your queue worker even further by only processing particular queues for a given connection
-
The --stop-when-empty option may be used to instruct the worker to process all jobs and then exit gracefully.
-
Since queue workers are long-lived processes, they will not pick up changes to your code without being restarted.
-
the queue workers will die when the queue:restart command is executed, you should be running a process manager such as Supervisor to automatically restart the queue workers.
-
each queue connection defines a retry_after option. This option specifies how many seconds the queue connection should wait before retrying a job that is being processed.
-
The --timeout option specifies how long the Laravel queue master process will wait before killing off a child queue worker that is processing a job.
-
When jobs are available on the queue, the worker will keep processing jobs with no delay in between them.
-
While sleeping, the worker will not process any new jobs - the jobs will be processed after the worker wakes up again
-
the numprocs directive will instruct Supervisor to run 8 queue:work processes and monitor all of them, automatically restarting them if they fail.
-
define a failed method directly on your job class, allowing you to perform job specific clean-up when a failure occurs.
-
When injecting an Eloquent model into a job, it is automatically serialized before being placed on the queue and restored when the job is processed