mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-05 17:53:12 +02:00
fix: remove lifecycle backfill on every startup
This commit is contained in:
parent
597456d4b5
commit
6c11b57c53
@ -12,7 +12,6 @@ import type { ChangeRequestType } from '../../changeRequest.types';
|
|||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { ChangeRequestStatusBadge } from '../../ChangeRequestStatusBadge/ChangeRequestStatusBadge.tsx';
|
import { ChangeRequestStatusBadge } from '../../ChangeRequestStatusBadge/ChangeRequestStatusBadge.tsx';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { changesCount } from '../../changesCount.js';
|
|
||||||
import {
|
import {
|
||||||
Separator,
|
Separator,
|
||||||
StyledFlexAlignCenterBox,
|
StyledFlexAlignCenterBox,
|
||||||
|
@ -26,8 +26,6 @@ export class FakeFeatureLifecycleStore implements IFeatureLifecycleStore {
|
|||||||
return results.filter((result) => result !== null) as NewStage[];
|
return results.filter((result) => result !== null) as NewStage[];
|
||||||
}
|
}
|
||||||
|
|
||||||
async backfill() {}
|
|
||||||
|
|
||||||
private async insertOne(
|
private async insertOne(
|
||||||
featureLifecycleStage: FeatureLifecycleStage,
|
featureLifecycleStage: FeatureLifecycleStage,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
@ -82,7 +82,6 @@ export class FeatureLifecycleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
listen() {
|
listen() {
|
||||||
this.featureLifecycleStore.backfill();
|
|
||||||
this.eventStore.on(FEATURE_CREATED, async (event) => {
|
this.eventStore.on(FEATURE_CREATED, async (event) => {
|
||||||
await this.featureInitialized(event.featureName);
|
await this.featureInitialized(event.featureName);
|
||||||
});
|
});
|
||||||
|
@ -25,5 +25,4 @@ export interface IFeatureLifecycleStore {
|
|||||||
delete(feature: string): Promise<void>;
|
delete(feature: string): Promise<void>;
|
||||||
deleteAll(): Promise<void>;
|
deleteAll(): Promise<void>;
|
||||||
deleteStage(stage: FeatureLifecycleStage): Promise<void>;
|
deleteStage(stage: FeatureLifecycleStage): Promise<void>;
|
||||||
backfill(): Promise<void>;
|
|
||||||
}
|
}
|
||||||
|
@ -37,26 +37,6 @@ export class FeatureLifecycleStore implements IFeatureLifecycleStore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async backfill(): Promise<void> {
|
|
||||||
const stopTimer = this.timer('backfill');
|
|
||||||
await this.db.raw(`
|
|
||||||
INSERT INTO feature_lifecycles (feature, stage, created_at)
|
|
||||||
SELECT features.name, 'initial', features.created_at
|
|
||||||
FROM features
|
|
||||||
LEFT JOIN feature_lifecycles ON features.name = feature_lifecycles.feature
|
|
||||||
WHERE feature_lifecycles.feature IS NULL
|
|
||||||
`);
|
|
||||||
await this.db.raw(`
|
|
||||||
INSERT INTO feature_lifecycles (feature, stage, created_at)
|
|
||||||
SELECT features.name, 'archived', features.archived_at
|
|
||||||
FROM features
|
|
||||||
LEFT JOIN feature_lifecycles ON features.name = feature_lifecycles.feature AND feature_lifecycles.stage = 'archived'
|
|
||||||
WHERE features.archived_at IS NOT NULL
|
|
||||||
AND feature_lifecycles.feature IS NULL
|
|
||||||
`);
|
|
||||||
stopTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
async insert(
|
async insert(
|
||||||
featureLifecycleStages: FeatureLifecycleStage[],
|
featureLifecycleStages: FeatureLifecycleStage[],
|
||||||
): Promise<NewStage[]> {
|
): Promise<NewStage[]> {
|
||||||
|
@ -211,55 +211,3 @@ test('should be able to toggle between completed/uncompleted', async () => {
|
|||||||
|
|
||||||
expect(body).toEqual([]);
|
expect(body).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should backfill intialized feature', async () => {
|
|
||||||
await app.createFeature('my_feature_c');
|
|
||||||
await featureLifecycleStore.delete('my_feature_c');
|
|
||||||
|
|
||||||
await featureLifecycleStore.backfill();
|
|
||||||
|
|
||||||
const { body } = await getFeatureLifecycle('my_feature_c');
|
|
||||||
expect(body).toEqual([
|
|
||||||
{ stage: 'initial', enteredStageAt: expect.any(String) },
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should backfill archived feature', async () => {
|
|
||||||
await app.createFeature('my_feature_d');
|
|
||||||
await app.archiveFeature('my_feature_d');
|
|
||||||
await featureLifecycleStore.delete('my_feature_d');
|
|
||||||
|
|
||||||
await featureLifecycleStore.backfill();
|
|
||||||
|
|
||||||
const { body } = await getFeatureLifecycle('my_feature_d');
|
|
||||||
expect(body).toEqual([
|
|
||||||
{ stage: 'initial', enteredStageAt: expect.any(String) },
|
|
||||||
{ stage: 'archived', enteredStageAt: expect.any(String) },
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should not backfill for existing lifecycle', async () => {
|
|
||||||
const environment = 'production'; // prod environment moves lifecycle to live stage
|
|
||||||
await app.createFeature('my_feature_e');
|
|
||||||
await app.enableFeature('my_feature_e', environment);
|
|
||||||
eventStore.emit(FEATURE_CREATED, { featureName: 'my_feature_e' });
|
|
||||||
eventBus.emit(CLIENT_METRICS_ADDED, [
|
|
||||||
{
|
|
||||||
featureName: 'my_feature_e',
|
|
||||||
environment: environment,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
await reachedStage('my_feature_e', 'live');
|
|
||||||
|
|
||||||
await featureLifecycleStore.backfill();
|
|
||||||
|
|
||||||
const { body } = await getFeatureLifecycle('my_feature_e');
|
|
||||||
expect(body).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
{ stage: 'initial', enteredStageAt: expect.any(String) },
|
|
||||||
{ stage: 'pre-live', enteredStageAt: expect.any(String) },
|
|
||||||
{ stage: 'live', enteredStageAt: expect.any(String) },
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
expect(body).toHaveLength(3);
|
|
||||||
});
|
|
||||||
|
Loading…
Reference in New Issue
Block a user