feat: push expired tiles into job queue and major refactoring#3
feat: push expired tiles into job queue and major refactoring#3melancholiai merged 9 commits intomasterfrom
Conversation
| @@ -0,0 +1,74 @@ | |||
| import { Logger } from '@map-colonies/js-logger'; | |||
There was a problem hiding this comment.
file name should be lowercase
README.md
Outdated
|
|
||
| The output of the append command of `osm2pgsql` is an expire list of tiles in requested zoom levels. | ||
|
|
||
| The expired tiles list can be uploaded to a source of your choice, `s3` or `queue`. |
There was a problem hiding this comment.
- you dont upload to a queue, you push
- it should be mentioned that the queue is pgboss
- we should mention that its also possible to use to both.
src/index.ts
Outdated
| interface IError { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| error: (...data: any[]) => void; | ||
| } |
There was a problem hiding this comment.
better name, and move to common
src/containerConfig.ts
Outdated
| const httpClientConfig = config.get<object>('httpClient'); | ||
| const httpClient = httpClientFactory(httpClientConfig); |
There was a problem hiding this comment.
just use axios, there's no need for the factory as its not generic or anything.
src/containerConfig.ts
Outdated
| { token: ShutdownHandler, provider: { useValue: shutdownHandler } }, | ||
| { token: CLI_BUILDER, provider: { useFactory: cliBuilderFactory } }, | ||
| { token: CREATE_COMMAND_FACTORY, provider: { useFactory: createCommandFactory } }, | ||
| { token: CREATE_MANAGER_FACTORY, provider: { useFactory: createManagerFactory } }, | ||
| { token: APPEND_COMMAND_FACTORY, provider: { useFactory: appendCommandFactory } }, | ||
| { token: APPEND_MANAGER_FACTORY, provider: { useFactory: appendManagerFactory } }, | ||
| { token: SERVICES.CONFIG, provider: { useValue: config } }, | ||
| { token: SERVICES.LOGGER, provider: { useValue: logger } }, | ||
| { token: SERVICES.TRACER, provider: { useValue: tracer } }, | ||
| { token: SERVICES.HTTP_CLIENT, provider: { useValue: httpClient } }, | ||
| { token: SERVICES.CONFIG_STORE, provider: { useValue: configStore } }, | ||
| { token: EXIT_CODE, provider: { useValue: ExitCodes.SUCCESS } }, | ||
| ]; |
There was a problem hiding this comment.
i think this can be ordered better. config/logger should be first.
helm/README.md
Outdated
|
|
||
| **postgres:** | ||
|
|
||
| the postgres for osm2pgsql |
There was a problem hiding this comment.
i think better phrasing is needed.
something like this?
the postgres database target for osm2pgsql?
.gitignore
Outdated
| jest_html_reporters.html | ||
| reports | ||
|
|
||
| local.json No newline at end of file |
There was a problem hiding this comment.
mb local*.json ?
and new line is missing.
helm/README.md
Outdated
| *append* | ||
| - `cli.append.replicationUrl` - the source of replication | ||
| - `cli.append.limit.value` - should limit the amount of appends in a single run | ||
| - `cli.append.limit.enabled` - should limit the amount of appends in a single run |
There was a problem hiding this comment.
should? use a more decisive wording.
package.json
Outdated
| "@opentelemetry/api": "1.0.1", | ||
| "@opentelemetry/api-metrics": "0.23.0", | ||
| "@opentelemetry/instrumentation-http": "0.23.0", | ||
| "@types/mapbox__sphericalmercator": "^1.1.5", |
| import fsPromises from 'fs/promises'; | ||
| import { existsSync } from 'fs'; | ||
| import { Arguments } from 'yargs'; | ||
| import { isWebUri } from 'valid-url'; | ||
| import { AppendArguments, QueueSettings } from '../commands/append/interfaces'; | ||
| import { validateBySchema, ValidationResponse } from '../../validation/validator'; | ||
| import { LIMIT_SCHEMA, Limit, AppendEntity, QUEUE_SETTINGS_SCHEMA, APPEND_CONFIG_SCHEMA } from '../../validation/schemas'; | ||
| import { NOT_FOUND_INDEX } from '../../common/constants'; | ||
| import { CreateArguments } from '../commands/create/createFactory'; | ||
| import { DumpSourceType } from '../commands/create/constants'; | ||
|
|
||
| type InvalidHandler<T> = (validationResponse: ValidationResponse<T>) => void; | ||
| type CheckFunc<T> = (args: Arguments<T>) => Promise<boolean> | boolean; | ||
|
|
||
| export const limitCheck = (invalidHandler: InvalidHandler<unknown>): CheckFunc<AppendArguments> => { | ||
| const check: CheckFunc<AppendArguments> = (args) => { | ||
| const { limit } = args; | ||
| const validationResponse = validateBySchema<Limit>({ limit }, LIMIT_SCHEMA); | ||
| invalidHandler(validationResponse); | ||
| return true; | ||
| }; | ||
| return check; | ||
| }; | ||
|
|
||
| export const configCheck = (invalidHandler: InvalidHandler<unknown>): CheckFunc<AppendArguments> => { | ||
| const check: CheckFunc<AppendArguments> = async (args) => { | ||
| const { config } = args; | ||
| const configContent = await fsPromises.readFile(config, 'utf-8'); | ||
| const configContentAsJson: unknown = JSON.parse(configContent); | ||
| const validationResponse = validateBySchema<AppendEntity[]>(configContentAsJson, APPEND_CONFIG_SCHEMA); | ||
| invalidHandler(validationResponse); | ||
| return true; | ||
| }; | ||
| return check; | ||
| }; | ||
|
|
||
| export const uploadTargetsCheck = (invalidHandler: InvalidHandler<unknown>): CheckFunc<AppendArguments> => { | ||
| const check: CheckFunc<AppendArguments> = (args) => { | ||
| const { uploadTargets } = args; | ||
| if (uploadTargets.indexOf('queue') !== NOT_FOUND_INDEX) { | ||
| const { name, minZoom, maxZoom } = args; | ||
| const request: QueueSettings = { | ||
| name: name as string, | ||
| minZoom: minZoom as number, | ||
| maxZoom: maxZoom as number, | ||
| }; | ||
| const validationResponse = validateBySchema<QueueSettings>(request, QUEUE_SETTINGS_SCHEMA); | ||
| invalidHandler(validationResponse); | ||
| } | ||
| return true; | ||
| }; | ||
| return check; | ||
| }; | ||
|
|
||
| export const dumpSourceCheck = (): CheckFunc<CreateArguments> => { | ||
| const check: CheckFunc<CreateArguments> = (args) => { | ||
| const { dumpSourceType, dumpSource } = args; | ||
|
|
||
| const errorPrefix = `provided dump source of type ${dumpSourceType} is not valid`; | ||
| if (dumpSourceType === DumpSourceType.LOCAL_FILE) { | ||
| if (!existsSync(dumpSource)) { | ||
| throw new Error(`${errorPrefix}, ${dumpSource} does not exist locally`); | ||
| } | ||
| } else if (isWebUri(dumpSource) === undefined) { | ||
| throw new Error(`${errorPrefix}, ${dumpSource} is not a valid web uri`); | ||
| } | ||
|
|
||
| return true; | ||
| }; | ||
| return check; | ||
| }; |
There was a problem hiding this comment.
some documentation on the functions would be nice.
src/validation/validator.ts
Outdated
| public constructor(@inject(SERVICES.LOGGER) private readonly logger: Logger) { | ||
| this.ajv = new Ajv({ $data: true }); | ||
| ajvKeywords.default(this.ajv); | ||
| export function validateBySchema<T>(content: unknown, schema: JSONSchemaType<T>): ValidationResponse<T> { |
There was a problem hiding this comment.
its more of an ajv wrapper, than validate by schema.
Closes #2