本文整理汇总了PHP中PhabricatorWorker类的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorWorker类的具体用法?PHP PhabricatorWorker怎么用?PHP PhabricatorWorker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PhabricatorWorker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute(PhutilArgumentParser $args)
{
$ids = $args->getArg('id');
if (!$ids) {
throw new PhutilArgumentUsageException(pht('Specify one or more lease IDs to release with "%s".', '--id'));
}
$viewer = $this->getViewer();
$drydock_phid = id(new PhabricatorDrydockApplication())->getPHID();
$leases = id(new DrydockLeaseQuery())->setViewer($viewer)->withIDs($ids)->execute();
PhabricatorWorker::setRunAllTasksInProcess(true);
foreach ($ids as $id) {
$lease = idx($leases, $id);
if (!$lease) {
echo tsprintf("%s\n", pht('Lease "%s" does not exist.', $id));
continue;
}
if (!$lease->canRelease()) {
echo tsprintf("%s\n", pht('Lease "%s" is not releasable.', $id));
continue;
}
$command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($lease->getPHID())->setAuthorPHID($drydock_phid)->setCommand(DrydockCommand::COMMAND_RELEASE)->save();
$lease->scheduleUpdate();
echo tsprintf("%s\n", pht('Scheduled release of lease "%s".', $id));
}
}
示例2: executeBuildCommand
private function executeBuildCommand(HarbormasterBuild $build, HarbormasterBuildTransaction $xaction)
{
$command = $xaction->getNewValue();
switch ($command) {
case HarbormasterBuildCommand::COMMAND_RESTART:
$issuable = $build->canRestartBuild();
break;
case HarbormasterBuildCommand::COMMAND_PAUSE:
$issuable = $build->canPauseBuild();
break;
case HarbormasterBuildCommand::COMMAND_RESUME:
$issuable = $build->canResumeBuild();
break;
case HarbormasterBuildCommand::COMMAND_ABORT:
$issuable = $build->canAbortBuild();
break;
default:
throw new Exception(pht('Unknown command %s', $command));
}
if (!$issuable) {
return;
}
$actor = $this->getActor();
if (!$build->canIssueCommand($actor, $command)) {
return;
}
id(new HarbormasterBuildCommand())->setAuthorPHID($xaction->getAuthorPHID())->setTargetPHID($build->getPHID())->setCommand($command)->save();
PhabricatorWorker::scheduleTask('HarbormasterBuildWorker', array('buildID' => $build->getID()), array('objectPHID' => $build->getPHID()));
}
示例3: execute
public function execute(PhutilArgumentParser $args)
{
$viewer = $this->getViewer();
$names = $args->getArg('buildable');
if (count($names) != 1) {
throw new PhutilArgumentUsageException(pht('Specify exactly one buildable object, by object name.'));
}
$name = head($names);
$buildable = id(new PhabricatorObjectQuery())->setViewer($viewer)->withNames($names)->executeOne();
if (!$buildable) {
throw new PhutilArgumentUsageException(pht('No such buildable "%s"!', $name));
}
if (!$buildable instanceof HarbormasterBuildableInterface) {
throw new PhutilArgumentUsageException(pht('Object "%s" is not a buildable!', $name));
}
$plan_id = $args->getArg('plan');
if (!$plan_id) {
throw new PhutilArgumentUsageException(pht('Use --plan to specify a build plan to run.'));
}
$plan = id(new HarbormasterBuildPlanQuery())->setViewer($viewer)->withIDs(array($plan_id))->executeOne();
if (!$plan) {
throw new PhutilArgumentUsageException(pht('Build plan "%s" does not exist.', $plan_id));
}
$console = PhutilConsole::getConsole();
$buildable = HarbormasterBuildable::initializeNewBuildable($viewer)->setIsManualBuildable(true)->setBuildablePHID($buildable->getHarbormasterBuildablePHID())->setContainerPHID($buildable->getHarbormasterContainerPHID())->save();
$console->writeOut("%s\n", pht('Applying plan %s to new buildable %s...', $plan->getID(), 'B' . $buildable->getID()));
$console->writeOut("\n %s\n\n", PhabricatorEnv::getProductionURI('/B' . $buildable->getID()));
PhabricatorWorker::setRunAllTasksInProcess(true);
$buildable->applyPlan($plan);
$console->writeOut("%s\n", pht('Done.'));
return 0;
}
示例4: doWork
protected function doWork()
{
$lock = $this->acquireJobLock();
$job = $this->loadJob();
$actor = $this->loadActor($job);
$status = $job->getStatus();
switch ($status) {
case PhabricatorWorkerBulkJob::STATUS_WAITING:
// This is what we expect. Other statuses indicate some kind of race
// is afoot.
break;
default:
throw new PhabricatorWorkerPermanentFailureException(pht('Found unexpected job status ("%s").', $status));
}
$tasks = $job->createTasks();
foreach ($tasks as $task) {
$task->save();
}
$this->updateJobStatus($job, PhabricatorWorkerBulkJob::STATUS_RUNNING);
$lock->unlock();
foreach ($tasks as $task) {
PhabricatorWorker::scheduleTask('PhabricatorWorkerBulkJobTaskWorker', array('jobID' => $job->getID(), 'taskID' => $task->getID()), array('priority' => PhabricatorWorker::PRIORITY_BULK));
}
$this->updateJob($job);
}
示例5: execute
protected function execute(ConduitAPIRequest $request)
{
$viewer = $request->getUser();
$build_target_phid = $request->getValue('buildTargetPHID');
$message_type = $request->getValue('type');
$build_target = id(new HarbormasterBuildTargetQuery())->setViewer($viewer)->withPHIDs(array($build_target_phid))->executeOne();
if (!$build_target) {
throw new Exception(pht('No such build target!'));
}
$save = array();
$lint_messages = $request->getValue('lint', array());
foreach ($lint_messages as $lint) {
$save[] = HarbormasterBuildLintMessage::newFromDictionary($build_target, $lint);
}
$unit_messages = $request->getValue('unit', array());
foreach ($unit_messages as $unit) {
$save[] = HarbormasterBuildUnitMessage::newFromDictionary($build_target, $unit);
}
$save[] = HarbormasterBuildMessage::initializeNewMessage($viewer)->setBuildTargetPHID($build_target->getPHID())->setType($message_type);
$build_target->openTransaction();
foreach ($save as $object) {
$object->save();
}
$build_target->saveTransaction();
// If the build has completely paused because all steps are blocked on
// waiting targets, this will resume it.
PhabricatorWorker::scheduleTask('HarbormasterBuildWorker', array('buildID' => $build_target->getBuild()->getID()));
return null;
}
示例6: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$viewer = $this->getViewer();
$subscription_phid = $args->getArg('subscription');
if (!$subscription_phid) {
throw new PhutilArgumentUsageException(pht('Specify which subscription to invoice with %s.', '--subscription'));
}
$subscription = id(new PhortuneSubscriptionQuery())->setViewer($viewer)->withPHIDs(array($subscription_phid))->needTriggers(true)->executeOne();
if (!$subscription) {
throw new PhutilArgumentUsageException(pht('Unable to load subscription with PHID "%s".', $subscription_phid));
}
$now = $args->getArg('now');
$now = $this->parseTimeArgument($now);
if (!$now) {
$now = PhabricatorTime::getNow();
}
$time_guard = PhabricatorTime::pushTime($now, date_default_timezone_get());
$console->writeOut("%s\n", pht('Set current time to %s.', phabricator_datetime(PhabricatorTime::getNow(), $viewer)));
$auto_range = $args->getArg('auto-range');
$last_arg = $args->getArg('last');
$next_arg = $args->getARg('next');
if (!$auto_range && !$last_arg && !$next_arg) {
throw new PhutilArgumentUsageException(pht('Specify a billing range with %s and %s, or use %s.', '--last', '--next', '--auto-range'));
} else {
if (!$auto_range & (!$last_arg || !$next_arg)) {
throw new PhutilArgumentUsageException(pht('When specifying %s or %s, you must specify both arguments ' . 'to define the beginning and end of the billing range.', '--last', '--next'));
} else {
if (!$auto_range && ($last_arg && $next_arg)) {
$last_time = $this->parseTimeArgument($args->getArg('last'));
$next_time = $this->parseTimeArgument($args->getArg('next'));
} else {
if ($auto_range && ($last_arg || $next_arg)) {
throw new PhutilArgumentUsageException(pht('Use either %s or %s and %s to specify the ' . 'billing range, but not both.', '--auto-range', '--last', '--next'));
} else {
$trigger = $subscription->getTrigger();
$event = $trigger->getEvent();
if (!$event) {
throw new PhutilArgumentUsageException(pht('Unable to calculate %s, this subscription has not been ' . 'scheduled for billing yet. Wait for the trigger daemon to ' . 'schedule the subscription.', '--auto-range'));
}
$last_time = $event->getLastEventEpoch();
$next_time = $event->getNextEventEpoch();
}
}
}
}
$console->writeOut("%s\n", pht('Preparing to invoice subscription "%s" from %s to %s.', $subscription->getSubscriptionName(), $last_time ? phabricator_datetime($last_time, $viewer) : pht('subscription creation'), phabricator_datetime($next_time, $viewer)));
PhabricatorWorker::setRunAllTasksInProcess(true);
if (!$args->getArg('force')) {
$console->writeOut("**<bg:yellow> %s </bg>**\n%s\n", pht('WARNING'), phutil_console_wrap(pht('Manually invoicing will double bill payment accounts if the ' . 'range overlaps an existing or future invoice. This script is ' . 'intended for testing and development, and should not be part ' . 'of routine billing operations. If you continue, you may ' . 'incorrectly overcharge customers.')));
if (!phutil_console_confirm(pht('Really invoice this subscription?'))) {
throw new Exception(pht('Declining to invoice.'));
}
}
PhabricatorWorker::scheduleTask('PhortuneSubscriptionWorker', array('subscriptionPHID' => $subscription->getPHID(), 'trigger.last-epoch' => $last_time, 'trigger.this-epoch' => $next_time, 'manual' => true), array('objectPHID' => $subscription->getPHID()));
return 0;
}
示例7: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$viewer = $this->getViewer();
$tos = $args->getArg('to');
$body = $args->getArg('body');
PhabricatorWorker::setRunAllTasksInProcess(true);
PhabricatorSMSImplementationAdapter::sendSMS($tos, $body);
$console->writeErr("%s\n\n phabricator/ \$ ./bin/sms list-outbound \n\n", pht('Send completed! You can view the list of SMS messages sent by ' . 'running this command:'));
}
示例8: releaseLease
private function releaseLease(DrydockLease $lease)
{
$lease->openTransaction();
$lease->setStatus(DrydockLeaseStatus::STATUS_RELEASED)->save();
// TODO: Hold slot locks until destruction?
DrydockSlotLock::releaseLocks($lease->getPHID());
$lease->saveTransaction();
PhabricatorWorker::scheduleTask('DrydockLeaseDestroyWorker', array('leasePHID' => $lease->getPHID()), array('objectPHID' => $lease->getPHID()));
$resource = $lease->getResource();
$blueprint = $resource->getBlueprint();
$blueprint->didReleaseLease($resource, $lease);
}
示例9: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$console->writeOut("%s\n", pht('Adding many test tasks to worker queue. Use ^C to exit.'));
$n = 0;
while (true) {
PhabricatorWorker::scheduleTask('PhabricatorTestWorker', array());
if ($n++ % 100 === 0) {
$console->writeOut('.');
}
}
}
示例10: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$is_all = $args->getArg('all');
$is_type = $args->getArg('type');
$is_force = $args->getArg('force');
$obj_names = $args->getArg('objects');
if ($obj_names && ($is_all || $is_type)) {
throw new PhutilArgumentUsageException(pht("You can not name objects to index alongside the '%s' or '%s' flags.", '--all', '--type'));
} else {
if (!$obj_names && !($is_all || $is_type)) {
throw new PhutilArgumentUsageException(pht("Provide one of '%s', '%s' or a list of object names.", '--all', '--type'));
}
}
if ($obj_names) {
$phids = $this->loadPHIDsByNames($obj_names);
} else {
$phids = $this->loadPHIDsByTypes($is_type);
}
if (!$phids) {
throw new PhutilArgumentUsageException(pht('Nothing to index!'));
}
if ($args->getArg('background')) {
$is_background = true;
} else {
PhabricatorWorker::setRunAllTasksInProcess(true);
$is_background = false;
}
if (!$is_background) {
$console->writeOut("%s\n", pht('Run this workflow with "%s" to queue tasks for the daemon workers.', '--background'));
}
$groups = phid_group_by_type($phids);
foreach ($groups as $group_type => $group) {
$console->writeOut("%s\n", pht('Indexing %d object(s) of type %s.', count($group), $group_type));
}
$bar = id(new PhutilConsoleProgressBar())->setTotal(count($phids));
$parameters = array('force' => $is_force);
$any_success = false;
foreach ($phids as $phid) {
try {
PhabricatorSearchWorker::queueDocumentForIndexing($phid, $parameters);
$any_success = true;
} catch (Exception $ex) {
phlog($ex);
}
$bar->update(1);
}
$bar->done();
if (!$any_success) {
throw new Exception(pht('Failed to rebuild search index for any documents.'));
}
}
示例11: execute
protected function execute(ConduitAPIRequest $request)
{
$viewer = $request->getUser();
$build_target_phid = $request->getValue('buildTargetPHID');
$message_type = $request->getValue('type');
$build_target = id(new HarbormasterBuildTargetQuery())->setViewer($viewer)->withPHIDs(array($build_target_phid))->executeOne();
if (!$build_target) {
throw new Exception(pht('No such build target!'));
}
$message = HarbormasterBuildMessage::initializeNewMessage($viewer)->setBuildTargetPHID($build_target->getPHID())->setType($message_type)->save();
// If the build has completely paused because all steps are blocked on
// waiting targets, this will resume it.
PhabricatorWorker::scheduleTask('HarbormasterBuildWorker', array('buildID' => $build_target->getBuild()->getID()));
return null;
}
示例12: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$viewer = $this->getViewer();
$triggers = $this->loadTriggers($args);
$now = $args->getArg('now');
$now = $this->parseTimeArgument($now);
if (!$now) {
$now = PhabricatorTime::getNow();
}
$time_guard = PhabricatorTime::pushTime($now, date_default_timezone_get());
$console->writeOut("%s\n", pht('Set current time to %s.', phabricator_datetime(PhabricatorTime::getNow(), $viewer)));
$last_time = $this->parseTimeArgument($args->getArg('last'));
$next_time = $this->parseTimeArgument($args->getArg('next'));
PhabricatorWorker::setRunAllTasksInProcess(true);
foreach ($triggers as $trigger) {
$console->writeOut("%s\n", pht('Executing trigger %s.', $this->describeTrigger($trigger)));
$event = $trigger->getEvent();
if ($event) {
if (!$last_time) {
$last_time = $event->getLastEventEpoch();
}
if (!$next_time) {
$next_time = $event->getNextEventEpoch();
}
}
if (!$next_time) {
$console->writeOut("%s\n", pht('Trigger is not scheduled to execute. Use --next to simluate ' . 'a scheduled event.'));
continue;
} else {
$console->writeOut("%s\n", pht('Executing event as though it was scheduled to execute at %s.', phabricator_datetime($next_time, $viewer)));
}
if (!$last_time) {
$console->writeOut("%s\n", pht('Executing event as though it never previously executed.'));
} else {
$console->writeOut("%s\n", pht('Executing event as though it previously executed at %s.', phabricator_datetime($last_time, $viewer)));
}
$trigger->executeTrigger($last_time, $next_time);
$reschedule_time = $trigger->getNextEventEpoch($next_time, $is_reschedule = true);
if (!$reschedule_time) {
$console->writeOut("%s\n", pht('After executing under these conditions, this event would never ' . 'execute again.'));
} else {
$console->writeOut("%s\n", pht('After executing under these conditions, this event would ' . 'next execute at %s.', phabricator_datetime($reschedule_time, $viewer)));
}
}
return 0;
}
示例13: execute
public function execute(PhutilArgumentParser $args)
{
$viewer = $this->getViewer();
$ids = $args->getArg('id');
if (!$ids) {
throw new PhutilArgumentUsageException(pht('Specify one or more lease IDs to update with "%s".', '--id'));
}
$leases = id(new DrydockLeaseQuery())->setViewer($viewer)->withIDs($ids)->execute();
PhabricatorWorker::setRunAllTasksInProcess(true);
foreach ($ids as $id) {
$lease = idx($leases, $id);
if (!$lease) {
echo tsprintf("%s\n", pht('Lease "%s" does not exist.', $id));
continue;
}
echo tsprintf("%s\n", pht('Updating lease "%s".', $id));
$lease->scheduleUpdate();
}
}
示例14: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$is_all = $args->getArg('all');
$is_type = $args->getArg('type');
$obj_names = $args->getArg('objects');
if ($obj_names && ($is_all || $is_type)) {
throw new PhutilArgumentUsageException("You can not name objects to index alongside the '--all' or '--type' " . "flags.");
} else {
if (!$obj_names && !($is_all || $is_type)) {
throw new PhutilArgumentUsageException("Provide one of '--all', '--type' or a list of object names.");
}
}
if ($obj_names) {
$phids = $this->loadPHIDsByNames($obj_names);
} else {
$phids = $this->loadPHIDsByTypes($is_type);
}
if (!$phids) {
throw new PhutilArgumentUsageException('Nothing to index!');
}
if ($args->getArg('background')) {
$is_background = true;
} else {
PhabricatorWorker::setRunAllTasksInProcess(true);
$is_background = false;
}
if (!$is_background) {
$console->writeOut("%s\n", pht('Run this workflow with "--background" to queue tasks for the ' . 'daemon workers.'));
}
$groups = phid_group_by_type($phids);
foreach ($groups as $group_type => $group) {
$console->writeOut("%s\n", pht('Indexing %d object(s) of type %s.', count($group), $group_type));
}
$bar = id(new PhutilConsoleProgressBar())->setTotal(count($phids));
$indexer = new PhabricatorSearchIndexer();
foreach ($phids as $phid) {
$indexer->queueDocumentForIndexing($phid);
$bar->update(1);
}
$bar->done();
}
示例15: execute
public function execute(PhutilArgumentParser $args)
{
$viewer = $this->getViewer();
$force_update = $args->getArg('force');
$names = $args->getArg('buildable');
if (count($names) != 1) {
throw new PhutilArgumentUsageException(pht('Specify exactly one buildable, by object name.'));
}
$buildable = id(new PhabricatorObjectQuery())->setViewer($viewer)->withNames($names)->executeOne();
if (!$buildable) {
throw new PhutilArgumentUsageException(pht('No such buildable "%s"!', head($names)));
}
if (!$buildable instanceof HarbormasterBuildable) {
throw new PhutilArgumentUsageException(pht('Object "%s" is not a Harbormaster Buildable!', head($names)));
}
// Reload the buildable directly to get builds.
$buildable = id(new HarbormasterBuildableQuery())->setViewer($viewer)->withIDs(array($buildable->getID()))->needBuilds(true)->executeOne();
$builds = $buildable->getBuilds();
$builds = mpull($builds, null, 'getID');
$build_id = $args->getArg('build');
if ($build_id) {
$builds = array_select_keys($builds, array($build_id));
if (!$builds) {
throw new PhutilArgumentUsageException(pht('The specified buildable does not have a build with ID "%s".', $build_id));
}
}
$console = PhutilConsole::getConsole();
if (!$args->getArg('background')) {
PhabricatorWorker::setRunAllTasksInProcess(true);
}
foreach ($builds as $build) {
$console->writeOut("%s\n", pht('Updating build %d of buildable %s...', $build->getID(), $buildable->getMonogram()));
$engine = id(new HarbormasterBuildEngine())->setViewer($viewer)->setBuild($build);
if ($force_update) {
$engine->setForceBuildableUpdate(true);
}
$engine->continueBuild();
}
$console->writeOut("%s\n", pht('Done.'));
return 0;
}