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" | |||
| import { join, dirname } from 'node:path'; | ||
| import { createReadStream } from 'node:fs'; |
| const currentNgDumpDir = join(WORKDIR, this.state, NG_DUMP_DIR); | ||
| const ngDumpOutputPath = join(currentNgDumpDir, ngDumpName); |
There was a problem hiding this comment.
every fs function should live in fs repository
| import type { PgDumpPipelineArgs } from '../common/pipelineRunner'; | ||
| import { runPgDumpPipeline } from '../common/pipelineRunner'; |
| import type { ConfigType } from '@common/config'; | ||
| import { FsRepository } from '@src/fsRepository/fsRepository'; | ||
| import { nameFormat } from '../common/helpers'; | ||
| import type { CleanupMode } from '../common/types'; |
| stateSourceCheck(stateSource); | ||
|
|
||
| const target = config.get('cli.schedule.target'); | ||
| if (target === undefined) { | ||
| throw new CheckError('cli.schedule.target must be configured to run the schedule command', 'cli.schedule.target', target); | ||
| } | ||
|
|
||
| const cronExpression = config.get('cli.schedule.cronExpression'); | ||
| if (cronExpression === undefined) { | ||
| throw new CheckError( | ||
| 'cli.schedule.cronExpression must be configured to run the schedule command', | ||
| 'cli.schedule.cronExpression', | ||
| cronExpression | ||
| ); |
There was a problem hiding this comment.
all these checks are stuff that schemas should solve. If an undefined cli.schedule.target causes an error, just require it
| }): DependencyContainer => { | ||
| const logger = overrides.logger ?? buildLogger(); | ||
| const config = overrides.config ?? buildConfig(); | ||
| const manager = overrides.manager ?? ({} as CreateManager); |
| 'cli.stateSource': '1', | ||
| 'cli.outputFormat': 'dump_{state}_{timestamp}.pbf', | ||
| 'cli.cleanupMode': 'none', | ||
| 'cli.resume': false, | ||
| 'cli.info': false, | ||
| 's3.endpoint': 'https://s3.example.com', | ||
| 's3.bucketName': 'bucket', | ||
| 's3.acl': 'private', | ||
| 'cli.dumpServer.endpoint': undefined, | ||
| 'cli.dumpServer.headers': [], | ||
| ...overrides, |
There was a problem hiding this comment.
consider putting non test specific configs in test.json
| const dependencyContainer = buildDependencyContainer({ config: validConfig() }); | ||
| const { handler } = createCommandFactory(dependencyContainer); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/naming-convention -- required by yargs' Arguments<T> shape |
There was a problem hiding this comment.
if you disable it every five lines just disable the rule for the whole file
| }); | ||
|
|
||
| it('collects osmium info and attaches it to the metadata when shouldCollectInfo is true', async () => { | ||
| spawnChildMock.mockResolvedValue({ exitCode: 0, stdout: '{"num_nodes":1}', stderr: '' } as never); |
| "@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", |
Create cron-node,
upgrade all libraries,
add ci
add tests