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)); } }
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())); }
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; }
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)); }
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); }
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; }
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; }
public function renderForDisplay(PhabricatorUser $viewer) { $suffix = parent::renderForDisplay($viewer); $commit = id(new DiffusionCommitQuery())->setViewer($viewer)->withIDs(array(idx($this->getTaskData(), 'commitID')))->executeOne(); if (!$commit) { return $suffix; } $link = DiffusionView::linkCommit($commit->getRepository(), $commit->getCommitIdentifier()); return array($link, $suffix); }
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:')); }
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); }
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('.'); } } }
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.')); } }
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; }
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; }
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(); } }
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(); }
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; }
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()); } }
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())); }
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())); }
public function execute(PhutilArgumentParser $args) { $console = PhutilConsole::getConsole(); $resource_type = $args->getArg('type'); if (!$resource_type) { throw new PhutilArgumentUsageException(pht('Specify a resource type with `%s`.', '--type')); } $attributes = $args->getArg('attributes'); if ($attributes) { $options = new PhutilSimpleOptions(); $options->setCaseSensitive(true); $attributes = $options->parse($attributes); } PhabricatorWorker::setRunAllTasksInProcess(true); $lease = id(new DrydockLease())->setResourceType($resource_type); if ($attributes) { $lease->setAttributes($attributes); } $lease->queueForActivation()->waitUntilActive(); $console->writeOut("%s\n", pht('Acquired Lease %s', $lease->getID())); return 0; }
public function execute(PhutilArgumentParser $args) { $viewer = $this->getViewer(); $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID(); PhabricatorWorker::setRunAllTasksInProcess(true); $resources = id(new DrydockResourceQuery())->setViewer($viewer)->withStatuses(array(DrydockResourceStatus::STATUS_ACTIVE))->execute(); foreach ($resources as $resource) { $command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($resource->getPHID())->setAuthorPHID($drydock_phid)->setCommand(DrydockCommand::COMMAND_RECLAIM)->save(); $resource->scheduleUpdate(); $resource = $resource->reload(); $name = pht('Resource %d: %s', $resource->getID(), $resource->getResourceName()); switch ($resource->getStatus()) { case DrydockResourceStatus::STATUS_RELEASED: case DrydockResourceStatus::STATUS_DESTROYED: echo tsprintf("%s\n", pht('Resource "%s" was reclaimed.', $name)); break; default: echo tsprintf("%s\n", pht('Resource "%s" could not be reclaimed.', $name)); break; } } }
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; }
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); } }
/** * Set this flag to execute scheduled tasks synchronously, in the same * process. This is useful for debugging, and otherwise dramatically worse * in every way imaginable. */ public static function setRunAllTasksInProcess($all) { self::$runAllTasksInProcess = $all; }
public function scheduleUpdate() { PhabricatorWorker::scheduleTask('DrydockRepositoryOperationUpdateWorker', array('operationPHID' => $this->getPHID()), array('objectPHID' => $this->getPHID(), 'priority' => PhabricatorWorker::PRIORITY_ALERTS)); }
public function execute() { $ref_updates = $this->findRefUpdates(); $all_updates = $ref_updates; $caught = null; try { try { $this->rejectDangerousChanges($ref_updates); } catch (DiffusionCommitHookRejectException $ex) { // If we're rejecting dangerous changes, flag everything that we've // seen as rejected so it's clear that none of it was accepted. $this->rejectCode = PhabricatorRepositoryPushLog::REJECT_DANGEROUS; throw $ex; } $this->applyHeraldRefRules($ref_updates, $all_updates); $content_updates = $this->findContentUpdates($ref_updates); $all_updates = array_merge($all_updates, $content_updates); $this->applyHeraldContentRules($content_updates, $all_updates); // Run custom scripts in `hook.d/` directories. $this->applyCustomHooks($all_updates); // If we make it this far, we're accepting these changes. Mark all the // logs as accepted. $this->rejectCode = PhabricatorRepositoryPushLog::REJECT_ACCEPT; } catch (Exception $ex) { // We'll throw this again in a minute, but we want to save all the logs // first. $caught = $ex; } // Save all the logs no matter what the outcome was. $event = $this->newPushEvent(); $event->setRejectCode($this->rejectCode); $event->setRejectDetails($this->rejectDetails); $event->openTransaction(); $event->save(); foreach ($all_updates as $update) { $update->setPushEventPHID($event->getPHID()); $update->save(); } $event->saveTransaction(); if ($caught) { throw $caught; } // If this went through cleanly, detect pushes which are actually imports // of an existing repository rather than an addition of new commits. If // this push is importing a bunch of stuff, set the importing flag on // the repository. It will be cleared once we fully process everything. if ($this->isInitialImport($all_updates)) { $repository = $this->getRepository(); $repository->markImporting(); } if ($this->emailPHIDs) { // If Herald rules triggered email to users, queue a worker to send the // mail. We do this out-of-process so that we block pushes as briefly // as possible. // (We do need to pull some commit info here because the commit objects // may not exist yet when this worker runs, which could be immediately.) PhabricatorWorker::scheduleTask('PhabricatorRepositoryPushMailWorker', array('eventPHID' => $event->getPHID(), 'emailPHIDs' => array_values($this->emailPHIDs), 'info' => $this->loadCommitInfoForWorker($all_updates)), array('priority' => PhabricatorWorker::PRIORITY_ALERTS)); } return 0; }
/** * Convenience function to handle sending an SMS. */ public static function sendSMS(array $to_numbers, $body) { PhabricatorWorker::scheduleTask('PhabricatorSMSDemultiplexWorker', array('toNumbers' => $to_numbers, 'body' => $body), array('priority' => PhabricatorWorker::PRIORITY_ALERTS)); }
/** * Perform an actual resource allocation with a particular blueprint. * * @param DrydockBlueprint The blueprint to allocate a resource from. * @param DrydockLease Requested lease. * @return DrydockResource Allocated resource. * @task allocator */ private function allocateResource(DrydockBlueprint $blueprint, DrydockLease $lease) { $resource = $blueprint->allocateResource($lease); $this->validateAllocatedResource($blueprint, $resource, $lease); // If this resource was allocated as a pending resource, queue a task to // activate it. if ($resource->getStatus() == DrydockResourceStatus::STATUS_PENDING) { PhabricatorWorker::scheduleTask('DrydockResourceUpdateWorker', array('resourcePHID' => $resource->getPHID()), array('objectPHID' => $resource->getPHID())); } return $resource; }
public function scheduleUpdate($epoch = null) { PhabricatorWorker::scheduleTask('DrydockLeaseUpdateWorker', array('leasePHID' => $this->getPHID(), 'isExpireTask' => $epoch !== null), array('objectPHID' => $this->getPHID(), 'delayUntil' => $epoch)); }