Skip to content

Commit

Permalink
PS-704 workflow concurrency (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem authored Oct 30, 2024
1 parent 7eeded3 commit 34133bf
Show file tree
Hide file tree
Showing 48 changed files with 1,534 additions and 591 deletions.
31 changes: 31 additions & 0 deletions databox/api/migrations/Version20241028171322.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241028171322 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE job_state ADD number SMALLINT NOT NULL DEFAULT 0');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE job_state DROP number');
}
}
10 changes: 10 additions & 0 deletions databox/api/src/Controller/Admin/JobStateCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Alchemy\AdminBundle\Controller\AbstractAdminCrudController;
use Alchemy\AdminBundle\Field\ArrayObjectField;
use Alchemy\AdminBundle\Field\IdField;
use Alchemy\AdminBundle\Filter\AssociationIdentifierFilter;
use Alchemy\Workflow\Doctrine\Entity\JobState;
use Alchemy\Workflow\State\JobState as JobStateModel;
use Alchemy\Workflow\State\JobState as ModelJobState;
Expand All @@ -18,9 +19,12 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Filter\ChoiceFilter;
use EasyCorp\Bundle\EasyAdminBundle\Filter\DateTimeFilter;
use EasyCorp\Bundle\EasyAdminBundle\Filter\NumericFilter;
use EasyCorp\Bundle\EasyAdminBundle\Filter\TextFilter;
use Symfony\Component\HttpFoundation\RedirectResponse;

class JobStateCrudController extends AbstractAdminCrudController
Expand Down Expand Up @@ -89,6 +93,9 @@ public function configureCrud(Crud $crud): Crud
return parent::configureCrud($crud)
->setEntityLabelInSingular('Job State')
->setEntityLabelInPlural('Job States')
->setDefaultSort([
'triggeredAt' => 'DESC',
])
->setSearchFields(['id']);
}

Expand All @@ -102,8 +109,10 @@ public function configureFilters(Filters $filters): Filters
'SKIPPED' => ModelJobState::STATUS_SKIPPED,
'RUNNING' => ModelJobState::STATUS_RUNNING,
]))
->add(AssociationIdentifierFilter::new('workflow'))
->add(DateTimeFilter::new('startedAt'))
->add(DateTimeFilter::new('endedAt'))
->add(NumericFilter::new('number'))
;
}

Expand All @@ -114,6 +123,7 @@ public function configureFields(string $pageName): iterable
yield TextField::new('jobId', 'Job ID');
yield DateTimeField::new('triggeredAt', 'Triggered At');
yield DateTimeField::new('startedAt', 'Started At');
yield NumberField::new('number');
yield ChoiceField::new('status', 'Status')
->setChoices([
'TRIGGERED' => ModelJobState::STATUS_TRIGGERED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function configureActions(Actions $actions): Actions
{
$viewWorkflow = Action::new('viewWorkflow', 'View', 'fa fa-eye')
->setHtmlAttributes(['target' => '_blank'])
->linkToUrl(fn (WorkflowState $entity): string => sprintf('%s/workflows/%s', $this->databoxClientBaseUrl, $entity->getId()));
->linkToUrl(fn (WorkflowState $entity): string => sprintf('%s/?_m=%s', $this->databoxClientBaseUrl, urlencode(sprintf('/workflows/%s', $entity->getId()))));

$cancel = Action::new('cancelWorkflow', 'Cancel Workflow', 'fas fa-ban')
->displayIf(fn (WorkflowState $entity) => ModelWorkflowState::STATUS_STARTED === $entity->getStatus())
Expand All @@ -66,6 +66,9 @@ public function configureCrud(Crud $crud): Crud
return parent::configureCrud($crud)
->setEntityLabelInSingular('Workflow State')
->setEntityLabelInPlural('Workflow States')
->setDefaultSort([
'startedAt' => 'DESC',
])
->setSearchFields(['id']);
}

Expand Down
14 changes: 7 additions & 7 deletions databox/api/src/Entity/Core/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class Attribute extends AbstractBaseAttribute implements ESIndexableDeleteDepend
final public const string GROUP_READ = 'attr:read';
final public const string GROUP_LIST = 'attr:index';

final public const ORIGIN_MACHINE = 0;
final public const ORIGIN_HUMAN = 1;
final public const ORIGIN_FALLBACK = 2;
final public const ORIGIN_INITIAL = 3;
final public const int ORIGIN_MACHINE = 0;
final public const int ORIGIN_HUMAN = 1;
final public const int ORIGIN_FALLBACK = 2;
final public const int ORIGIN_INITIAL = 3;

final public const ORIGIN_LABELS = [
self::ORIGIN_MACHINE => 'machine',
Expand All @@ -75,9 +75,9 @@ class Attribute extends AbstractBaseAttribute implements ESIndexableDeleteDepend
self::ORIGIN_INITIAL => 'initial',
];

final public const STATUS_VALID = 0;
final public const STATUS_REVIEW_PENDING = 1;
final public const STATUS_DECLINED = 2;
final public const int STATUS_VALID = 0;
final public const int STATUS_REVIEW_PENDING = 1;
final public const int STATUS_DECLINED = 2;

final public const STATUS_LABELS = [
self::STATUS_VALID => 'valid',
Expand Down
2 changes: 1 addition & 1 deletion databox/api/src/Entity/Core/AttributeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AttributeEntity extends AbstractUuidEntity
use CreatedAtTrait;
use UpdatedAtTrait;
use WorkspaceTrait;
public const TYPE_LENGTH = 100;
public const int TYPE_LENGTH = 100;

final public const string GROUP_READ = 'attr-entity:read';
final public const string GROUP_LIST = 'attr-entity:index';
Expand Down
8 changes: 4 additions & 4 deletions databox/api/src/Entity/Core/RenditionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ class RenditionRule extends AbstractUuidEntity
final public const string GROUP_READ = 'rendrule:read';
final public const string GROUP_LIST = 'rendrule:index';

final public const TYPE_USER = 0;
final public const TYPE_GROUP = 1;
final public const TYPE_WORKSPACE = 0;
final public const TYPE_COLLECTION = 1;
final public const int TYPE_USER = 0;
final public const int TYPE_GROUP = 1;
final public const int TYPE_WORKSPACE = 0;
final public const int TYPE_COLLECTION = 1;

final public const OBJECT_CLASSES = [
self::TYPE_WORKSPACE => Workspace::class,
Expand Down
8 changes: 4 additions & 4 deletions databox/api/src/Entity/Core/TagFilterRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class TagFilterRule extends AbstractUuidEntity
final public const string GROUP_READ = 'tfr:read';
final public const string GROUP_LIST = 'tfr:index';

final public const TYPE_USER = 0;
final public const TYPE_GROUP = 1;
final public const TYPE_WORKSPACE = 0;
final public const TYPE_COLLECTION = 1;
final public const int TYPE_USER = 0;
final public const int TYPE_GROUP = 1;
final public const int TYPE_WORKSPACE = 0;
final public const int TYPE_COLLECTION = 1;

final public const OBJECT_CLASSES = [
self::TYPE_WORKSPACE => Workspace::class,
Expand Down
12 changes: 6 additions & 6 deletions databox/api/src/Entity/Core/WorkspaceItemPrivacyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
interface WorkspaceItemPrivacyInterface
{
// Completely secret, only owner or granted users can view the item
public const SECRET = 0;
public const int SECRET = 0;

// Item is listed for users allowed in the workspace but content is not accessible
public const PRIVATE_IN_WORKSPACE = 1;
public const int PRIVATE_IN_WORKSPACE = 1;

// Open to users allowed in the workspace
public const PUBLIC_IN_WORKSPACE = 2;
public const int PUBLIC_IN_WORKSPACE = 2;

// Item is listed to every user, but content is not accessible
public const PRIVATE = 3;
public const int PRIVATE = 3;

// Public to every authenticated users
public const PUBLIC_FOR_USERS = 4;
public const int PUBLIC_FOR_USERS = 4;

// Public to everyone
public const PUBLIC = 5;
public const int PUBLIC = 5;

public const KEYS = [
WorkspaceItemPrivacyInterface::SECRET => 'secret',
Expand Down
2 changes: 1 addition & 1 deletion databox/api/src/Security/RenditionPermissionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class RenditionPermissionManager
{
private const IS_EMPTY = 0;
private const int IS_EMPTY = 0;
private const string ANONYMOUS = '~';

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/js/visual-workflow/src/Job/JobDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function JobDetail({
const values: Cells = [
[`Status`, undefined !== job.status ? jobStatuses[job.status] : '-'],
[`Duration`, job.duration ?? '-'],
[`#`, (job.number ?? '-').toString()],
[`Started At`, <DateValue date={job.startedAt}/>],
];

Expand All @@ -33,7 +34,7 @@ export default function JobDetail({
loading={rerunning}
onClick={() => {
setRerunning(true);
job.onRerun!(job.id).finally(() => {
job.onRerun!(job.jobId).finally(() => {
setRerunning(false);
});
}}
Expand Down
8 changes: 4 additions & 4 deletions lib/js/visual-workflow/src/VisualWorkflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ export default function VisualWorkflow({
...j,
onRerun: onRerunJob,
};
jobIndex[j.id] = nodeData;
jobIndex[j.jobId] = nodeData;

nodes.push({
type: 'jobNode',
id: j.id,
id: j.jobId,
position: {
x: stageXPadding * (1 + sIndex * 2) + nodeWith * sIndex,
y: nodeYPadding * (1 + jIndex * 2) + nodeHeight * jIndex,
Expand All @@ -77,9 +77,9 @@ export default function VisualWorkflow({
jobIndex[n].isDependency = true;

edges.push({
id: `${j.id}-${n}`,
id: `${j.jobId}-${n}`,
source: n,
target: j.id,
target: j.jobId,
className: 'job-edge',
})
})
Expand Down
5 changes: 3 additions & 2 deletions lib/js/visual-workflow/src/stories/workflowSample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export const workflowSample: Workflow = {
jobs: [
{
name: 'init',
id: 'init',
stateId: 'init-0',
jobId: 'init',
status: JobStatus.Success,
duration: '0.053s',
triggeredAt: '2023-05-24T10:22:25.495639+00:00',
Expand All @@ -30,7 +31,7 @@ export const workflowSample: Workflow = {
},
{
name: 'skipped',
id: 'skipped',
jobId: 'skipped',
status: JobStatus.Skipped,
},
],
Expand Down
4 changes: 3 additions & 1 deletion lib/js/visual-workflow/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export type Inputs = Record<string, any>;
export type Outputs = Record<string, any>;

export type Job = {
id: string;
stateId?: string;
jobId: string;
number?: number;
name: string;
status?: JobStatus | undefined;
errors?: JobError[] | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ Alchemy\Workflow\Doctrine\Entity\JobState:
name: status
type: smallint
nullable: false
number:
name: status
type: smallint
nullable: false
11 changes: 6 additions & 5 deletions lib/php/workflow/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
"require": {
"php": "^8.3",
"ext-json": "*",
"symfony/console": "^5.4 || ^6",
"symfony/yaml": "^6.2",
"symfony/console": "^5.4 || ^6 || ^7",
"symfony/yaml": "^6.2 || ^7",
"ramsey/uuid": "^4.2",
"symfony/process": "^6.3",
"symfony/expression-language": "^5.2 || ^6.2",
"symfony/property-access": "^5.2 || ^6.2"
"symfony/process": "^6.3 || ^7",
"symfony/expression-language": "^5.2 || ^6.2 || ^7",
"symfony/property-access": "^5.2 || ^6.2 || ^7"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.17",
"phpunit/phpunit": "^9.5",
"symfony/http-kernel": "^6 || ^7",
"symfony/var-dumper": "^5.4",
"doctrine/orm": "^2.14",
"symfony/messenger": "^6.4",
Expand Down
Loading

0 comments on commit 34133bf

Please sign in to comment.