SproutCMS

This is the code documentation for the SproutCMS project

class Worker

Functions called by worker libraries to indicate status, etc

Source code (18 results)

/modules/Demo/Controllers/Admin/DemoItemAdminController.php   Highlighted file source

Line 25: use Sprout\Helpers\WorkerCtrl;
Line 63: $url = "admin/call/{$this->controller_name}/runWorker";
Line 64: $tools['worker'] = '<li class="worker"><a href="' . Enc::html($url) . '">Run demo worker</a></li>';
Line 176: public function runWorker()
Line 178: $worker = WorkerCtrl::start('SproutModules\\Karmabunny\\Demo\\Helpers\\DemoWorker', 100, 500, 1000);
Line 179: Url::redirect($worker['log_url']);

/modules/Demo/Helpers/DemoWorker.php   Highlighted file source

Line 17: use Sprout\Helpers\Worker;
Line 18: use Sprout\Helpers\WorkerBase;
Line 22: * A basic demonstration of how worker jobs run, using {@see WorkerBase}
Line 24: class DemoWorker extends WorkerBase
Line 26: protected $job_name = 'Demo worker';
Line 34: * Do the work which a worker must do
Line 38: Worker::message("It's running! {$a}");
Line 41: Worker::metric(1, $i);
Line 44: Worker::message("Still running!");
Line 45: Worker::message('$_SERVER:');
Line 46: Worker::message(print_r($_SERVER, true));
Line 49: Worker::metric(2, $i);
Line 52: Worker::message("Almost there!");
Line 53: Worker::message('Sprout::absRoot():');
Line 54: Worker::message(Sprout::absRoot());
Line 57: Worker::metric(3, $i);
Line 60: Worker::message('Finished');
Line 61: Worker::success();

/sprout/config/routes.php   Highlighted file source

Line 129: $config['worker_job/run/([0-9]+)/([a-zA-Z0-9]+)'] = 'WorkerJobController/run/$1/$2';

/sprout/Controllers/Admin/FileAdminController.php   Highlighted file source

Line 22: use Sprout\Exceptions\WorkerJobException;
Line 54: use Sprout\Helpers\WorkerCtrl;
Line 1509: $info = WorkerCtrl::start('Sprout\\Helpers\\WorkerRedoSizes', $_POST['size']);
Line 1510: } catch (WorkerJobException $ex) {
Line 1511: Notification::error('Unable to create worker job');

/sprout/Controllers/Admin/PageAdminController.php   Highlighted file source

Line 25: use Sprout\Exceptions\WorkerJobException;
Line 71: use Sprout\Helpers\WorkerCtrl;
Line 2539: $info = WorkerCtrl::start('Sprout\\Helpers\\WorkerLinkChecker');
Line 2541: $info = WorkerCtrl::start('Sprout\\Helpers\\WorkerLinkChecker', $_POST['email']);
Line 2543: } catch (WorkerJobException $ex) {
Line 2613: WorkerCtrl::start('Sprout\\Helpers\\WorkerLinkChecker');

/sprout/Controllers/Admin/WorkerJobAdminController.php   Highlighted file source

Line 30: use Sprout\Helpers\Worker;
Line 34: * Handles most processing for Worker Jobs
Line 36: class WorkerJobAdminController extends ListAdminController
Line 38: protected $controller_name = 'worker_job';
Line 39: protected $friendly_name = 'Worker Jobs';
Line 103: * UI for running worker jobs manually
Line 107: $view = new View('sprout/admin/worker_job_manual_run');
Line 110: 'title' => 'Worker job manual run',
Line 117: * Manually runs a worker job
Line 127: Url::redirect('admin/extra/worker_job/manual_run');
Line 134: Url::redirect('admin/extra/worker_job/manual_run');
Line 143: ['Sprout\\Helpers\\WorkerBase']
Line 146: // Set up worker environment
Line 160: Worker::$starttime = time();
Line 166: * Return the status and log for the worker job edit view ajax update
Line 173: $q = "SELECT status, metric1val, metric2val, metric3val, log FROM ~worker_jobs WHERE id = ?";

/sprout/Controllers/DbToolsController.php   Highlighted file source

Line 95: [ 'url' => 'admin/extra/worker_job/manual_run', 'name' => 'Manual run worker job', 'desc' => 'Manually run a worker job in a browser' ],
Line 118: [ 'url' => 'admin/intro/worker_job', 'name' => 'Worker job log', 'desc' => 'Log of worker (background) processes' ],

/sprout/Controllers/WorkerJobController.php   Highlighted file source

Line 18: use Sprout\Helpers\Worker;
Line 22: * Runs worker jobs (i.e. Helpers which extend {@see WorkerBase})
Line 24: class WorkerJobController extends Controller
Line 28: * Actually run a worker job
Line 38: $q = "SELECT class_name, args FROM ~worker_jobs WHERE id = ? AND code = ?";
Line 41: Worker::start($job_id);
Line 43: $inst = Sprout::instance($job['class_name'], 'Sprout\Helpers\WorkerBase');

/sprout/Exceptions/WorkerJobException.php   Highlighted file source

Line 22: class WorkerJobException extends Exception

/sprout/Helpers/Sprout.php   Highlighted file source

Line 521: throw new Exception('Not in use any more; use the worker "WorkerLinkChecker".');

/sprout/Helpers/Worker.php   Highlighted file source

Line 20: * Functions called by worker libraries to indicate status, etc
Line 22: class Worker
Line 32: * Called just before the worker thread is started.
Line 40: throw new Exception('Worker jobs MUST be run in CLI mode.');
Line 45: set_exception_handler(array('Sprout\\Helpers\\Worker', 'exceptionHandler'));
Line 46: register_shutdown_function(array('Sprout\\Helpers\\Worker', 'shutdown'));
Line 56: Pdb::update('worker_jobs', $update_fields, array('id' => $job_id));
Line 62: $q = "UPDATE {$pf}worker_jobs
Line 71: $q = "UPDATE {$pf}worker_jobs
Line 86: * Save and output log message for the currently running worker job
Line 138: * Report that a worker job failed.
Line 152: $q = "UPDATE {$pf}worker_jobs SET
Line 159: self::message('Worker terminated');
Line 165: * Report the successful completion of the worker job.
Line 183: $q = "UPDATE {$pf}worker_jobs SET
Line 196: * Exception and error handling for worker jobs

/sprout/Helpers/WorkerBase.php   Highlighted file source

Line 18: * Base class for worker jobs, which are run via CLI in a separate process
Line 20: abstract class WorkerBase {
Line 40: // Whatever is provided as arguments to WorkerCtrl::start will be provided in the function call

/sprout/Helpers/WorkerCtrl.php   Highlighted file source

Line 20: use Sprout\Exceptions\WorkerJobException;
Line 24: * Functions to update and report on worker status
Line 26: class WorkerCtrl
Line 30: * Starts a new worker
Line 31: * Workers are run in their own process (using the PHP CLI)
Line 42: * @throws WorkerJobException If the job failed to start
Line 51: if (!($inst instanceof WorkerBase)) {
Line 52: throw new InvalidArgumentException('Provided class is not a subclass of "Worker".');
Line 56: $q = "DELETE FROM ~worker_jobs WHERE DATE_ADD(date_modified, INTERVAL 6 MONTH) < NOW()";
Line 78: $job_id = Pdb::insert('worker_jobs', $update_fields);
Line 82: Cron::message("Starting worker job # {$job_id}, class '{$class_name}'.");
Line 85: // Set up an environment for the worker task
Line 86: putenv('PHP_S_WORKER=1');
Line 95: Pdb::update('worker_jobs', ['php_bin' => 'NOT FOUND'], ['id' => $job_id]);
Line 96: throw new WorkerJobException('Unable to find working PHP binary, which is needed for executing background tasks');
Line 101: Pdb::update('worker_jobs', ['php_bin' => 'Unuseable (CGI): ' . $php], ['id' => $job_id]);
Line 102: throw new WorkerJobException('Found a PHP binary, but it\'s a CGI binary; CLI binary required for executing background tasks');
Line 105: Pdb::update('worker_jobs', ['php_bin' => $php], ['id' => $job_id]);
Line 108: $arg = escapeshellarg("worker_job/run/{$job_id}/{$job_code}");
Line 113: $ex = new WorkerJobException('Failed to start process');
Line 124: $q = "SELECT status FROM ~worker_jobs WHERE id = ?";
Line 135: $ex = new WorkerJobException($err);
Line 142: 'log_url' => 'admin/edit/worker_job/' . $job_id
Line 174: * Return the status and metric values for a given worker job.
Line 183: $q = "SELECT status, metric1val, metric2val, metric3val FROM ~worker_jobs WHERE id = ?";

/sprout/Helpers/WorkerLinkChecker.php   Highlighted file source

Line 21: class WorkerLinkChecker extends WorkerBase
Line 78: Worker::message('Found ' . count($res) . ' page(s) total');
Line 79: Worker::metric(1, count($res));
Line 80: Worker::metric(2, 0);
Line 81: Worker::metric(3, 0);
Line 87: Worker::message("Checking page # {$row['id']}; '{$row['name']}'");
Line 90: Worker::metric(2, $processed);
Line 91: Worker::metric(3, $found);
Line 94: Worker::message('');
Line 95: Worker::message(count($errs) . ' pages have bad link(s)');
Line 96: Worker::message($found . ' bad link(s) total');
Line 97: Worker::message('');
Line 100: Worker::message("Preparing HTML report");
Line 107: Worker::message("Preparing CSV report");
Line 112: Worker::message('');
Line 113: Worker::message("Sending reports via email");
Line 136: Worker::message("Sent report to {$row['name']} ({$row['email']})");
Line 139: Worker::message("Sending of report to {$row['name']} ({$row['email']}) failed!");
Line 143: Worker::message("{$sent} email(s) sent successfully.");
Line 146: Worker::message('');
Line 147: Worker::success();

/sprout/Helpers/WorkerRedoSizes.php   Highlighted file source

Line 17: class WorkerRedoSizes extends WorkerBase
Line 28: Worker::message("Only processing size '{$size}'.");
Line 30: Worker::message("Processing all sizes.");
Line 39: Worker::message($row['filename']);
Line 44: Worker::success();

/sprout/tests/sproutTest.php   Highlighted file source

Line 235: Sprout::instance('Sprout\Helpers\WorkerBase');

/sprout/tests/WorkerLinkCheckerTest.php   Highlighted file source

Line 14: use Sprout\Helpers\WorkerLinkChecker;
Line 16: class WorkerLinkCheckerTest extends PHPUnit_Framework_TestCase
Line 44: $obj = new WorkerLinkChecker();
Line 69: $obj = new WorkerLinkChecker();

/sprout/views/admin/worker_job_manual_run.php   Highlighted file source

Line 8: This tool will manually run a worker job class from within a browser request.
Line 13: <form action="admin/call/worker_job/manualRunAction" method="post">
Line 17: Form::nextFieldDetails('Worker class', true, 'This must include the namespace');
Line 18: echo Form::text('class_name', ['placeholder' => 'e.g. Sprout\\Helpers\\WorkerLinkChecker'], []);
Line 28: <button class="button" type="submit">Run worker job</button>

A total of 143 lines in 18 files were found