function main()
{
    $options = getopt('v');
    $verbose = array_key_exists('v', $options);
    $queueConfig = \Application\Facade::getInstance()->getRegisterQueueConfig();
    $notifRepo = \Application\Facade::getInstance()->getNotifRepo();
    if ($verbose) {
        $dsn = $queueConfig->toString();
        dump('queueName[' . $queueConfig->queueName . '] ' . $dsn . ' timeout=' . $queueConfig->timeout);
    }
    $notifFactory = new NotifFactory();
    foreach (getRequest($queueConfig) as $request) {
        $notif = makeNotif($notifFactory, $request);
        echo '.';
        if (!$notif instanceof Notif) {
            continue;
        }
        if ($verbose) {
            dump(time() . ' register: ' . json_encode($notif));
        }
        $notifRepo->register($notif);
    }
}
 * User: Jiang Yu
 * Date: 2015/06/30
 * Time: 3:37 PM.
 */
use Worker\EndlessTasks;
require __DIR__ . '/../bootstrap.php';
$fireNotifications = function ($jsonArray) {
    $requestFactory = new \Worker\Model\TaskFactory();
    $tasks = [];
    foreach ($jsonArray as $jsonString) {
        $options = json_decode($jsonString, true);
        if (!is_array($options)) {
            continue;
        }
        $tasks[] = $requestFactory->create($options[CURLOPT_URL], $options);
    }
    PHP_Timer::start();
    $worker = new \Worker\CurlWorker();
    $worker->addTasks($tasks);
    $worker->run();
    $delta = PHP_Timer::stop();
    echo PHP_Timer::resourceUsage() . ' fire notif cost: ' . PHP_Timer::secondsToTimeString($delta) . PHP_EOL;
};
$facebookOptions = \Application\Facade::getInstance()->getFBGatewayOptions();
dump($facebookOptions);
$taskGenerator = new EndlessTasks($facebookOptions['queueLocation']);
$bufferedNotifications = $taskGenerator->get();
/** @var string[] $tasks */
foreach ($bufferedNotifications as $tasks) {
    call_user_func($fireNotifications, $tasks);
}
Exemple #3
0
<?php

/**
 * Created by PhpStorm.
 * User: Jiang Yu
 * Date: 2015/06/26
 * Time: 4:29 PM
 */
require __DIR__ . '/../../bootstrap.php';
$facebook = \Application\Facade::getInstance()->getParam('facebook');
dump($facebook);
 * User: Jiang Yu
 * Date: 2015/06/24
 * Time: 7:45 PM
 */
use Application\Facade;
use FBGateway\FBNotifFactory;
use Persistency\Facebook\GatewayPersistBuilder;
use Repository\FBGatewayRepo;
require __DIR__ . '/../bootstrap.php';
$options = getopt('v', ['fireTime:', 'no-debug']);
$verbose = isset($options['v']);
$fireTime = isset($options['fireTime']) ? (int) $options['fireTime'] : time();
$debugEnabled = !isset($options['no-debug']);
$timer = (new \Timer\Generator())->shootThenGo($fireTime, time() + 3600);
$fbGatewayConfig = Facade::getInstance()->getFBGatewayOptions();
$gunner = (new GatewayPersistBuilder())->build($fbGatewayConfig);
$fbNotifFactory = new FBNotifFactory();
$fireMachine = new FBGatewayRepo($gunner, $fbNotifFactory);
$notifListRepo = Facade::getInstance()->getNotifListRepo();
foreach ($timer as $timestamp) {
    $pendingList = $notifListRepo->getPending($timestamp);
    if (count($pendingList) === 0) {
        continue;
    }
    if ($verbose) {
        dump(date('Ymd H:i:s') . ' pending notifications = ' . count($pendingList));
    }
    $fbNotifList = $fbNotifFactory->makeList($pendingList);
    $fireMachine->burst($fbNotifList);
    $notifListRepo->markFired($pendingList);
}