<?php define('APPROOT', dirname(__DIR__)); require_once APPROOT . '/src/GAS/includes/autoloader.inc.php'; \GAS\config\GasConfig::instance()->setWorkerStarterScript(APPROOT . '/scripts/startWorker.php'); \GAS\config\GasConfig::instance()->loadFromJson(APPROOT . '/examples/config.json'); $gasManager = new \GAS\GasManager(); // Use the simple file-based logger (not ideal due to contention on concurrent file access but good enough for demo purposes) // You'd use a different implemenation in production. $gasManager->setJobLogger(new \GAS\FileJobLogger()); $jobs = array(); echo "\n\nSubmitting jobs to the queue...\n"; for ($i = 0; $i < 5; $i++) { $jobHandle = $gasManager->doBackground('calcPi', ''); $jobs[$jobHandle] = array(); } echo "\n\nSubmitted all the jobs, now waiting until they are all complete...\n"; $knownJobsRemaining = true; while ($knownJobsRemaining) { $jobsStillToProcess = 0; $knownJobsRemaining = false; foreach ($jobs as $jobHandle => $values) { if ($gasManager->isJobKnown($jobHandle)) { $knownJobsRemaining = true; $jobsStillToProcess++; } } if ($jobsStillToProcess) { echo "\n{$jobsStillToProcess} jobs still to process..."; sleep(10); } else {
<?php define('APPROOT', dirname(__DIR__)); require_once APPROOT . '/src/GAS/includes/autoloader.inc.php'; \GAS\config\GasConfig::instance()->setWorkerStarterScript(APPROOT . '/scripts/startWorker.php'); \GAS\config\GasConfig::instance()->loadFromJson(APPROOT . '/examples/config.json'); $gasManager = new \GAS\GasManager(); $jobs = array(); echo "\n\nSubmitting jobs to the queue...\n"; for ($i = 0; $i < 100; $i++) { $sleepSeconds = mt_rand(1, 60); $jobHandle = $gasManager->doBackground('sleepFunc', $sleepSeconds); $jobs[$jobHandle] = array('sleepSeconds' => $sleepSeconds, 'status' => 'queued'); } echo "\n\nSubmitted all the jobs, now waiting until they are all complete...\n"; $knownJobsRemaining = true; while ($knownJobsRemaining) { $jobsStillToProcess = 0; $knownJobsRemaining = false; foreach ($jobs as $jobHandle => $values) { if ($gasManager->isJobKnown($jobHandle)) { $knownJobsRemaining = true; $jobsStillToProcess++; } } if ($jobsStillToProcess) { echo "\n{$jobsStillToProcess} jobs still to process..."; sleep(5); } else { echo "\n\nAll jobs processed!\n\n"; }