Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VACMS-16853: next-build git information for content release #16923

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docroot/modules/custom/va_gov_build_trigger/drush.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ services:
- '@logger.factory'
tags:
- { name: drush.command }
va_gov_build_trigger.next_content_release_commands:
class: \Drupal\va_gov_build_trigger\Commands\NextContentReleaseCommands
arguments:
- '@va_gov_build_trigger.next_release_state_manager'
- '@va_gov_build_trigger.build_scheduler'
- '@va_gov_content_release.request'
- '@state'
- '@logger.factory'
tags:
- { name: drush.command }
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?php

namespace Drupal\va_gov_build_trigger\Commands;

use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\State\StateInterface;
use Drupal\va_gov_build_trigger\Controller\ContentReleaseNotificationController;
use Drupal\va_gov_build_trigger\EventSubscriber\ContinuousReleaseSubscriber;
use Drupal\va_gov_build_trigger\Service\BuildSchedulerInterface;
use Drupal\va_gov_build_trigger\Service\ReleaseStateManager;
use Drupal\va_gov_build_trigger\Service\ReleaseStateManagerInterface;
use Drupal\va_gov_content_release\Request\RequestInterface;
use Drush\Commands\DrushCommands;

/**
* A Drush interface to the content release.
*/
class NextContentReleaseCommands extends DrushCommands {
/**
* The release state manager.
*
* @var \Drupal\va_gov_build_trigger\Service\ReleaseStateManagerInterface
*/
protected $releaseStateManager;

/**
* The build scheduler service.
*
* @var \Drupal\va_gov_build_trigger\Service\BuildSchedulerInterface
*/
protected $buildScheduler;

/**
* The content release request service.
*
* @var \Drupal\va_gov_content_release\Request\RequestInterface
*/
protected $requestService;

/**
* The state management service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;

/**
* Constructor.
*
* @param \Drupal\va_gov_build_trigger\Service\ReleaseStateManagerInterface $releaseStateManager
* The release state manager service.
* @param \Drupal\va_gov_build_trigger\Service\BuildSchedulerInterface $buildScheduler
* The build scheduler service.
* @param \Drupal\va_gov_content_release\Request\RequestInterface $requestService
* The request service.
* @param \Drupal\Core\State\StateInterface $state
* The state service.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerChannelFactory
* A logger channel factory.
*/
public function __construct(
ReleaseStateManagerInterface $releaseStateManager,
BuildSchedulerInterface $buildScheduler,
RequestInterface $requestService,
StateInterface $state,
LoggerChannelFactoryInterface $loggerChannelFactory
) {
$this->releaseStateManager = $releaseStateManager;
$this->buildScheduler = $buildScheduler;
$this->requestService = $requestService;
$this->state = $state;
$this->logger = $loggerChannelFactory->get('va_gov_build_trigger');
}

/**
* Reset the content release state.
*
* @command va-gov:content-release:next-reset-state
*/
public function resetState() {
$this->releaseStateManager->resetState();
$this->logger()->info('Content release state has been reset to \'ready\'.');
}

/**
* Advance the state like an external system would do through HTTP.
*
* @param string $state
* Required. Declare which state to advance to.
*
* @command va-gov:content-release:next-advance-state
*/
public function advanceState($state) {
$is_allowed_notification = in_array($state, ContentReleaseNotificationController::allowedNotifications());
$can_transition = $this->releaseStateManager->canAdvanceStateTo($state);
$can_transition = ($can_transition === ReleaseStateManager::STATE_TRANSITION_OK);

if (!$is_allowed_notification || !$can_transition) {
$this->logger()->error('State cannot be advanced to @state', [
'@state' => $state,
]);
return;
}

$this->releaseStateManager->advanceStateTo($state);
$this->logger()->info('State has been advanced to @state', [
'@state' => $state,
]);
}

/**
* Get the current release state.
*
* @command va-gov:content-release:next-get-state
*/
public function getReleaseState() {
$state = $this->releaseStateManager->getState();
$this->io()->write($state);
}

/**
* Make sure builds are going out at least hourly during business hours.
*
* @command va-gov:content-release:next-check-scheduled
*/
public function checkScheduledBuild() {
$this->buildScheduler->checkScheduledBuild();
}

/**
* If the state is stale, reset the state.
*
* @command va-gov:content-release:next-check-stale
*/
public function checkStale() {
if ($this->releaseStateManager->releaseStateIsStale()) {
$this->resetState();
$this->requestService->submitRequest('Submitting new request due to staleness.');
}
}

/**
* Check continuous release state.
*
* @command va-gov:content-release:next-is-continuous-release-enabled
*/
public function checkContinuousReleaseState() {
$this->io()->writeln(print_r($this->state->get(ContinuousReleaseSubscriber::CONTINUOUS_RELEASE_ENABLED, FALSE)));
}

/**
* Toggle continuous release.
*
* @command va-gov:content-release:next-toggle-continuous
*/
public function toggleContinuousRelease() {
$current = $this->state->get(ContinuousReleaseSubscriber::CONTINUOUS_RELEASE_ENABLED, FALSE);
$this->state->set(ContinuousReleaseSubscriber::CONTINUOUS_RELEASE_ENABLED, !$current);
$status_text = (!$current === TRUE ? 'enabled' : 'disabled');
$this->io()->writeln('Continuous release is now ' . $status_text);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public function contentEditsShouldTriggerFrontendBuild() : bool {
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
public function triggerFrontendBuild() : void {
$this->getEnvironment()->triggerFrontendBuild();
public function triggerFrontendBuild(array $payload) : void {
$this->getEnvironment()->triggerFrontendBuild($payload);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getWebUrl() : string;
/**
* Trigger the frontend web build.
*/
public function triggerFrontendBuild() : void;
public function triggerFrontendBuild(array $payload) : void;

/**
* Should this environment trigger a frontend content deploy?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritDoc}
*/
public function triggerFrontendBuild() : void {
public function triggerFrontendBuild(array $payload) : void {
// Write different files based on the frontend.
$destination = $payload['frontend'] === 'next_build' ? 'public://.next-buildrequest' : 'public://.buildrequest';

// The existence of this file triggers a content release.
// See scripts/queue_runner/queue_runner.sh.
$this->filesystem->saveData('build plz', 'public://.buildrequest', FileSystemInterface::EXISTS_REPLACE);
$this->filesystem->saveData('build plz', $destination, FileSystemInterface::EXISTS_REPLACE);
$this->messenger()->addStatus('A request to rebuild the front end has been submitted.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function releaseContinuously(ReleaseStateTransitionEvent $event) {

if ($is_complete && $is_enabled) {
$this->runDuringBusinessHours(function () {
$this->requestService->submitRequest('Continuous release');
$this->requestService->submitRequest('Continuous release', ['frontend' => 'content_build']);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public function process(Job $job) {
switch ($this->releaseStateManager->canAdvanceStateTo(ReleaseStateManager::STATE_DISPATCHED)) {
case ReleaseStateManager::STATE_TRANSITION_OK:
try {
$this->environmentDiscovery->triggerFrontendBuild();
$payload = $job->getPayload();
$this->environmentDiscovery->triggerFrontendBuild($payload);
}
catch (\Exception $e) {
return JobResult::failure('Release dispatch failed with error: ' . $e->getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ public function process(Job $job) {
switch ($this->releaseStateManager->canAdvanceStateTo(ReleaseStateManager::STATE_REQUESTED)) {
case ReleaseStateManager::STATE_TRANSITION_OK:
$payload = $job->getPayload();
$dispatch_job = Job::create('va_gov_content_release_dispatch', ['placeholder' => 'placeholder']);
$dispatch_job = Job::create('va_gov_content_release_dispatch', [
'placeholder' => 'placeholder',
'frontend' => $payload['frontend'],
]);
$this->dispatchQueue->enqueueJob($dispatch_job);
$this->releaseStateManager->advanceStateTo(ReleaseStateManager::STATE_REQUESTED);
$message = 'Content release dispatch has been queued. Reason: @reason';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritDoc}
*/
public function triggerFrontendBuild() : void {
public function triggerFrontendBuild(array $payload) : void {
try {
if ($this->pendingWorkflowRunExists()) {
$vars = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Drupal\va_gov_build_trigger\Service;

use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\State\StateInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* A service for managing the state of the next release.
*/
class NextReleaseStateManager extends ReleaseStateManager {
public const STATE_KEY = 'va_gov_build_trigger.next_release_state';

/**
* ReleaseStateManager constructor.
*
* @param \Drupal\Core\State\StateInterface $state
* The site state service.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
* The site event dispatcher service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The site time service.
*/
public function __construct(StateInterface $state, EventDispatcherInterface $dispatcher, TimeInterface $time) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [PHP_CodeSniffer] <Generic.CodeAnalysis.UselessOverridingMethod.Found> reported by reviewdog 🐶
Possible useless method overriding detected

parent::__construct($state, $dispatcher, $time);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ services:
va_gov_build_trigger.release_state_manager:
class: Drupal\va_gov_build_trigger\Service\ReleaseStateManager
arguments: ['@state', '@event_dispatcher', '@datetime.time']
va_gov_build_trigger.next_release_state_manager:
class: Drupal\va_gov_build_trigger\Service\NextReleaseStateManager
arguments: ['@state', '@event_dispatcher', '@datetime.time']
va_gov.site_status:
class: Drupal\va_gov_build_trigger\SiteStatus\SiteStatus
arguments: ['@state']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(
* va-gov-content-release-request-submit
*/
public function submitRequest(string $reason = 'Build requested via Drush.') {
$this->requestService->submitRequest($reason);
$this->requestService->submitRequest($reason, ['frontend' => 'content_build']);
$this->io()->success('Content Release requested; check the queue for status.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function handleNodeUpdate(VaNodeInterface $node) : void {
$strategy = $this->strategyPluginManager->getStrategy($strategyId);
if ($strategy->shouldTriggerContentRelease($node)) {
$reason = $strategy->getReasonMessage($node);
$this->request->submitRequest($reason);
$this->request->submitRequest($reason, ['frontend' => 'content_build']);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ public function isUnderTest(FormStateInterface $form_state): bool {
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->reporter->reportInfo($this->t('Content release requested successfully.'));
if (!$this->isUnderTest($form_state)) {
$this->request->submitRequest('Build requested via form.');
// Determine which frontend submitted the request based on field presence.
$frontend = isset($form["build_request"]["next_build_selection"]) ? 'next_build' : 'content_build';
$this->request->submitRequest('Build requested via form.', ['frontend' => $frontend]);
}
else {
$this->reporter->reportInfo($this->t('Build request skipped; form is under test.'));
Expand Down
Loading
Loading