The name of the table can be configured via the config/queue.php configuration file. After a job has exceeded this amount of attempts, it will be inserted into a failed_jobs table. Don't worry, it happens to the best of us! Laravel includes a convenient way to specify the maximum number of times a job should be attempted. Since things don't always go as planned, sometimes your queued jobs will fail. If you are using APCu, add apc.enable_cli=1 to your APCu configuration. By default, APCu does not work for CLI jobs. Note: This command relies on the cache system to schedule the restart. Remember, the queue workers will die when the queue:restart command is executed, so you should be running a process manager such as Supervisor which automatically restarts the queue workers. This command will gracefully instruct all queue workers to "die" after they finish processing their current job so that no existing jobs are lost. You may gracefully restart all of the workers by including the following command in your deployment script: So, the simplest way to deploy an application using daemon queue workers is to restart the workers during your deployment script. Since daemon queue workers are long-lived processes, they will not pick up changes in your code without being restarted. For example, if you are doing image manipulation with the GD library, you should free the memory with imagedestroy when you are done. Therefore, you should be careful to free any heavy resources before your job finishes. Coding Considerations For Daemon Queue Listenersĭaemon queue workers do not restart the framework before processing each job. You may use the php artisan help queue:work job to view all of the available options. Php artisan queue : work connection - name - daemon - sleep = 3 - tries = 3Īs you can see, the queue:work job supports most of the same options available to queue:listen. The release method accepts one argument: the number of seconds you wish to wait until the job is made available again: If you would like to release the job manually, the InteractsWithQueue trait, which is already included in your generated job class, provides access to the queue job release method. More information on running the queue listener can be found below. The number of maximum attempts is defined by the -tries switch used on the queue:listen or queue:work Artisan jobs. The job will continue to be released until it has been attempted the maximum number of times allowed by your application. If an exception is thrown while the job is being processed, it will automatically be released back onto the queue so it may be attempted again. The Laravel service container automatically injects these dependencies. Note that we are able to type-hint dependencies on the handle method of the job. The handle method is called when the job is processed by the queue. It's all totally transparent to your application and prevents issues that can arise from serializing full Eloquent model instances. When the job is actually handled, the queue system will automatically re-retrieve the full model instance from the database. If your queued job accepts an Eloquent model in its constructor, only the identifier for the model will be serialized onto the queue. Because of the SerializesModels trait that the job is using, Eloquent models will be gracefully serialized and unserialized when the job is processing. In this example, note that we were able to pass an Eloquent model directly into the queued job's constructor. Once the migration is created, you may migrate your database using the migrate command: To generate a migration that creates this table, run the queue:table Artisan command. In order to use the database queue driver, you will need a database table to hold the jobs. In this file you will find connection configurations for each of the queue drivers that are included with the framework, which includes a database, Beanstalkd, Amazon SQS, Redis, and synchronous (for local use) driver.Ī null queue driver is also included which simply discards queued jobs. The queue configuration file is stored in config/queue.php. Queues allow you to defer the processing of a time consuming task, such as sending an e-mail, until a later time which drastically speeds up web requests to your application. The Laravel queue service provides a unified API across a variety of different queue back-ends.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |