There is no problem not worth solving, and no technology not worth learning!

In Laravel, queue tasks perform an incomplete investigation and analysis

模拟的方案一,确定在中断队列任务的运行后,在执行至 同步主题的素材至CDN 时,程序的后续流程不会再执行。其最终表现与步骤一一致。然后再次开始 php artisan queue:work,确认队列任务已经丢失

1. Install a theme, which is implemented based on the queue. The code is as follows


    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        // 判断 原始主题ID 是否为空,为空则为安装主题,否则为复制主题
        if (empty($this->themeInstallationTask->themeInstallation->original_theme_id)) {
            // 下载 ZIP
            $downloadZipRes = $this->downloadZip();

            // 解压缩 ZIP
            self::$absolutePath = $downloadZipRes['absolutePath'];
            $this->unzip($downloadZipRes['destination']);

            // 执行安装命令
            self::$destination = $downloadZipRes['destination'];
            $this->execInstallationCommand($this->themeInstallationTask->themeInstallation->theme_id);

        } else {
            // 复制主题文件
            $this->copyThemeAsset();
        }

        // 同步主题的素材至CDN
        $this->syncThemeAssetCdn($this->themeInstallationTask->themeInstallation->theme_id);

        $this->themeInstallationTask->themeInstallation->processing = ThemeInstallation::PROCESSING_FALSE;
        $this->themeInstallationTask->themeInstallation->processing_failed = ThemeInstallation::PROCESSING_FAILED_FALSE;

        $this->themeInstallationTask->themeInstallationVersionPreset->processing = ThemeInstallationVersionPreset::PROCESSING_FALSE;
        $this->themeInstallationTask->themeInstallationVersionPreset->processing_failed = ThemeInstallationVersionPreset::PROCESSING_FAILED_FALSE;

        $this->themeInstallationTask->processing = ThemeInstallationTask::PROCESSING_FALSE;
        $this->themeInstallationTask->processing_failed = ThemeInstallationTask::PROCESSING_FAILED_FALSE;

        $this->themeInstallationTask->push();

        event(new ThemeCreated($this->themeInstallationTask->themeInstallation->theme));

    }


2. Based on the preliminary analysis conclusion, when the material to the synchronization theme is executed to the CDN, it feels like the operation of the program is suddenly interrupted. the present situation. as shown in Figure 1

基于初步的分析结论,在执行至 同步主题的素材至CDN 时,感觉程序的运行就突然中断了似的。表现出的现状。
Figure 1

3. It feels like the container is restarted when the material to the synchronization theme is executed to the CDN. This leads to the interruption of the program operation. Decided to simulate the local environment. Decide to add SLEEP (60) when executing the material to the sync topic to the CDN.


    /**
     * 同步主题的素材至CDN
     *
     * @param string $themeId 主题 ID
     * @return void
     */
    private function syncThemeAssetCdn($themeId)
    {
        $this->themeInstallationTask->step = ThemeInstallationTask::STEP_SYNC_THEME_ASSET_CDN;
        $this->themeInstallationTask->save();

        // 程序开始的地方

        app(ExecCommandHandler::class)->syncThemeAssetCdn($themeId);

        sleep(60);

        // 程序结束的地方,中途未抛出异常
    }


4. The process of the simulation scheme 1 is to interrupt the operation of the queue task when executing to Sleep (60), and manually stop the queue processor. as shown in Figure 2

模拟的方案一的流程是,当在执行至 sleep(60) 时,中断队列任务的运行,手动让队列处理器停止运行
Figure 2

PS E:\wwwroot\object> php artisan queue:work
[2022-08-04 13:57:07][tnFIT28iqbv67GpZ2xwzP6hRFEaJJ6vh] Processing: Modules\ThemeStoreDB\Jobs\ThemeInstallationJob
PS E:\wwwroot\object>


5. Simulation Scheme 1, determine that after the operation of the interrupt queue task, when the material to the synchronization theme is executed to the CDN, the subsequent process of the program will not be executed again. Its final performance is consistent with the step 1. Then start php artisan queue:work again, confirming that the queue task has been lost. as shown in Figure 3

模拟的方案一,确定在中断队列任务的运行后,在执行至 同步主题的素材至CDN 时,程序的后续流程不会再执行。其最终表现与步骤一一致。然后再次开始 php artisan queue:work,确认队列任务已经丢失
Figure 3

6. The process of the simulation scheme 2 is to manually stop the operation of the PHP program when executing to SLEEP (60). as shown in Figure 4

模拟的方案二的流程是,当在执行至 sleep(60) 时,手动停止 PHP 程序的运行
Figure 4

PS C:\Windows\system32> php-cgi.exe -b 127.0.0.1:9001-c C:/php-7.4.27/php.ini
PS C:\Windows\system32>


7. Simulation scheme 2, determine that after the operation of the PHP program is stopped, the subsequent process of the program will not be executed when the material to the synchronization theme is executed to the CDN. Its final performance is consistent with the step 1. However, if php artisan queue:work is always running at this time, when the php program starts to run, the queue task can still continue to execute.

8. The temporary solution to this problem is: re-initiate a new queue task. Find a way to solve it later.

PHP / Laravel / Yii2 Legacy Project Maintenance & Long-Term Technical Support

If your PHP / Laravel / Yii2 project is already in production but needs bug fixing, API troubleshooting, performance optimization, developer handover support, or long-term maintenance, feel free to contact me for remote technical support.

Ideal For:
✅ PHP legacy systems without active maintenance
✅ Laravel / Yii2 project bug fixes
✅ Admin panel feature iterations
✅ RESTful API troubleshooting
✅ MySQL / Redis / Nginx performance issues
✅ Long-term remote part-time maintenance

We can start with a small task:
✅ Production error troubleshooting
✅ API issue analysis
✅ Slow query and performance bottleneck diagnosis
✅ Initial code structure review
✅ Deployment environment and log inspection

If you would like to discuss your project, please contact me and mention: PHP Maintenance Consultation.

Contact Me:
Telegram: @shuijingwan
WeChat: 13980074657
Email: shuijingwanwq@gmail.com

评论

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.