Skip to content

refactor: Create cron-node (MAPCO-10228) - #41

Open
Powfu2 wants to merge 4 commits into
masterfrom
feat/add-node-cron
Open

refactor: Create cron-node (MAPCO-10228)#41
Powfu2 wants to merge 4 commits into
masterfrom
feat/add-node-cron

Conversation

@Powfu2

@Powfu2 Powfu2 commented Jul 19, 2026

Copy link
Copy Markdown

Create cron-node,
upgrade all libraries,
add ci
add tests

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown

🎫 Related Jira Issue: MAPCO-10228

@Powfu2
Powfu2 requested a review from eyalr1100 July 19, 2026 08:32
Comment thread config/default.json Outdated
{
"telemetry": {
"shared": {
"serviceName": "planet-dumper"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

don't need

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

do shared: {}

Comment on lines +13 to +17
{{- if .Values.cron.enabled }}
TARGET: {{ .Values.cron.target | quote }}
CRON_EXPRESSION: {{ .Values.cron.schedule | quote }}
RUN_ON_INIT: {{ .Values.cron.runOnInit | quote }}
{{- end }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like with .values.cron but that's me

Comment thread src/commands/common/pipelineRunner.ts Outdated
try {
const state = await manager.getState(stateSource);

// pre cleanup

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

remove ai comments

Comment thread src/commands/common/pipelineRunner.ts Outdated
Comment on lines +118 to +123
if (cleanupMode === 'post-clean-workdir') {
await emptyDirectory(join(WORKDIR, state));
} else if (cleanupMode === 'post-clean-others') {
await emptyDirectory(WORKDIR, [state]);
} else if (cleanupMode === 'post-clean-all') {
await emptyDirectory(WORKDIR);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

UGLY! maybe switch? Maybe enum (as const, satisfy, whatever)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

WTF

Comment thread src/commands/common/types.ts Outdated
Comment on lines +5 to +14
export const PG_DUMP_CLEANUP_CHOICES: CleanupMode[] = ['none', 'pre-clean-others', 'post-clean-others'];

export const CREATE_CLEANUP_CHOICES: ExtendedCleanupMode[] = [
'none',
'pre-clean-others',
'post-clean-others',
'post-clean-workdir',
'post-clean-all',
];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AN ARRAY??? WITH LOW CARDINALITY VALUES???

Comment on lines +35 to +50
const buildArgv = (overrides: Partial<ScheduleArguments>): Arguments<ScheduleArguments> => ({
// eslint-disable-next-line @typescript-eslint/naming-convention -- required by yargs' Arguments<T> shape
_: [],
$0: 'planet-dumper',
outputFormat: 'dump_{state}_{timestamp}.pbf',
stateSource: '1',
cleanupMode: 'none',
s3Acl: 'private',
dumpServerHeaders: [],
resume: false,
info: false,
target: 'pg_dump',
cronExpression: '* * * * * *',
runOnInit: false,
...overrides,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I feel like this could be in a different class

Comment on lines +55 to +59
for (const task of getTasks().values()) {
void task.destroy();
}
vi.restoreAllMocks();
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

foreach

Comment on lines +65 to +66
// gate the first run on an explicit signal instead of a fixed delay, so "still in-flight"
// is guaranteed rather than timing-dependent on how fast the test happens to run

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

.

Comment on lines +42 to +62
const disabledArstotzkaConfig: ArstotzkaConfig = {
enabled: false,
services: { planetDumperPg: 'pg-service', planetDumperNg: 'ng-service' },
mediator: {
timeout: 1000,
enableRetryStrategy: false,
retryStrategy: {},
},
};

const enabledArstotzkaConfig: ArstotzkaConfig = {
enabled: true,
services: { planetDumperPg: 'pg-service', planetDumperNg: 'ng-service' },
mediator: {
timeout: 1000,
enableRetryStrategy: false,
retryStrategy: {},
actiony: { url: 'http://actiony.example.com' },
locky: { url: 'http://locky.example.com' },
},
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

instead of writing the same cofnig twice with one variable flipped, just use ... with overrides

Comment thread .release-please-manifest.json Outdated
@@ -0,0 +1,3 @@
{
".": "6.1.0"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The master tag says 4.0.0

@eyalr1100
eyalr1100 self-requested a review July 22, 2026 06:32
Comment thread src/commands/create/createManager.ts
Comment thread src/commands/create/createManager.ts
Comment thread src/commands/pgDump/pgDumpFactory.ts Outdated
Comment thread src/commands/schedule/scheduleFactory.ts Outdated
Comment on lines +114 to +119
let exitCode = ExitCodes.GENERAL_ERROR;

if (error instanceof ErrorWithExitCode) {
exitCode = error.exitCode;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
let exitCode = ExitCodes.GENERAL_ERROR;
if (error instanceof ErrorWithExitCode) {
exitCode = error.exitCode;
}
const exitCode = error instanceof ErrorWithExitCode ? error.exitCode : ExitCodes.GENERAL_ERROR;

}): DependencyContainer => {
const logger = overrides.logger ?? buildLogger();
const config = overrides.config ?? buildConfig();
const manager = overrides.manager ?? ({} as CreateManager);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no as

Comment thread tests/unit/commands/create/createFactory.spec.ts
Comment thread tests/unit/commands/create/createFactory.spec.ts Outdated
Comment thread tests/unit/commands/create/createManager.spec.ts
Comment thread package.json Outdated
"@map-colonies/config": "^4.0.1",
"@map-colonies/js-logger": "^5.0.0",
"@map-colonies/read-pkg": "^2.0.0",
"@map-colonies/schemas": "https://ghatmpstorage.blob.core.windows.net/npm-packages/schemas-213f62397c5cf2f0f83694fbcdaf18665b00bd6e.tgz",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

don't forget to change

Comment on lines +18 to +20
if (!arstotzkaConfig.enabled) {
return {};
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

imo this function shouldn't be the one checking if arstotzka is enabled

Comment thread src/commands/create/createFactory.ts
Comment thread src/commands/create/createFactory.ts

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You didn't fix this file at all

Comment thread src/commands/pgDump/pgDumpManager.ts
const runCreatePipelineMock = vi.mocked(runCreatePipeline);
const terminateChildrenMock = vi.mocked(terminateChildren);

const buildLogger = (): Logger => ({ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() }) as unknown as Logger;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

fix this, as unknown as is a bad habbit, I'd rather you create a vi.fn() for every logger function instead
Also I don't think you need to test the logs so you can remove logger altogether

Comment thread tests/unit/commands/create/createFactory.spec.ts
Comment thread tests/unit/commands/create/createManager.spec.ts
Comment thread tests/unit/commands/create/createManager.spec.ts

const spawnChildMock = vi.mocked(spawnChild);

const buildAxios = (): AxiosInstance => ({ get: vi.fn() }) as unknown as AxiosInstance;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use nock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants