In Laravel 6, during queue execution, some view files are not executed
1. Reference:In Laravel 6, during the execution of the queue, the execution of each task will execute view::addLocation($location); however, each task will only take the $location of the first task. . However, it is found that there are still problems in the subsequent production environment. During queue execution, some view files are not executed (“Setting_Migrations”:[]). as shown in Figure 1
INSERT INTO "" ("source_db", "store_name", "id", "theme_installation_id", "theme_installation_version_preset_id", "from_version", "to_version", "processing", "processing_failed", "step", "failed_message", "extra", "created_at", "updated_at") VALUES ('aws_db12', 'buglcexk30', 5, 5, 5, 'v2.11.1', 'v3.4.0', 0, 0, 7, '', '{"setting_migrations":[],"theme_download_paths":{"zip_path":"/theme_downloads/2023/11/07/1699423025.8743.1229090882.zip","destination":"/theme_downloads/2023/11/07/1699423025.8743.1229090882"}}', '2023-11-08 05:57:02', '2023-11-08 05:57:13');
INSERT INTO "" ("source_db", "store_name", "id", "theme_installation_id", "theme_installation_version_preset_id", "from_version", "to_version", "processing", "processing_failed", "step", "failed_message", "extra", "created_at", "updated_at") VALUES ('aws_db18', 'carver10', 7, 7, 7, 'v2.11.1', 'v3.4.0', 0, 0, 7, '', '{"setting_migrations":[{"file":"v3.0.0/migrate_product_detail.php","exec_at":"2023-11-08 05:57:11"},{"file":"2023_07_11_10_custom_mobile_layout/migrate_product_detail.php","exec_at":"2023-11-08 05:57:11"}],"theme_download_paths":{"zip_path":"/theme_downloads/2023/11/07/1699423022.7951.958836417.zip","destination":"/theme_downloads/2023/11/07/1699423022.7951.958836417"}}', '2023-11-08 05:57:01', '2023-11-08 05:57:11');
INSERT INTO "" ("source_db", "store_name", "id", "theme_installation_id", "theme_installation_version_preset_id", "from_version", "to_version", "processing", "processing_failed", "step", "failed_message", "extra", "created_at", "updated_at") VALUES ('aws_db3', 'cisfioadre59', 8, 8, 8, 'v2.11.1', 'v3.4.0', 0, 0, 7, '', '{"setting_migrations":[],"theme_download_paths":{"zip_path":"/theme_downloads/2023/11/07/1699423022.7315.1637916782.zip","destination":"/theme_downloads/2023/11/07/1699423022.7315.1637916782"}}', '2023-11-08 05:57:01', '2023-11-08 05:57:11');
2. Since the test environment has not reappeared, I finally decided to simulate the deployment method of the production environment as much as possible. Deploy as a cluster from a stand-alone, and in the Raccher workload, click + to the right of the number of available copies of the pod, and add a pod. Try to reproduce this defect. as shown in Figure 2
3. Finally, the reason is that the queue server is a cluster mode. In the cluster mode, there is a certain dependency relationship between queue tasks being destroyed. Let me give an example. The queue InstallTheMeToDB is executed on the A machine, then there is a decompressed theme package file on this machine. However, after the queue InstallTheMeToDB is executed, the execution of the next queue MigrateThemeSettings will be triggered, but this queue may be executed on the B machine. At this time, the execution of this queue depends on the previous decompressed theme package file, but it does not exist on the B machine. This leads to the fact that the theme migration file is not executed.
4. There are now 3 solutions:
(1) Combine 2 jobs into 1;
(2) Find a way to force two jobs to execute on the same machine;
(3) Different machines share a storage, and then decompress the theme package files on the shared storage. This scheme has to ensure that there is no time delay;
5. In the end, it was decided to adopt the 2nd plan: find a way to force the two jobs to execute on the same machine. If you want to perform queue tasks immediately (synchronously), you can use the DispatchNow method. When using this method, queue tasks will not be queued and run in the current process immediately.
MigrateThemeSettings::dispatchNow($this->themeInstallationTask);
6. When the exception is thrown in the queue MigrateThemeSettings, the failed method in MigrateThemeSettings is not executed, but the failed method in installThemetoDB method. in line with expectations. as shown in Figure 3
7. When looking for the decompressed theme package file in the queue MigrateThemeSettings, there is no longer a situation that cannot be found, which is in line with expectations.
![在队列执行过程中,一些视图文件未执行("setting_migrations":[])](https://www.shuijingwanwq.com/wp-content/uploads/2023/12/1-5.png)

