Skip to content

Commit

Permalink
feat: create constants, queue types and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Jul 17, 2024
1 parent 1748c0b commit a62ca97
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 2 deletions.
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/server-analysis-manager-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"@privateaim/kit": "^0.8.0",
"@privateaim/server-kit": "^0.8.0"
},
"devDependencies": {
"docker-scan": "^1.1.0"
},
"gitHead": "5d3b6f4ce1edf2383bdfbf66e913a08c8a3a2e40",
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

export * from './builder';
export * from './core';
export * from './master-images';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2023-2024.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

import { QueueRouterRoutingType } from '@privateaim/server-kit';

export enum MasterImagesEvent {
SYNCHRONISING = 'synchronizing',
SYNCHRONIZED = 'synchronized',
SYNCHRONIZATION_FAILED = 'synchronizationFailed',

BUILDING = 'building',
BUILT = 'built',
BUILD_FAILED = 'buildFailed',

PUSHING = 'pushing',
PUSHED = 'pushed',
PUSH_FAILED = 'pushFailed',
}

export enum MasterImagesCommand {
SYNCHRONIZE = 'synchronize',
}

export const MasterImagesEventQueueRouterRouting = {
type: QueueRouterRoutingType.PUB_SUB,
key: 'analysisMasterImagesEvents',
};

export const MasterImagesTaskQueueRouterRouting = {
type: QueueRouterRoutingType.WORK,
key: 'analysisMasterImagesCommands',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (c) 2024.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

export * from './constants';
export * from './queue';
export * from './types';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2023-2024.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

import type { QueueRouterPayload } from '@privateaim/server-kit';
import { buildQueueRouterPublishPayload } from '@privateaim/server-kit';
import { cleanupPayload } from '../../utils';
import { MasterImagesEventQueueRouterRouting, MasterImagesTaskQueueRouterRouting } from './constants';
import type { MasterImagesCommandContext, MasterImagesEventContext } from './types';

export function buildMasterImagesTaskQueueRouterPayload(
context: MasterImagesCommandContext,
) : QueueRouterPayload {
return buildQueueRouterPublishPayload({
type: context.command,
data: cleanupPayload(context.data),
metadata: {
routing: MasterImagesTaskQueueRouterRouting,
},
});
}

export function buildMasterImagesEventQueueRouterPayload(
context: MasterImagesEventContext,
) : QueueRouterPayload {
return buildQueueRouterPublishPayload({
type: context.event,
data: cleanupPayload(context.data),
metadata: {
routing: MasterImagesEventQueueRouterRouting,
},
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2023-2024.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

import type { Group, Image } from 'docker-scan';
import type { MasterImagesCommand, MasterImagesEvent } from './constants';

export type MasterImagesBasePayload = {
error?: Error
};

export type MasterImagesSynchronizeCommandContext = {
command: `${MasterImagesCommand.SYNCHRONIZE}`,
data: MasterImagesBasePayload,
};

export type MaterImagesSynchronizedPayload = MasterImagesBasePayload & {
images: Image[],
groups: Group[]
};
export type MasterImagesSynchronizedEventContext = {
data: MaterImagesSynchronizedPayload,
event: `${MasterImagesEvent.SYNCHRONIZED}`;
};
export type MasterImagesSynchronizingEventContext = {
data: MasterImagesBasePayload,
event: `${MasterImagesEvent.SYNCHRONISING}`;
};
export type MasterImagesSynchronizationFailedEventContext = {
data: MasterImagesBasePayload,
event: `${MasterImagesEvent.SYNCHRONIZATION_FAILED}`;
};

export type MasterImagesBuildEventContext = {
data: MasterImagesBasePayload,
event: `${MasterImagesEvent.BUILD_FAILED}` |
`${MasterImagesEvent.BUILDING}` |
`${MasterImagesEvent.BUILT}`;
};

export type MasterImagesPushEventContext = {
data: MasterImagesBasePayload,
event: `${MasterImagesEvent.PUSH_FAILED}` |
`${MasterImagesEvent.PUSHING}` |
`${MasterImagesEvent.PUSHED}`;
};

export type MasterImagesCommandContext = MasterImagesSynchronizeCommandContext;
export type MasterImagesEventContext = MasterImagesSynchronizedEventContext |
MasterImagesSynchronizingEventContext |
MasterImagesSynchronizationFailedEventContext |
MasterImagesBuildEventContext |
MasterImagesPushEventContext;
3 changes: 1 addition & 2 deletions packages/server-analysis-manager-kit/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export enum ComponentName {
BUILDER = 'builder',
CORE = 'core',
MASTER_IMAGES = 'masterImages',
}

export enum ErrorCode {
Expand All @@ -16,5 +17,3 @@ export enum ErrorCode {
REGISTRY_PROJECT_NOT_FOUND = 'registryProjectNotFound',
NONE = 'none',
}

export const ROUTER_QUEUE_ROUTING_KEY = 'tm.router';

0 comments on commit a62ca97

Please sign in to comment.