refactor: Create cron-node (MAPCO-10228) - #41
Conversation
|
🎫 Related Jira Issue: MAPCO-10228 |
| { | ||
| "telemetry": { | ||
| "shared": { | ||
| "serviceName": "planet-dumper" |
| {{- if .Values.cron.enabled }} | ||
| TARGET: {{ .Values.cron.target | quote }} | ||
| CRON_EXPRESSION: {{ .Values.cron.schedule | quote }} | ||
| RUN_ON_INIT: {{ .Values.cron.runOnInit | quote }} | ||
| {{- end }} |
There was a problem hiding this comment.
I like with .values.cron but that's me
| try { | ||
| const state = await manager.getState(stateSource); | ||
|
|
||
| // pre cleanup |
| 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); |
There was a problem hiding this comment.
UGLY! maybe switch? Maybe enum (as const, satisfy, whatever)?
| 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', | ||
| ]; | ||
|
|
There was a problem hiding this comment.
AN ARRAY??? WITH LOW CARDINALITY VALUES???
| 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, | ||
| }); |
There was a problem hiding this comment.
I feel like this could be in a different class
| for (const task of getTasks().values()) { | ||
| void task.destroy(); | ||
| } | ||
| vi.restoreAllMocks(); | ||
| }); |
| // 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 |
| 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' }, | ||
| }, | ||
| }; |
There was a problem hiding this comment.
instead of writing the same cofnig twice with one variable flipped, just use ... with overrides
| @@ -0,0 +1,3 @@ | |||
| { | |||
| ".": "6.1.0" | |||
| let exitCode = ExitCodes.GENERAL_ERROR; | ||
|
|
||
| if (error instanceof ErrorWithExitCode) { | ||
| exitCode = error.exitCode; | ||
| } | ||
|
|
There was a problem hiding this comment.
| 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); |
| "@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", |
| if (!arstotzkaConfig.enabled) { | ||
| return {}; | ||
| } |
There was a problem hiding this comment.
imo this function shouldn't be the one checking if arstotzka is enabled
| 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; |
There was a problem hiding this comment.
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
|
|
||
| const spawnChildMock = vi.mocked(spawnChild); | ||
|
|
||
| const buildAxios = (): AxiosInstance => ({ get: vi.fn() }) as unknown as AxiosInstance; |
Create cron-node,
upgrade all libraries,
add ci
add tests