@friggframework/core 2.0.0-next.0 → 2.0.0-next.10

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0-next.0",
4
+ "version": "2.0.0-next.10",
5
5
  "dependencies": {
6
6
  "@hapi/boom": "^10.0.1",
7
7
  "aws-sdk": "^2.1200.0",
@@ -15,9 +15,9 @@
15
15
  "node-fetch": "^2.6.7"
16
16
  },
17
17
  "devDependencies": {
18
- "@friggframework/eslint-config": "^2.0.0-next.0",
19
- "@friggframework/prettier-config": "^2.0.0-next.0",
20
- "@friggframework/test": "^2.0.0-next.0",
18
+ "@friggframework/eslint-config": "2.0.0-next.10",
19
+ "@friggframework/prettier-config": "2.0.0-next.10",
20
+ "@friggframework/test": "2.0.0-next.10",
21
21
  "@types/lodash": "^4.14.191",
22
22
  "@typescript-eslint/eslint-plugin": "^8.0.0",
23
23
  "chai": "^4.3.6",
@@ -48,5 +48,5 @@
48
48
  },
49
49
  "homepage": "https://github.com/friggframework/frigg#readme",
50
50
  "description": "",
51
- "gitHead": "e37f577d3c14f8eed6584517830c6c61815cf759"
51
+ "gitHead": "67dc76e94c02c0074f7ff2d7292c4d2203bf3949"
52
52
  }
@@ -0,0 +1,4 @@
1
+ const { QueuerUtil } = require('./queuer-util');
2
+ module.exports = {
3
+ QueuerUtil,
4
+ };
@@ -0,0 +1,61 @@
1
+ const { v4: uuid } = require('uuid');
2
+ const AWS = require('aws-sdk');
3
+ const awsConfigOptions = () => {
4
+ const config = {};
5
+ if (process.env.IS_OFFLINE) {
6
+ console.log('Running in offline mode');
7
+ }
8
+ if (process.env.AWS_ENDPOINT) {
9
+ config.endpoint = process.env.AWS_ENDPOINT;
10
+ }
11
+ return config;
12
+ };
13
+ AWS.config.update(awsConfigOptions());
14
+ const sqs = new AWS.SQS();
15
+
16
+ const QueuerUtil = {
17
+ batchSend: async (entries = [], queueUrl) => {
18
+ console.log(
19
+ `Enqueuing ${entries.length} entries on SQS to queue ${queueUrl}`
20
+ );
21
+ const buffer = [];
22
+ const batchSize = 10;
23
+
24
+ for (const entry of entries) {
25
+ buffer.push({
26
+ Id: uuid(),
27
+ MessageBody: JSON.stringify(entry),
28
+ });
29
+ // Sends 10, then purges the buffer
30
+ if (buffer.length === batchSize) {
31
+ console.log('Buffer at 10, sending batch');
32
+ await sqs
33
+ .sendMessageBatch({
34
+ Entries: buffer,
35
+ QueueUrl: queueUrl,
36
+ })
37
+ .promise();
38
+ // Purge the buffer
39
+ buffer.splice(0, buffer.length);
40
+ }
41
+ }
42
+ console.log('Buffer at end, sending final batch');
43
+
44
+ // If any remaining entries under 10 are left in the buffer, send and return
45
+ if (buffer.length > 0) {
46
+ console.log(buffer);
47
+ return sqs
48
+ .sendMessageBatch({
49
+ Entries: buffer,
50
+ QueueUrl: queueUrl,
51
+ })
52
+ .promise();
53
+ }
54
+
55
+ // If we're exact... just return an empty object for now
56
+
57
+ return {};
58
+ },
59
+ };
60
+
61
+ module.exports = { QueuerUtil };