Programming Language PHP

Namespace ZenCodex\ComposerMirror

Class Log

Method/Function info

Total Examples 4

4 code examples of PHP ZenCodex\ComposerMirror\Log::info extracted from open source projects

Was this example useful?
0
                                                    protected function badCountOfProviderPackages($baseFile = 'packages.json.new')
    {
        Log::info('------------- ' . __FUNCTION__ . ' -------------');
        $cachedir = $this->config->cachedir;
        $packagejson = json_decode(file_get_contents($cachedir . $baseFile));

        $i = $j = 0;
        foreach ($packagejson->{'provider-includes'} as $tpl => $provider) {
            $providerjson = str_replace('%hash%', $provider->sha256, $tpl);
            $file = $cachedir . $providerjson;
            if (!file_exists($file)) {
                Log::error('LOST FILE => ' . $file);
                $i++;
            } elseif ($provider->sha256 !== hash_file('sha256', $file)) {
                Log::error('HASH ERROR => ' . $file);
                $i++;

                // 删除错误文件,重新下载
                unlink($file);
            } else {
                $j++;
            }
        }

        Log::info($i . ' / ' . ($i + $j));

        return $i;
    }
                                            
Was this example useful?
0
                                                    /**
     * check sha256
     */
    protected function badCountOfAllPackages()
    {
        Log::info('------------- ' . __FUNCTION__ . ' -------------');
        $app = App::getInstance();

        $cachedir = $this->config->cachedir;
        $packagejson = json_decode(file_get_contents($cachedir . 'packages.json'));

        $i = $j = 0;
        $errCount = $touchCount = $allCount = 0;

        foreach ($packagejson->{'provider-includes'} as $tpl => $provider) {
            $providerjson = str_replace('%hash%', $provider->sha256, $tpl);
            $packages = json_decode(file_get_contents($cachedir . $providerjson));

            $progressBar = new ProgressBarManager(0, count((array) $packages->providers));
            $progressBar->setFormat("$tpl : %current%/%max% [%bar%] %percent%%");

            foreach ($packages->providers as $tpl2 => $sha) {
                $file = $cachedir . "p/$tpl2\$$sha->sha256.json";

                if (!file_exists($file)) {
                    Log::error('LOST FILE => ' . $file);
                    $i++;
                } elseif ($sha->sha256 !== hash_file('sha256', $file)) {
                    Log::error('HASH ERROR => ' . $file);
                    $i++;
                    unlink($file);
                } else {
                    $j++;
                }

                // 检测zip包
                $originContent = file_get_contents($file);
                $packageData = json_decode($originContent, true);
                foreach ($packageData['packages'] as $packageName => $versions) {
                    foreach ($versions as $verNumber => $vMeta) {

                        // 废弃的包 dist url 为null,跳过不处理
                        // bananeapocalypse/nuitinfo2013api
                        // This package is abandoned and no longer maintained. No replacement package was suggested.

                        if (!$vMeta['dist']['url']) {
//                            Log::error('发现异常包,跳过: ' . $vMeta['dist']['url']);
                            $errCount++;
                            continue;
                        }

                        // 保存 github/bitbucket ... 真实对应下载地址
                        $zipFile = $this->config->distdir . $packageName . '/' . $vMeta['dist']['reference'] . '.zip';
                        if (!file_exists($zipFile)) {
                            $this->storeFile($zipFile, $vMeta['dist']['url']);
                            if (!$this->config->cloudsync) {
                                continue;
                            }
                            $app->pushJob2Task($zipFile);
                        } else {
                            $this->touchFile($zipFile, $app->timestamp);
                            $touchCount++;
                        }

                        $allCount++;
                    }
                }

                $progressBar->advance();
            }
        }

        // 保存时间
        $line = implode(',', [$app->timestamp, $errCount, $touchCount, $allCount]);
        file_put_contents($this->config->dbdir . 'touchall.log', $line . PHP_EOL, FILE_APPEND);
        Log::info($i . ' / ' . ($i + $j));

        return $i;
    }
                                            
Was this example useful?
0
                                                    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $cloud = App::getInstance()->getCloud();
        $this->wp = new WorkerPool();
        $this->wp->setWorkerPoolSize(10)->create(new ClosureWorker(
            function ($jobData, $semaphone, $storage) use ($cloud) {
                $cloud->{$jobData->method}($jobData->data);
            }
        ));

//        $isExit = false;
//        $signal_handler = function ($signal) use(&$isExit) {
//            $this->warn("kill signal, please wait for all works done");
//            $isExit = true;
//        };
//
//        pcntl_signal(SIGINT, $signal_handler);  // Ctrl + C
//        pcntl_signal(SIGCHLD, $signal_handler);
//        pcntl_signal(SIGTSTP, $signal_handler);  // Ctrl + Z

        $beanstalk = App::getInstance()->getClientHandler();
        $beanstalk->watch('composer');

        $stats = $beanstalk->stats();
        Log::info('current-jobs-ready => ' . $stats['current-jobs-ready']);
        Log::info('current-jobs-reserved => ' . $stats['current-jobs-reserved']);
        Log::info('current-jobs-buried => ' . $stats['current-jobs-buried']);

        while (1) {
            $job = $beanstalk->reserve(15); // Block until job is available.
            if (!$job) {
                break;
            }

            $jobData = json_decode($job->getData());
            if (!method_exists($cloud, $jobData->method)) {
                throw new \RuntimeException('找不到此方法 => ' . $jobData->method);
            }

            // 只处理最后一个 packages.json,其余的多进程处理
            if ($this->isMainPackageFile($jobData)) {
                $this->processMainPackageFile($jobData);
            } else {
                $this->wp->run($jobData);
            }

            try {
                $beanstalk->delete($job);
            } catch (Exception $e) {
                // Noting to do
            }
        }

        Log::info('DONE!');
    }
                                            
Was this example useful?
0
                                                    // 将文件上传到 又拍云
    public function pushOneFile($file)
    {
        Log::info($file);
        if (!file_exists($file)) {
            throw new \RuntimeException('pushOneFile, Not found => ' . $file);
        }

        // default value for return
        $ret = -1;
        if (count($this->lastUpload) > 1000) {
            $this->lastUpload = [];
        }

        // fix issue: {"msg":"too many requests of the same uri","code":42900002 }
        // sleep to wait
        if (isset($this->lastUpload[$file]) && (time() - intval($this->lastUpload[$file]) < 30)) {
            Log::warn('wait 10s, workaround => too many requests of the same uri');
            sleep(30);
        }

        [$ext, $uri, $tmpfile] = $this->pickFileInfo($file);
        if (empty($tmpfile)) {
            goto __END__;
        }

        try {
            $f = fopen($tmpfile, 'rb');
            // 根据扩展名指定bucket,上传到又拍云
            $this->cloudDisk($ext)->writeStream($uri, $f);
            Log::debug('pushOneFile success => ' . $file);
            $ret = 1;
        } catch (\Exception $e) {
            Log::error("pushOneFile => $file \n" . $e->getMessage());
        }

        __END__:
        $ext == 'zip' and file_exists($tmpfile) and unlink($tmpfile);

        return $ret;
    }