Skip to content

Commit

Permalink
[Update] Updated the deployment subscriber to take into account the n…
Browse files Browse the repository at this point in the history
…ew workflow for managing the lifecycle of applications.
  • Loading branch information
supermalang committed Nov 13, 2023
1 parent 2806cc9 commit a89cf54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/EventSubscriber/CreditTransactionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Workflow\Event\Event;
use Symfony\Component\Workflow\Registry;
use App\Entity\CreditTransaction;
use App\Entity\Organization;
Expand Down
15 changes: 9 additions & 6 deletions src/EventSubscriber/DeploymentsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Symfony\Component\Workflow\Event\Event;
use App\Repository\ServiceRepository;

use function PHPUnit\Framework\arrayHasKey;

class DeploymentsSubscriber implements EventSubscriberInterface
{
private $em;
Expand Down Expand Up @@ -54,8 +56,8 @@ public static function getSubscribedEvents():array
public function setDeploymentOrganizationAppAndPlan(BeforeEntityPersistedEvent $event)
{
$entity = $event->getEntityInstance();

if ($entity instanceof Deployments) {
if ($entity instanceof Deployments && null == $entity->getId()) {
$request = $this->requestStack->getCurrentRequest();
$deploymentplan = $request->query->get('plan') ?? null;
$appid = $request->query->get('id') ?? null;
Expand Down Expand Up @@ -92,7 +94,7 @@ public function launchNewDeployment(AfterEntityPersistedEvent $event)
{
$entity = $event->getEntityInstance();

if ($entity instanceof Deployments) {
if ($entity instanceof Deployments && "pending_deployment" == $entity->getStatus()) {
$this->bus->dispatch(new LaunchDeploymentMessage($entity->getId()));
}
}
Expand All @@ -101,8 +103,9 @@ public function launchNewDeployment(AfterEntityPersistedEvent $event)
public function start_app(Event $event)
{
$deployment = $event->getSubject();

if ($deployment instanceof Deployments) {

/** We don't want the deployment to launch for a second time if we just have deployed */
if ($deployment instanceof Deployments && !in_array("deploying", $event->getTransition()->getFroms())) {
$service = $this->serviceRepository->find($deployment->getService()->getId());
$start_tags = $service->getStartTags();
$job_tags = is_array($start_tags) ? implode(', ', $start_tags) : $start_tags;
Expand All @@ -115,7 +118,7 @@ public function start_app(Event $event)
public function stop_app(Event $event)
{
$deployment = $event->getSubject();

if ($deployment instanceof Deployments) {
$service = $this->serviceRepository->find($deployment->getService()->getId());
$stop_tags = $service->getStopTags();
Expand Down

0 comments on commit a89cf54

Please sign in to comment.