@naturalcycles/abba 1.25.3 → 1.26.0

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/abba.d.ts CHANGED
@@ -36,6 +36,8 @@ export declare class Abba {
36
36
  private updateExclusions;
37
37
  /**
38
38
  * Delete an experiment. Removes all user assignments and buckets.
39
+ * Requires the experiment to have been inactive for at least 15 minutes in order to
40
+ * avoid row locking issues.
39
41
  * Cold method.
40
42
  */
41
43
  deleteExperiment(experimentId: string): Promise<void>;
package/dist/abba.js CHANGED
@@ -12,7 +12,7 @@ const util_1 = require("./util");
12
12
  /**
13
13
  * 10 minutes
14
14
  */
15
- const CACHE_TTL = 600_000; // 10 minutes
15
+ const CACHE_TTL = 600_000;
16
16
  class Abba {
17
17
  constructor(cfg) {
18
18
  this.cfg = cfg;
@@ -103,9 +103,15 @@ class Abba {
103
103
  }
104
104
  /**
105
105
  * Delete an experiment. Removes all user assignments and buckets.
106
+ * Requires the experiment to have been inactive for at least 15 minutes in order to
107
+ * avoid row locking issues.
106
108
  * Cold method.
107
109
  */
108
110
  async deleteExperiment(experimentId) {
111
+ const experiment = await this.experimentDao.requireById(experimentId);
112
+ const hasBeenInactiveFor15Mins = experiment.status === types_1.AssignmentStatus.Inactive &&
113
+ (0, js_lib_1.localTime)(experiment.updated).isOlderThan(15, 'minute');
114
+ (0, js_lib_1._assert)(hasBeenInactiveFor15Mins, 'Experiment must be inactive for at least 15 minutes before deletion');
109
115
  const userAssignmentDeleteQuery = this.userAssignmentDao
110
116
  .query()
111
117
  .filterEq('experimentId', experimentId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/abba",
3
- "version": "1.25.3",
3
+ "version": "1.26.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build",
package/src/abba.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _assert, _Memo, _shuffle, pMap, Unsaved } from '@naturalcycles/js-lib'
1
+ import { _assert, _Memo, _shuffle, localTime, pMap, Unsaved } from '@naturalcycles/js-lib'
2
2
  import { LRUMemoCache } from '@naturalcycles/nodejs-lib'
3
3
  import { SegmentationData } from '.'
4
4
  import { bucketDao } from './dao/bucket.dao'
@@ -25,7 +25,7 @@ import {
25
25
  /**
26
26
  * 10 minutes
27
27
  */
28
- const CACHE_TTL = 600_000 // 10 minutes
28
+ const CACHE_TTL = 600_000
29
29
 
30
30
  export class Abba {
31
31
  private experimentDao = experimentDao(this.cfg.db)
@@ -149,9 +149,21 @@ export class Abba {
149
149
 
150
150
  /**
151
151
  * Delete an experiment. Removes all user assignments and buckets.
152
+ * Requires the experiment to have been inactive for at least 15 minutes in order to
153
+ * avoid row locking issues.
152
154
  * Cold method.
153
155
  */
154
156
  async deleteExperiment(experimentId: string): Promise<void> {
157
+ const experiment = await this.experimentDao.requireById(experimentId)
158
+
159
+ const hasBeenInactiveFor15Mins =
160
+ experiment.status === AssignmentStatus.Inactive &&
161
+ localTime(experiment.updated).isOlderThan(15, 'minute')
162
+ _assert(
163
+ hasBeenInactiveFor15Mins,
164
+ 'Experiment must be inactive for at least 15 minutes before deletion',
165
+ )
166
+
155
167
  const userAssignmentDeleteQuery = this.userAssignmentDao
156
168
  .query()
157
169
  .filterEq('experimentId', experimentId)