sync_my.php 1.1 KB
<?php


swoole_set_process_name('php-email-sync-list-my');

$pm = new \Swoole\Process\Manager();


$pm->addBatch(30,function ($work_id){
    //error_reporting();
    include_once __DIR__."/../vendor/autoload.php";

    $number = 0;

    while (1){
        if($number>500){
            break;
        }
        $id = redis()->lPop('sync_email_lists_my');

        if($id && is_numeric($id)){
            // 占用当前的id,占用2小时
            if(redis()->add('just_sync_'.$id,time(),600)){
                $number++;
                try{
                    // 开始同步
                    $email = db()->cache(3600)->first(\Model\emailSql::first($id));
                    if($email){
                        (new \Service\SyncMail($email))->sync();
                    }

                }catch (Throwable $e){
                    logs('sync : '.$e->getMessage());
                }

                // 30秒后 消除占用
                redis()->expire('just_sync_'.$id,120);
            }
        }else{
            sleep(1);
        }
    }

    _echo('子进程即将推出');

});

$pm->start();