generated from MapColonies/ts-server-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added polling jobs status system
- Loading branch information
Shlomi Koncha
committed
Aug 23, 2022
1 parent
786bccc
commit 4fcdad4
Showing
20 changed files
with
372 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { inject, singleton } from 'tsyringe'; | ||
import { HttpClient, IHttpRetryConfig } from '@map-colonies/mc-utils'; | ||
import { Logger } from '@map-colonies/js-logger'; | ||
import { BBox } from '@turf/helpers'; | ||
import { SERVICES } from '../common/constants'; | ||
import { ICallbackData, IConfig } from '../common/interfaces'; | ||
|
||
@singleton() | ||
export class CallbackClient extends HttpClient { | ||
public constructor(@inject(SERVICES.LOGGER) logger: Logger, @inject(SERVICES.CONFIG) private readonly config: IConfig) { | ||
super(logger, '', 'requestCallback', config.get<IHttpRetryConfig>('httpRetry')); | ||
} | ||
|
||
public async send(callbackUrl: string, params: ICallbackData): Promise<void> { | ||
this.logger.info(`send Callback request to URL: ${callbackUrl} with data ${JSON.stringify(params)}`); | ||
await this.post(callbackUrl, params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//TODO: replace with model | ||
export enum OperationStatus { | ||
PENDING = 'Pending', | ||
IN_PROGRESS = 'In-Progress', | ||
COMPLETED = 'Completed', | ||
FAILED = 'Failed', | ||
EXPIRED = 'Expired', | ||
ABORTED = 'Aborted', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { promises as fsPromise } from 'fs'; | ||
import { join } from 'path'; | ||
import { BBox, BBox2d } from '@turf/helpers/dist/js/lib/geojson'; | ||
|
||
export const getFileSize = async (filePath: string): Promise<number> => { | ||
const fileSizeInBytes = (await fsPromise.stat(filePath)).size; | ||
return Math.trunc(fileSizeInBytes); // Make sure we return an Integer | ||
}; | ||
|
||
export const generatePackageName = (dbId: string, zoomLevel: number, bbox: BBox): string => { | ||
const numberOfDecimals = 5; | ||
const bboxToString = bbox.map((val) => String(val.toFixed(numberOfDecimals)).replace('.', '_').replace(/-/g, 'm')).join(''); | ||
return `gm_${dbId.replace(/-/g, '_')}_${zoomLevel}_${bboxToString}.gpkg`; | ||
} | ||
|
||
export const getGpkgFilePath = (gpkgsLocation: string, packageName: string): string => { | ||
const packageDirectoryName = packageName.substr(0, packageName.lastIndexOf('.')); | ||
const packageFullPath = join(gpkgsLocation, packageDirectoryName as string, packageName); | ||
return packageFullPath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.