@hestia-earth/pipeline-utils 0.12.1 → 0.13.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/dist/api.d.ts +1 -1
- package/dist/api.js +3 -2
- package/dist/api.js.map +1 -1
- package/dist/ec2.js +4 -2
- package/dist/ec2.js.map +1 -1
- package/dist/find-nodes.js +37 -41
- package/dist/find-nodes.js.map +1 -1
- package/dist/gitlab.js +1 -4
- package/dist/gitlab.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/lambda.d.ts +1 -1
- package/dist/lambda.js +4 -2
- package/dist/lambda.js.map +1 -1
- package/dist/local.js +3 -6
- package/dist/local.js.map +1 -1
- package/dist/progress.js +1 -1
- package/dist/progress.js.map +1 -1
- package/dist/s3.d.ts +1 -0
- package/dist/s3.js +77 -42
- package/dist/s3.js.map +1 -1
- package/dist/sns.d.ts +1 -1
- package/dist/sns.js +6 -4
- package/dist/sns.js.map +1 -1
- package/dist/sqs.d.ts +1 -1
- package/dist/sqs.js +6 -4
- package/dist/sqs.js.map +1 -1
- package/dist/utils.js +22 -19
- package/dist/utils.js.map +1 -1
- package/package.json +29 -33
- package/src/api.ts +4 -5
- package/src/ec2.ts +16 -13
- package/src/find-nodes.ts +85 -80
- package/src/gitlab.ts +1 -4
- package/src/index.ts +0 -1
- package/src/lambda.ts +19 -16
- package/src/local.ts +20 -24
- package/src/progress.ts +39 -22
- package/src/s3.ts +150 -89
- package/src/sns.ts +36 -28
- package/src/sqs.ts +36 -28
- package/src/utils.ts +45 -38
- package/dist/requests.d.ts +0 -8
- package/dist/requests.js +0 -84
- package/dist/requests.js.map +0 -1
- package/src/requests.ts +0 -89
package/src/local.ts
CHANGED
|
@@ -17,25 +17,22 @@ const currentDir = (key: string) => {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
export const loadTextFile = (folder: string) => (file: string) =>
|
|
20
|
-
mkdirAsObservable(currentDir(join(folder, file)), { recursive: true })
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
);
|
|
20
|
+
mkdirAsObservable(currentDir(join(folder, file)), { recursive: true }).pipe(
|
|
21
|
+
mergeMap(() => readFileAsObservable(join(folder, file), 'utf8')),
|
|
22
|
+
take(1),
|
|
23
|
+
map((res: any) => res as string)
|
|
24
|
+
);
|
|
26
25
|
|
|
27
|
-
export const loadJSONFile =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
);
|
|
26
|
+
export const loadJSONFile =
|
|
27
|
+
(folder: string) =>
|
|
28
|
+
<T>(file: string) =>
|
|
29
|
+
loadTextFile(folder)(file).pipe(map(res => JSON.parse(stripBOM(res)) as T));
|
|
32
30
|
|
|
33
31
|
export const uploadText = (folder: string) => (file: string, data: string) =>
|
|
34
|
-
mkdirAsObservable(currentDir(join(folder, file)), { recursive: true })
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
);
|
|
32
|
+
mkdirAsObservable(currentDir(join(folder, file)), { recursive: true }).pipe(
|
|
33
|
+
mergeMap(() => writeFileAsObservable(join(folder, file), data, 'utf8')),
|
|
34
|
+
map(() => data)
|
|
35
|
+
);
|
|
39
36
|
|
|
40
37
|
export const uploadJSON = (folder: string) => (file: string, data) =>
|
|
41
38
|
uploadText(folder)(file, JSON.stringify(data, null, 2));
|
|
@@ -43,8 +40,7 @@ export const uploadJSON = (folder: string) => (file: string, data) =>
|
|
|
43
40
|
export const lastModified = (folder: string) => (file: string) => {
|
|
44
41
|
try {
|
|
45
42
|
return of(statSync(join(folder, file)).mtime);
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
43
|
+
} catch (err) {
|
|
48
44
|
return of(new Date());
|
|
49
45
|
}
|
|
50
46
|
};
|
|
@@ -53,8 +49,7 @@ export const fileExists = (folder: string) => (file: string) => {
|
|
|
53
49
|
try {
|
|
54
50
|
const success = statSync(join(folder, file)).isFile();
|
|
55
51
|
return of(success);
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
52
|
+
} catch (err) {
|
|
58
53
|
return of(false);
|
|
59
54
|
}
|
|
60
55
|
};
|
|
@@ -62,11 +57,12 @@ export const fileExists = (folder: string) => (file: string) => {
|
|
|
62
57
|
export const fileSize = (folder: string) => (file: string) => {
|
|
63
58
|
try {
|
|
64
59
|
return of(statSync(join(folder, file)).size);
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
60
|
+
} catch (err) {
|
|
67
61
|
return of(undefined as number);
|
|
68
62
|
}
|
|
69
63
|
};
|
|
70
64
|
|
|
71
|
-
export const deleteFile =
|
|
72
|
-
|
|
65
|
+
export const deleteFile =
|
|
66
|
+
(folder: string) =>
|
|
67
|
+
(file: string): Observable<any> =>
|
|
68
|
+
unlinkAsObservable(join(folder, file));
|
package/src/progress.ts
CHANGED
|
@@ -29,7 +29,11 @@ export class HestiaError extends Error {
|
|
|
29
29
|
* @param key The file throwing this error
|
|
30
30
|
* @param errors The errors
|
|
31
31
|
*/
|
|
32
|
-
constructor(
|
|
32
|
+
constructor(
|
|
33
|
+
public message,
|
|
34
|
+
public key: string,
|
|
35
|
+
public errors: any = ''
|
|
36
|
+
) {
|
|
33
37
|
super(message);
|
|
34
38
|
}
|
|
35
39
|
|
|
@@ -46,30 +50,43 @@ const fileToProgress = (path: string) => `${path.split('.')[0]}.progress`;
|
|
|
46
50
|
|
|
47
51
|
const uploadProgress = (step: string, path: string, Bucket: string, since?: Date, err?: HestiaError, details?: any) =>
|
|
48
52
|
of(fileToProgress(path)).pipe(
|
|
49
|
-
mergeMap(filepath =>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
mergeMap(filepath =>
|
|
54
|
+
loadJSONFile<Partial<IFileProgress>>(filepath, Bucket).pipe(
|
|
55
|
+
catchError(() => of({} as Partial<IFileProgress>)),
|
|
56
|
+
mergeMap(data =>
|
|
57
|
+
uploadJSON(
|
|
58
|
+
filepath,
|
|
59
|
+
{
|
|
60
|
+
step,
|
|
61
|
+
success: !err,
|
|
62
|
+
time: {
|
|
63
|
+
...(data.time || {}),
|
|
64
|
+
...(since ? { [step]: timeSpent(since) } : {})
|
|
65
|
+
},
|
|
66
|
+
details,
|
|
67
|
+
error: err ? err.toString() : null
|
|
68
|
+
},
|
|
69
|
+
'application/json',
|
|
70
|
+
Bucket
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
)
|
|
62
75
|
);
|
|
63
76
|
|
|
64
|
-
export const handleError =
|
|
65
|
-
(
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
export const handleError =
|
|
78
|
+
(step: FileProgress, params: IFunctionParam, since?: Date, Bucket = bucket) =>
|
|
79
|
+
(err: HestiaError) =>
|
|
80
|
+
uploadProgress(step, params.key, Bucket, since, err).pipe(
|
|
81
|
+
mergeMap(() => publish(`${step}${publishFunctionSuffix.Error}`, params))
|
|
82
|
+
);
|
|
68
83
|
|
|
69
|
-
export const handleSuccess =
|
|
70
|
-
(
|
|
71
|
-
|
|
72
|
-
|
|
84
|
+
export const handleSuccess =
|
|
85
|
+
(step: FileProgress, params: IFunctionParam, since?: Date, Bucket = bucket) =>
|
|
86
|
+
(details?: any) =>
|
|
87
|
+
uploadProgress(step, params.key, Bucket, since, null, details).pipe(
|
|
88
|
+
mergeMap(() => publish(`${step}${publishFunctionSuffix.Success}`, params))
|
|
89
|
+
);
|
|
73
90
|
|
|
74
91
|
export const defaultErrorHandler = (key: string) => (err: Error) =>
|
|
75
92
|
throwError(new HestiaError(err.message, key, err.stack));
|
package/src/s3.ts
CHANGED
|
@@ -32,43 +32,62 @@ export const getS3 = () => {
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
export const getObject = ({ Key, ...params }: AWS.S3.GetObjectRequest) =>
|
|
35
|
-
from(
|
|
35
|
+
from(
|
|
36
|
+
getS3()
|
|
37
|
+
.getObject({ ...params, Key: decodeURI(Key) })
|
|
38
|
+
.promise()
|
|
39
|
+
).pipe(
|
|
36
40
|
take(1),
|
|
37
41
|
map(({ Body }) => Body.toString())
|
|
38
42
|
);
|
|
39
43
|
|
|
40
44
|
export const putObject = ({ Key, ...params }: AWS.S3.PutObjectRequest) =>
|
|
41
|
-
from(
|
|
45
|
+
from(
|
|
46
|
+
getS3()
|
|
47
|
+
.putObject({ ...params, Key: decodeURI(Key) })
|
|
48
|
+
.promise()
|
|
49
|
+
).pipe(
|
|
42
50
|
take(1),
|
|
43
51
|
map(res => (res.$response.data || '').toString())
|
|
44
52
|
);
|
|
45
53
|
|
|
46
54
|
export const deleteObjects = (Objects: AWS.S3.Object[], Bucket = bucket) =>
|
|
47
|
-
from(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
from(
|
|
56
|
+
getS3()
|
|
57
|
+
.deleteObjects({
|
|
58
|
+
Bucket,
|
|
59
|
+
Delete: {
|
|
60
|
+
Objects: Objects.map(({ Key }) => ({ Key }))
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
.promise()
|
|
64
|
+
).pipe(
|
|
53
65
|
take(1),
|
|
54
66
|
map(res => (res.$response.data || '').toString())
|
|
55
67
|
);
|
|
56
68
|
|
|
57
69
|
export const copyObject = (fromParams, toParams, MetadataDirective?: string) =>
|
|
58
|
-
from(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
from(
|
|
71
|
+
getS3()
|
|
72
|
+
.copyObject({
|
|
73
|
+
Bucket: toParams.bucket,
|
|
74
|
+
Key: decodeURI(toParams.key),
|
|
75
|
+
CopySource: `${fromParams.bucket}/${fromParams.key}`,
|
|
76
|
+
MetadataDirective
|
|
77
|
+
})
|
|
78
|
+
.promise()
|
|
79
|
+
).pipe(
|
|
64
80
|
take(1),
|
|
65
81
|
map(res => (res.$response.data || '').toString())
|
|
66
82
|
);
|
|
67
83
|
|
|
68
|
-
export const loadStream = (key: string, Bucket = bucket) =>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
export const loadStream = (key: string, Bucket = bucket) =>
|
|
85
|
+
getS3()
|
|
86
|
+
.getObject({
|
|
87
|
+
Bucket,
|
|
88
|
+
Key: decodeURI(key)
|
|
89
|
+
})
|
|
90
|
+
.createReadStream();
|
|
72
91
|
|
|
73
92
|
export const loadFile = (key: string) => {
|
|
74
93
|
const stream = loadStream(key);
|
|
@@ -86,80 +105,122 @@ export const loadFile = (key: string) => {
|
|
|
86
105
|
return subject.asObservable();
|
|
87
106
|
};
|
|
88
107
|
|
|
89
|
-
export const loadTextFile = (key: string, Bucket = bucket) =>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
export const
|
|
107
|
-
|
|
108
|
-
Key: key,
|
|
109
|
-
Body: data
|
|
110
|
-
}) : local.uploadText(Bucket)(key, data);
|
|
111
|
-
|
|
112
|
-
export const uploadJSON = (key: string, data, type = 'application/json', Bucket = bucket) => isS3Mode ? putObject({
|
|
113
|
-
Bucket,
|
|
114
|
-
Key: key,
|
|
115
|
-
Body: JSON.stringify(data, null, 2),
|
|
116
|
-
ContentType: type
|
|
117
|
-
}) : local.uploadJSON(Bucket)(key, data);
|
|
118
|
-
|
|
119
|
-
export const waitObjectCreated = (key: string, Bucket = bucket) => isS3Mode ?
|
|
120
|
-
from(getS3().waitFor('objectExists', {
|
|
108
|
+
export const loadTextFile = (key: string, Bucket = bucket) =>
|
|
109
|
+
isS3Mode
|
|
110
|
+
? getObject({
|
|
111
|
+
Bucket,
|
|
112
|
+
Key: key
|
|
113
|
+
}).pipe(map(res => res.replace(/\"/g, '')))
|
|
114
|
+
: local.loadTextFile(Bucket)(key);
|
|
115
|
+
|
|
116
|
+
export const loadJSONFile = <T>(key: string, Bucket = bucket): Observable<T> =>
|
|
117
|
+
isS3Mode
|
|
118
|
+
? getObject({
|
|
119
|
+
Bucket,
|
|
120
|
+
Key: key,
|
|
121
|
+
ResponseContentType: 'application/json'
|
|
122
|
+
}).pipe(map(res => JSON.parse(stripBOM(res)) as T))
|
|
123
|
+
: local.loadJSONFile(Bucket)(key);
|
|
124
|
+
|
|
125
|
+
export const uploadFile = (filepath: string, key: string, Bucket = bucket) =>
|
|
126
|
+
putObject({
|
|
121
127
|
Bucket,
|
|
122
|
-
Key:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
export const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
128
|
+
Key: key,
|
|
129
|
+
Body: createReadStream(filepath, 'utf8')
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
export const uploadText = (key: string, data: string, Bucket = bucket) =>
|
|
133
|
+
isS3Mode
|
|
134
|
+
? putObject({
|
|
135
|
+
Bucket,
|
|
136
|
+
Key: key,
|
|
137
|
+
Body: data
|
|
138
|
+
})
|
|
139
|
+
: local.uploadText(Bucket)(key, data);
|
|
140
|
+
|
|
141
|
+
export const uploadJSON = (key: string, data, type = 'application/json', Bucket = bucket) =>
|
|
142
|
+
isS3Mode
|
|
143
|
+
? putObject({
|
|
144
|
+
Bucket,
|
|
145
|
+
Key: key,
|
|
146
|
+
Body: JSON.stringify(data, null, 2),
|
|
147
|
+
ContentType: type
|
|
148
|
+
})
|
|
149
|
+
: local.uploadJSON(Bucket)(key, data);
|
|
150
|
+
|
|
151
|
+
export const waitObjectCreated = (key: string, Bucket = bucket) =>
|
|
152
|
+
isS3Mode
|
|
153
|
+
? from(
|
|
154
|
+
getS3()
|
|
155
|
+
.waitFor('objectExists', {
|
|
156
|
+
Bucket,
|
|
157
|
+
Key: decodeURI(key)
|
|
158
|
+
})
|
|
159
|
+
.promise()
|
|
160
|
+
).pipe(
|
|
161
|
+
take(1),
|
|
162
|
+
map(() => true)
|
|
163
|
+
)
|
|
164
|
+
: of(true);
|
|
165
|
+
|
|
166
|
+
const headObject = (key: string, Bucket = bucket) =>
|
|
167
|
+
from(
|
|
168
|
+
getS3()
|
|
169
|
+
.headObject({
|
|
170
|
+
Bucket,
|
|
171
|
+
Key: decodeURI(key)
|
|
172
|
+
})
|
|
173
|
+
.promise()
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
export const lastModified = (key: string, Bucket = bucket) =>
|
|
177
|
+
isS3Mode
|
|
178
|
+
? headObject(key, Bucket).pipe(
|
|
179
|
+
map(({ LastModified }) => LastModified),
|
|
180
|
+
catchError(() => of(null as Date)),
|
|
181
|
+
take(1)
|
|
182
|
+
)
|
|
183
|
+
: local.lastModified(Bucket)(key);
|
|
184
|
+
|
|
185
|
+
export const fileExists = (key: string, Bucket = bucket) =>
|
|
186
|
+
isS3Mode
|
|
187
|
+
? headObject(key, Bucket).pipe(
|
|
188
|
+
map(() => true),
|
|
189
|
+
catchError(() => of(false)),
|
|
190
|
+
take(1)
|
|
191
|
+
)
|
|
192
|
+
: local.fileExists(Bucket)(key);
|
|
193
|
+
|
|
194
|
+
export const fileSize = (key: string, Bucket = bucket) =>
|
|
195
|
+
isS3Mode
|
|
196
|
+
? headObject(key, Bucket).pipe(
|
|
197
|
+
map(({ ContentLength }) => ContentLength),
|
|
198
|
+
catchError(() => of(undefined as number)),
|
|
199
|
+
take(1)
|
|
200
|
+
)
|
|
201
|
+
: local.fileSize(Bucket)(key);
|
|
202
|
+
|
|
203
|
+
export const deleteObject = (key: string, Bucket = bucket) =>
|
|
204
|
+
isS3Mode
|
|
205
|
+
? from(
|
|
206
|
+
getS3()
|
|
207
|
+
.deleteObject({
|
|
208
|
+
Bucket,
|
|
209
|
+
Key: decodeURI(key)
|
|
210
|
+
})
|
|
211
|
+
.promise()
|
|
212
|
+
)
|
|
213
|
+
: local.deleteFile(Bucket)(key);
|
|
155
214
|
|
|
156
215
|
export const listFolder = async (Prefix = '', Bucket = bucket, nextToken?: string): Promise<AWS.S3.Object[]> => {
|
|
157
|
-
const { Contents, IsTruncated, NextContinuationToken } = await getS3()
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
216
|
+
const { Contents, IsTruncated, NextContinuationToken } = await getS3()
|
|
217
|
+
.listObjectsV2({
|
|
218
|
+
Bucket,
|
|
219
|
+
Prefix,
|
|
220
|
+
ContinuationToken: nextToken,
|
|
221
|
+
MaxKeys: 1000
|
|
222
|
+
})
|
|
223
|
+
.promise();
|
|
163
224
|
return [...Contents, ...(IsTruncated ? await listFolder(Prefix, bucket, NextContinuationToken) : [])];
|
|
164
225
|
};
|
|
165
226
|
|
package/src/sns.ts
CHANGED
|
@@ -10,31 +10,39 @@ type attributes = {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export const publish = (
|
|
13
|
-
functionName: string,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
13
|
+
functionName: string,
|
|
14
|
+
params: IFunctionParam,
|
|
15
|
+
topicArn = process.env.SNS_TOPIC,
|
|
16
|
+
extras: attributes = {}
|
|
17
|
+
) =>
|
|
18
|
+
isS3Mode
|
|
19
|
+
? from(
|
|
20
|
+
new AWS.SNS()
|
|
21
|
+
.publish({
|
|
22
|
+
TopicArn: topicArn,
|
|
23
|
+
Message: JSON.stringify(params),
|
|
24
|
+
MessageAttributes: {
|
|
25
|
+
functionName: {
|
|
26
|
+
DataType: 'String',
|
|
27
|
+
StringValue: functionName
|
|
28
|
+
},
|
|
29
|
+
...Object.fromEntries(
|
|
30
|
+
Object.entries(extras || {}).map(([key, value]) => [
|
|
31
|
+
key,
|
|
32
|
+
{
|
|
33
|
+
DataType: 'String',
|
|
34
|
+
StringValue: value
|
|
35
|
+
}
|
|
36
|
+
])
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
.promise()
|
|
41
|
+
).pipe(
|
|
42
|
+
take(1),
|
|
43
|
+
map(res => {
|
|
44
|
+
debug(`SNS publish ${functionName}`, res);
|
|
45
|
+
return res;
|
|
46
|
+
})
|
|
47
|
+
)
|
|
48
|
+
: of(null);
|
package/src/sqs.ts
CHANGED
|
@@ -10,31 +10,39 @@ type attributes = {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export const sendMessage = (
|
|
13
|
-
functionName: string,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
13
|
+
functionName: string,
|
|
14
|
+
params: IFunctionParam,
|
|
15
|
+
queueUrl = process.env.SQS_URL,
|
|
16
|
+
extras: attributes = {}
|
|
17
|
+
) =>
|
|
18
|
+
isS3Mode
|
|
19
|
+
? from(
|
|
20
|
+
new AWS.SQS({ region })
|
|
21
|
+
.sendMessage({
|
|
22
|
+
QueueUrl: queueUrl,
|
|
23
|
+
MessageBody: JSON.stringify(params),
|
|
24
|
+
MessageAttributes: {
|
|
25
|
+
functionName: {
|
|
26
|
+
DataType: 'String',
|
|
27
|
+
StringValue: functionName
|
|
28
|
+
},
|
|
29
|
+
...Object.fromEntries(
|
|
30
|
+
Object.entries(extras || {}).map(([key, value]) => [
|
|
31
|
+
key,
|
|
32
|
+
{
|
|
33
|
+
DataType: 'String',
|
|
34
|
+
StringValue: value
|
|
35
|
+
}
|
|
36
|
+
])
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
.promise()
|
|
41
|
+
).pipe(
|
|
42
|
+
take(1),
|
|
43
|
+
map(res => {
|
|
44
|
+
debug(`SQS send message ${functionName}`, res);
|
|
45
|
+
return res;
|
|
46
|
+
})
|
|
47
|
+
)
|
|
48
|
+
: of(null);
|