本文整理汇总了PHP中PhabricatorWorker::scheduleTask方法的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorWorker::scheduleTask方法的具体用法?PHP PhabricatorWorker::scheduleTask怎么用?PHP PhabricatorWorker::scheduleTask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhabricatorWorker
的用法示例。
在下文中一共展示了PhabricatorWorker::scheduleTask方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: queueDocumentForIndexing
public static function queueDocumentForIndexing($phid, $parameters = null)
{
if ($parameters === null) {
$parameters = array();
}
parent::scheduleTask(__CLASS__, array('documentPHID' => $phid, 'parameters' => $parameters), array('priority' => parent::PRIORITY_IMPORT));
}
示例2: 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);
}
示例3: 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()));
}
示例4: 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;
}
示例5: 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;
}
示例6: 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('.');
}
}
}
示例7: 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);
}
示例8: 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;
}
示例9: queueForActivation
public function queueForActivation()
{
if ($this->getID()) {
throw new Exception('Only new leases may be queued for activation!');
}
$this->setStatus(DrydockLeaseStatus::STATUS_PENDING);
$this->save();
$task = PhabricatorWorker::scheduleTask('DrydockAllocatorWorker', $this->getID());
// NOTE: Scheduling the task might execute it in-process, if we're running
// from a CLI script. Reload the lease to make sure we have the most
// up-to-date information. Normally, this has no effect.
$this->reload();
$this->setTaskID($task->getID());
$this->save();
return $this;
}
示例10: releaseResource
private function releaseResource(DrydockResource $resource)
{
if ($resource->getStatus() != DrydockResourceStatus::STATUS_ACTIVE) {
// If we had multiple release commands
// This command is only meaningful to resources in the "Open" state.
return;
}
$viewer = $this->getViewer();
$drydock_phid = id(new PhabricatorDrydockApplication())->getPHID();
$resource->openTransaction();
$resource->setStatus(DrydockResourceStatus::STATUS_RELEASED)->save();
// TODO: Hold slot locks until destruction?
DrydockSlotLock::releaseLocks($resource->getPHID());
$resource->saveTransaction();
$statuses = array(DrydockLeaseStatus::STATUS_PENDING, DrydockLeaseStatus::STATUS_ACQUIRED, DrydockLeaseStatus::STATUS_ACTIVE);
$leases = id(new DrydockLeaseQuery())->setViewer($viewer)->withResourcePHIDs(array($resource->getPHID()))->withStatuses($statuses)->execute();
foreach ($leases as $lease) {
$command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($lease->getPHID())->setAuthorPHID($drydock_phid)->setCommand(DrydockCommand::COMMAND_RELEASE)->save();
$lease->scheduleUpdate();
}
PhabricatorWorker::scheduleTask('DrydockResourceDestroyWorker', array('resourcePHID' => $resource->getPHID()), array('objectPHID' => $resource->getPHID()));
}
示例11: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$ids = $args->getArg('id');
if (!$ids) {
throw new PhutilArgumentUsageException("Use the '--id' flag to specify one or more messages to resend.");
}
$messages = id(new PhabricatorMetaMTAMail())->loadAllWhere('id IN (%Ld)', $ids);
if ($ids) {
$ids = array_fuse($ids);
$missing = array_diff_key($ids, $messages);
if ($missing) {
throw new PhutilArgumentUsageException('Some specified messages do not exist: ' . implode(', ', array_keys($missing)));
}
}
foreach ($messages as $message) {
$message->setStatus(PhabricatorMetaMTAMail::STATUS_QUEUE);
$message->save();
$mailer_task = PhabricatorWorker::scheduleTask('PhabricatorMetaMTAWorker', $message->getID(), PhabricatorWorker::PRIORITY_ALERTS);
$console->writeOut("Queued message #%d for resend.\n", $message->getID());
}
}
示例12: executeBuildCommand
private function executeBuildCommand(HarbormasterBuild $build, HarbormasterBuildTransaction $xaction)
{
$command = $xaction->getNewValue();
switch ($command) {
case HarbormasterBuildCommand::COMMAND_RESTART:
$issuable = $build->canRestartBuild();
break;
case HarbormasterBuildCommand::COMMAND_STOP:
$issuable = $build->canStopBuild();
break;
case HarbormasterBuildCommand::COMMAND_RESUME:
$issuable = $build->canResumeBuild();
break;
default:
throw new Exception("Unknown command {$command}");
}
if (!$issuable) {
return;
}
id(new HarbormasterBuildCommand())->setAuthorPHID($xaction->getAuthorPHID())->setTargetPHID($build->getPHID())->setCommand($command)->save();
PhabricatorWorker::scheduleTask('HarbormasterBuildWorker', array('buildID' => $build->getID()));
}
示例13: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$viewer = $this->getViewer();
$key = $args->getArg('key');
if (count($key) < 1) {
throw new PhutilArgumentUsageException(pht('Specify a story key to republish.'));
} else {
if (count($key) > 1) {
throw new PhutilArgumentUsageException(pht('Specify exactly one story key to republish.'));
}
}
$key = head($key);
$story = id(new PhabricatorFeedQuery())->setViewer($viewer)->withChronologicalKeys(array($key))->executeOne();
if (!$story) {
throw new PhutilArgumentUsageException(pht('No story exists with key "%s"!', $key));
}
$console->writeOut("%s\n", pht('Republishing story...'));
PhabricatorWorker::setRunAllTasksInProcess(true);
PhabricatorWorker::scheduleTask('FeedPublisherWorker', array('key' => $key));
$console->writeOut("%s\n", pht('Done.'));
return 0;
}
示例14: continueBuild
public function continueBuild()
{
$build = $this->getBuild();
$lock_key = 'harbormaster.build:' . $build->getID();
$lock = PhabricatorGlobalLock::newLock($lock_key)->lock(15);
$build->reload();
$old_status = $build->getBuildStatus();
try {
$this->updateBuild($build);
} catch (Exception $ex) {
// If any exception is raised, the build is marked as a failure and the
// exception is re-thrown (this ensures we don't leave builds in an
// inconsistent state).
$build->setBuildStatus(HarbormasterBuild::STATUS_ERROR);
$build->save();
$lock->unlock();
$this->releaseAllArtifacts($build);
throw $ex;
}
$lock->unlock();
// NOTE: We queue new targets after releasing the lock so that in-process
// execution via `bin/harbormaster` does not reenter the locked region.
foreach ($this->getNewBuildTargets() as $target) {
$task = PhabricatorWorker::scheduleTask('HarbormasterTargetWorker', array('targetID' => $target->getID()), array('objectPHID' => $target->getPHID()));
}
// If the build changed status, we might need to update the overall status
// on the buildable.
$new_status = $build->getBuildStatus();
if ($new_status != $old_status || $this->shouldForceBuildableUpdate()) {
$this->updateBuildable($build->getBuildable());
}
$this->releaseQueuedArtifacts();
// If we are no longer building for any reason, release all artifacts.
if (!$build->isBuilding()) {
$this->releaseAllArtifacts($build);
}
}
示例15: insertTask
private function insertTask(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit, $data = array())
{
$vcs = $repository->getVersionControlSystem();
switch ($vcs) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$class = 'PhabricatorRepositoryGitCommitMessageParserWorker';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$class = 'PhabricatorRepositorySvnCommitMessageParserWorker';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$class = 'PhabricatorRepositoryMercurialCommitMessageParserWorker';
break;
default:
throw new Exception(pht("Unknown repository type '%s'!", $vcs));
}
$data['commitID'] = $commit->getID();
PhabricatorWorker::scheduleTask($class, $data);
}