@hestia-earth/pipeline-utils 0.8.2 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.9.1](https://gitlab.com/hestia-earth/hestia-pipeline-utils/compare/v0.9.0...v0.9.1) (2023-04-18)
6
+
7
+
8
+ ### Features
9
+
10
+ * **progress:** log time since datetime ([1dc6664](https://gitlab.com/hestia-earth/hestia-pipeline-utils/commit/1dc66648da05cbb4049b5c6cf46796c206e18870))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **progress:** fix wrong step name ([2f17942](https://gitlab.com/hestia-earth/hestia-pipeline-utils/commit/2f179425fd682f8850f01e0683d24b7a9737848a))
16
+
17
+ ## [0.9.0](https://gitlab.com/hestia-earth/hestia-pipeline-utils/compare/v0.8.2...v0.9.0) (2023-04-18)
18
+
19
+
20
+ ### ⚠ BREAKING CHANGES
21
+
22
+ * **progress:** `@hestia-earth/api` required above version `0.18.0`
23
+
24
+ ### Features
25
+
26
+ * **progress:** log time for each step ([51bf21b](https://gitlab.com/hestia-earth/hestia-pipeline-utils/commit/51bf21be9cd1cfa2124ff480da9c31a228632e60))
27
+
5
28
  ### [0.8.2](https://gitlab.com/hestia-earth/hestia-pipeline-utils/compare/v0.8.1...v0.8.2) (2023-04-06)
6
29
 
7
30
 
@@ -1,3 +1,4 @@
1
+ import { FileProgress } from '@hestia-earth/api';
1
2
  import { IFunctionParam } from './s3';
2
3
  export declare enum publishFunctionSuffix {
3
4
  Success = "Done",
@@ -15,6 +16,6 @@ export declare class HestiaError extends Error {
15
16
  stack: string;
16
17
  };
17
18
  }
18
- export declare const handleError: (step: string, params: IFunctionParam, time?: number, Bucket?: string) => (err: HestiaError) => import("rxjs").Observable<import("aws-sdk/lib/request").PromiseResult<import("aws-sdk/clients/sns").PublishResponse, import("aws-sdk").AWSError>>;
19
- export declare const handleSuccess: (step: string, params: IFunctionParam, time?: number, Bucket?: string) => (details?: any) => import("rxjs").Observable<import("aws-sdk/lib/request").PromiseResult<import("aws-sdk/clients/sns").PublishResponse, import("aws-sdk").AWSError>>;
19
+ export declare const handleError: (step: FileProgress, params: IFunctionParam, since?: Date, Bucket?: string) => (err: HestiaError) => import("rxjs").Observable<import("aws-sdk/lib/request").PromiseResult<import("aws-sdk/clients/sns").PublishResponse, import("aws-sdk").AWSError>>;
20
+ export declare const handleSuccess: (step: FileProgress, params: IFunctionParam, since?: Date, Bucket?: string) => (details?: any) => import("rxjs").Observable<import("aws-sdk/lib/request").PromiseResult<import("aws-sdk/clients/sns").PublishResponse, import("aws-sdk").AWSError>>;
20
21
  export declare const defaultErrorHandler: (key: string) => (err: Error) => import("rxjs").Observable<never>;
package/dist/progress.js CHANGED
@@ -29,16 +29,19 @@ class HestiaError extends Error {
29
29
  }
30
30
  exports.HestiaError = HestiaError;
31
31
  const fileToProgress = (path) => `${path.split('.')[0]}.progress`;
32
- const uploadProgress = (step, path, Bucket, time, err, details) => (0, s3_1.uploadJSON)(fileToProgress(path), {
32
+ const uploadProgress = (step, path, Bucket, since, err, details) => (0, rxjs_1.of)(fileToProgress(path)).pipe((0, operators_1.mergeMap)(filepath => (0, s3_1.loadJSONFile)(filepath, Bucket).pipe((0, operators_1.catchError)(() => (0, rxjs_1.of)({})), (0, operators_1.mergeMap)(data => (0, s3_1.uploadJSON)(filepath, {
33
33
  step,
34
34
  success: !err,
35
- time,
35
+ time: {
36
+ ...(data.time || {}),
37
+ ...(since ? { [step]: (0, exports.timeSpent)(since) } : {})
38
+ },
36
39
  details,
37
40
  error: err ? err.toString() : null
38
- }, 'application/json', Bucket);
39
- const handleError = (step, params, time = 0, Bucket = s3_1.bucket) => (err) => uploadProgress(step, params.key, Bucket, time, err).pipe((0, operators_1.mergeMap)(() => (0, sns_1.publish)(`${step}${publishFunctionSuffix.Error}`, params)));
41
+ }, 'application/json', Bucket)))));
42
+ const handleError = (step, params, since, Bucket = s3_1.bucket) => (err) => uploadProgress(step, params.key, Bucket, since, err).pipe((0, operators_1.mergeMap)(() => (0, sns_1.publish)(`${step}${publishFunctionSuffix.Error}`, params)));
40
43
  exports.handleError = handleError;
41
- const handleSuccess = (step, params, time = 0, Bucket = s3_1.bucket) => (details) => uploadProgress(step, params.key, Bucket, time, null, details).pipe((0, operators_1.mergeMap)(() => (0, sns_1.publish)(`${step}${publishFunctionSuffix.Success}`, params)));
44
+ const handleSuccess = (step, params, since, Bucket = s3_1.bucket) => (details) => uploadProgress(step, params.key, Bucket, since, null, details).pipe((0, operators_1.mergeMap)(() => (0, sns_1.publish)(`${step}${publishFunctionSuffix.Success}`, params)));
42
45
  exports.handleSuccess = handleSuccess;
43
46
  const defaultErrorHandler = (key) => (err) => (0, rxjs_1.throwError)(new HestiaError(err.message, key, err.stack));
44
47
  exports.defaultErrorHandler = defaultErrorHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"progress.js","sourceRoot":"","sources":["../src/progress.ts"],"names":[],"mappings":";;;AAAA,8CAA0C;AAC1C,+BAAkC;AAElC,6BAA0D;AAC1D,+BAAgC;AAEhC,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,yCAAgB,CAAA;IAChB,wCAAe,CAAA;AACjB,CAAC,EAHW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAGhC;AAEM,MAAM,SAAS,GAAG,CAAC,KAAW,EAAE,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;AAApE,QAAA,SAAS,aAA2D;AAEjF,MAAa,WAAY,SAAQ,KAAK;IAOpC,YAAmB,OAAO,EAAS,GAAW,EAAS,SAAc,EAAE;QACrE,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,YAAO,GAAP,OAAO,CAAA;QAAS,QAAG,GA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AAM,EAAE,EAAE,CACvG,CAAC,GAAgB,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,CAC7E,IAAA,oBAAQ,EAAC,GAAG,EAAE,CAAC,IAAA,aAAO,EAAC,GAAG,IAAI,GAAG,qBAAqB,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,CAAC,CACzE,CAAC;AAHS,QAAA,WAAW,eAGpB;AAEG,MAAM,aAAa,GAAG,CAAC,IAAkB,EAAE,MAAsB,EAAE,KAAY,EAAE,MAAM,GAAG,WAAM,EAAE,EAAE,CACzG,CAAC,OAAa,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CACpF,IAAA,oBAAQ,EAAC,GAAG,EAAE,CAAC,IAAA,aAAO,EAAC,GAAG,IAAI,GAAG,qBAAqB,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC,CAC3E,CAAC;AAHS,QAAA,aAAa,iBAGtB;AAEG,MAAM,mBAAmB,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC,GAAU,EAAE,EAAE,CACjE,IAAA,iBAAU,EAAC,IAAI,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAD9C,QAAA,mBAAmB,uBAC2B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/pipeline-utils",
3
- "version": "0.8.2",
3
+ "version": "0.9.1",
4
4
  "description": "Utilities for running pipelines",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -38,15 +38,18 @@
38
38
  "rxjs": "^6.6.7"
39
39
  },
40
40
  "peerDependencies": {
41
+ "@hestia-earth/api": ">=0.18.0",
41
42
  "@hestia-earth/json-schema": ">=15.0.0",
42
43
  "@hestia-earth/schema": ">=15.0.0"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@commitlint/cli": "^17.4.2",
46
47
  "@commitlint/config-conventional": "^17.4.2",
48
+ "@hestia-earth/api": "^0.18.0",
47
49
  "@hestia-earth/eslint-config": "^0.0.5",
48
50
  "@hestia-earth/json-schema": "^15.0.0",
49
51
  "@hestia-earth/schema": "^15.0.0",
52
+ "@hestia-earth/utils": "^0.11.0",
50
53
  "@types/aws-lambda": "^8.10.109",
51
54
  "@types/aws-sdk": "^2.7.0",
52
55
  "@types/chai": "^4.3.4",
package/src/progress.ts CHANGED
@@ -1,9 +1,20 @@
1
- import { mergeMap } from 'rxjs/operators';
2
- import { throwError } from 'rxjs';
1
+ import { catchError, mergeMap } from 'rxjs/operators';
2
+ import { of, throwError } from 'rxjs';
3
+ import { FileProgress } from '@hestia-earth/api';
3
4
 
4
- import { IFunctionParam, uploadJSON, bucket } from './s3';
5
+ import { IFunctionParam, uploadJSON, bucket, loadJSONFile } from './s3';
5
6
  import { publish } from './sns';
6
7
 
8
+ interface IFileProgress {
9
+ step: FileProgress;
10
+ success: boolean;
11
+ time: {
12
+ [step in FileProgress]?: number;
13
+ };
14
+ details?: any;
15
+ error?: any;
16
+ }
17
+
7
18
  export enum publishFunctionSuffix {
8
19
  Success = 'Done',
9
20
  Error = 'Error'
@@ -33,22 +44,30 @@ export class HestiaError extends Error {
33
44
 
34
45
  const fileToProgress = (path: string) => `${path.split('.')[0]}.progress`;
35
46
 
36
- const uploadProgress = (step: string, path: string, Bucket: string, time: number, err?: HestiaError, details?: any) =>
37
- uploadJSON(fileToProgress(path), {
38
- step,
39
- success: !err,
40
- time,
41
- details,
42
- error: err ? err.toString() : null
43
- }, 'application/json', Bucket);
44
-
45
- export const handleError = (step: string, params: IFunctionParam, time = 0, Bucket = bucket) => (err: HestiaError) =>
46
- uploadProgress(step, params.key, Bucket, time, err).pipe(
47
+ const uploadProgress = (step: string, path: string, Bucket: string, since?: Date, err?: HestiaError, details?: any) =>
48
+ of(fileToProgress(path)).pipe(
49
+ mergeMap(filepath => loadJSONFile<Partial<IFileProgress>>(filepath, Bucket).pipe(
50
+ catchError(() => of({} as Partial<IFileProgress>)),
51
+ mergeMap(data => uploadJSON(filepath, {
52
+ step,
53
+ success: !err,
54
+ time: {
55
+ ...(data.time || {}),
56
+ ...(since ? { [step]: timeSpent(since) } : {})
57
+ },
58
+ details,
59
+ error: err ? err.toString() : null
60
+ }, 'application/json', Bucket))
61
+ ))
62
+ );
63
+
64
+ export const handleError = (step: FileProgress, params: IFunctionParam, since?: Date, Bucket = bucket) =>
65
+ (err: HestiaError) => uploadProgress(step, params.key, Bucket, since, err).pipe(
47
66
  mergeMap(() => publish(`${step}${publishFunctionSuffix.Error}`, params))
48
67
  );
49
68
 
50
- export const handleSuccess = (step: string, params: IFunctionParam, time = 0, Bucket = bucket) => (details?: any) =>
51
- uploadProgress(step, params.key, Bucket, time, null, details).pipe(
69
+ export const handleSuccess = (step: FileProgress, params: IFunctionParam, since?: Date, Bucket = bucket) =>
70
+ (details?: any) => uploadProgress(step, params.key, Bucket, since, null, details).pipe(
52
71
  mergeMap(() => publish(`${step}${publishFunctionSuffix.Success}`, params))
53
72
  );
54
73