screwdriver-queue-service 2.0.20 → 2.0.21
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/config/default.yaml
CHANGED
package/config/kafka.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const config = require('config');
|
|
4
|
+
const kafkaConfig = config.get('kafka');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* get config
|
|
8
|
+
* @returns Object containing kafka config values
|
|
9
|
+
*/
|
|
10
|
+
function get() {
|
|
11
|
+
return {
|
|
12
|
+
kafkaEnabled: kafkaConfig.enabled === 'true',
|
|
13
|
+
useShortRegionName: kafkaConfig.shortRegion === 'true'
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
get
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -15,8 +15,8 @@ const blockedByConfig = config.get('plugins').blockedBy;
|
|
|
15
15
|
const { connectionDetails, queuePrefix, runningJobsPrefix, waitingJobsPrefix } = require('../../../config/redis');
|
|
16
16
|
const rabbitmqConf = require('../../../config/rabbitmq');
|
|
17
17
|
const { amqpURI, exchange, connectOptions } = rabbitmqConf.getConfig();
|
|
18
|
-
const
|
|
19
|
-
|
|
18
|
+
const kafkaConfig = require('../../../config/kafka');
|
|
19
|
+
const { kafkaEnabled, useShortRegionName } = kafkaConfig.get();
|
|
20
20
|
const RETRY_LIMIT = 3;
|
|
21
21
|
// This is in milliseconds, reference: https://github.com/actionhero/node-resque/blob/2ffdf0/lib/plugins/Retry.js#L12
|
|
22
22
|
const RETRY_DELAY = 5 * 1000;
|
|
@@ -57,6 +57,17 @@ const blockedByOptions = {
|
|
|
57
57
|
|
|
58
58
|
collapse: blockedByConfig.collapse
|
|
59
59
|
};
|
|
60
|
+
// AWS region map
|
|
61
|
+
const AWS_REGION_MAP = {
|
|
62
|
+
north: 'n',
|
|
63
|
+
west: 'w',
|
|
64
|
+
northeast: 'nw',
|
|
65
|
+
east: 'e',
|
|
66
|
+
south: 's',
|
|
67
|
+
central: 'c',
|
|
68
|
+
southeast: 'se'
|
|
69
|
+
};
|
|
70
|
+
|
|
60
71
|
let rabbitmqConn;
|
|
61
72
|
|
|
62
73
|
/**
|
|
@@ -134,6 +145,23 @@ async function pushToKafka(message, topic) {
|
|
|
134
145
|
}
|
|
135
146
|
}
|
|
136
147
|
|
|
148
|
+
/**
|
|
149
|
+
*
|
|
150
|
+
* @param {*String} accountId The AWS accountId
|
|
151
|
+
* @param {*String} region The region name
|
|
152
|
+
* @returns String topicName
|
|
153
|
+
*/
|
|
154
|
+
function getTopicName(accountId, region) {
|
|
155
|
+
const items = region.split('-');
|
|
156
|
+
|
|
157
|
+
if (items.length < 3 || !useShortRegionName) {
|
|
158
|
+
return `builds-${accountId}-${region}`;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const shortRegion = ''.concat(items[0], AWS_REGION_MAP[items[1]], items[2]);
|
|
162
|
+
|
|
163
|
+
return `builds-${accountId}-${shortRegion}`;
|
|
164
|
+
}
|
|
137
165
|
/**
|
|
138
166
|
* Schedule a job based on mode
|
|
139
167
|
* @method schedule
|
|
@@ -153,9 +181,8 @@ async function schedule(job, buildConfig) {
|
|
|
153
181
|
|
|
154
182
|
if (kafkaEnabled && buildConfig.provider) {
|
|
155
183
|
const { accountId, region } = buildConfig.provider;
|
|
156
|
-
const topic = `builds-${accountId}-${region}`;
|
|
157
184
|
|
|
158
|
-
return pushToKafka(msg,
|
|
185
|
+
return pushToKafka(msg, getTopicName(accountId, region));
|
|
159
186
|
}
|
|
160
187
|
|
|
161
188
|
if (rabbitmqConf.getConfig().schedulerMode) {
|