screwdriver-api 8.0.147 → 8.0.149

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,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "8.0.147",
3
+ "version": "8.0.149",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -134,10 +134,10 @@
134
134
  "screwdriver-scm-router": "^9.0.0",
135
135
  "screwdriver-template-validator": "^10.0.0",
136
136
  "screwdriver-workflow-parser": "^6.1.0",
137
- "sqlite3": "^5.1.4",
137
+ "sqlite3": "^6.0.1",
138
138
  "stream": "0.0.3",
139
139
  "tinytim": "^0.1.1",
140
- "uuid": "^9.0.0",
140
+ "uuid": "^11.1.1",
141
141
  "verror": "^1.10.1"
142
142
  },
143
143
  "release": {
@@ -168,5 +168,15 @@
168
168
  "rewiremock": "^3.14.4",
169
169
  "sinon": "^15.0.0",
170
170
  "stream-to-promise": "^3.0.0"
171
+ },
172
+ "overrides": {
173
+ "screwdriver-datastore-sequelize": {
174
+ "sequelize": {
175
+ "uuid": "^11.1.1"
176
+ }
177
+ },
178
+ "screwdriver-scm-github": {
179
+ "underscore": "^1.13.8"
180
+ }
171
181
  }
172
182
  }
@@ -6,6 +6,7 @@ const merge = require('lodash.mergewith');
6
6
  const isEmpty = require('lodash.isempty');
7
7
  const { PR_JOB_NAME, PR_STAGE_NAME, STAGE_TEARDOWN_PATTERN } = require('screwdriver-data-schema').config.regex;
8
8
  const { getFullStageJobName } = require('../../helper');
9
+ const { locker } = require('../../lock');
9
10
  const { updateVirtualBuildSuccess, emitBuildStatusEvent, isFixedBuild } = require('../triggers/helpers');
10
11
  const TERMINAL_STATUSES = ['FAILURE', 'ABORTED', 'UNSTABLE', 'COLLAPSED'];
11
12
  const FINISHED_STATUSES = ['SUCCESS', ...TERMINAL_STATUSES];
@@ -358,6 +359,7 @@ async function updateBuildAndTriggerDownstreamJobs(config, build, server, userna
358
359
  const { triggerNextJobs, removeJoinBuilds, createOrUpdateStageTeardownBuild } = server.plugins.builds;
359
360
 
360
361
  const currentStatus = build.status;
362
+ const isEndBuildStatus = ['SUCCESS', 'FAILURE', 'ABORTED'].includes(desiredStatus);
361
363
 
362
364
  const event = await eventFactory.get(build.eventId);
363
365
 
@@ -370,9 +372,8 @@ async function updateBuildAndTriggerDownstreamJobs(config, build, server, userna
370
372
  if (!desiredStatus) {
371
373
  build.statusMessage = statusMessage || build.statusMessage;
372
374
  build.statusMessageType = statusMessageType || build.statusMessageType;
373
- } else if (['SUCCESS', 'FAILURE', 'ABORTED'].includes(desiredStatus)) {
375
+ } else if (isEndBuildStatus) {
374
376
  build.meta = isEmpty(meta) ? build.meta || {} : meta;
375
- event.meta = merge({}, event.meta, build.meta);
376
377
  build.endTime = new Date().toISOString();
377
378
  } else if (desiredStatus === 'RUNNING') {
378
379
  build.startTime = new Date().toISOString();
@@ -416,8 +417,31 @@ async function updateBuildAndTriggerDownstreamJobs(config, build, server, userna
416
417
  const pipeline = await job.pipeline;
417
418
  const isFixed = await isFixedBuild({ build, job });
418
419
 
420
+ let eventLock;
421
+ const eventResource = `event:${event.id}`;
422
+
423
+ if (isEndBuildStatus) {
424
+ try {
425
+ eventLock = await locker.lock(eventResource);
426
+ } catch (err) {
427
+ eventLock = null;
428
+ }
429
+
430
+ const latestEvent = await eventFactory.get(build.eventId);
431
+
432
+ event.meta = merge({}, latestEvent ? latestEvent.meta : event.meta, build.meta);
433
+ }
434
+
419
435
  const [newBuild, newEvent] = await Promise.all([build.update(), event.update(), stopFrozen]);
420
436
 
437
+ if (isEndBuildStatus) {
438
+ try {
439
+ await locker.unlock(eventLock, eventResource);
440
+ } catch (err) {
441
+ // ignore unlock errors for parity with lock helper behavior
442
+ }
443
+ }
444
+
421
445
  if (desiredStatus) {
422
446
  await emitBuildStatusEvent({ server, build: newBuild, pipeline, event: newEvent, job, isFixed });
423
447
  }