Adds a configuration option to fact retrievers to define lifecycle for facts the retriever persists. Possible values are either 'items-to-live' or 'time-to-live'. The former will only n number of items in to the database for each fact per entity. The latter will remove all facts that are older than the TTL value.
Possible values:
* { itl: 5 } // Deletes all facts for the retriever/entity pair, apart from the last five
* { ttl: 1209600000 } // (2 weeks) Deletes all facts older than 2 weeks for the retriever/entity pair
* { ttl: { weeks: 2 } } // Deletes all facts older than 2 weeks for the retriever/entity pair
Signed-off-by: Jussi Hallila <jussi@hallila.com>
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { DateTime } from 'luxon';
|
||||
import { DateTime, DurationLike } from 'luxon';
|
||||
import { Config } from '@backstage/config';
|
||||
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import { Logger } from 'winston';
|
||||
@@ -190,6 +190,36 @@ export interface FactRetriever {
|
||||
| Record<string, string | symbol | (string | symbol)[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* A Luxon duration like object for time to live value
|
||||
*
|
||||
* @example
|
||||
* \{ ttl: 1209600000 \}
|
||||
* \{ ttl: \{ weeks: 4 \} \}
|
||||
*
|
||||
**/
|
||||
export type TTL = { ttl: DurationLike };
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* A number for items to live value
|
||||
*
|
||||
* @example
|
||||
* \{ itl: 10 \}
|
||||
*
|
||||
**/
|
||||
export type ITL = { itl: number };
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* A fact lifecycle definition. Determines which strategy to use to purge expired facts from the database.
|
||||
*/
|
||||
export type FactLifecycle = TTL | ITL;
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
@@ -216,4 +246,11 @@ export type FactRetrieverRegistration = {
|
||||
*
|
||||
*/
|
||||
cadence?: string;
|
||||
|
||||
/**
|
||||
* Fact lifecycle definition
|
||||
*
|
||||
* If defined this value will be used to determine expired items which will deleted when this fact retriever is run
|
||||
*/
|
||||
lifecycle?: FactLifecycle;
|
||||
};
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
TechInsightFact,
|
||||
FlatTechInsightFact,
|
||||
FactSchemaDefinition,
|
||||
FactLifecycle,
|
||||
} from './facts';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
@@ -35,8 +36,13 @@ export interface TechInsightsStore {
|
||||
*
|
||||
* @param id - Unique identifier of the fact retriever these facts relate to
|
||||
* @param facts - A collection of TechInsightFacts
|
||||
* @param lifecycle - (Optional) Fact lifecycle object indicating the expiration logic for these items
|
||||
*/
|
||||
insertFacts(id: string, facts: TechInsightFact[]): Promise<void>;
|
||||
insertFacts(
|
||||
id: string,
|
||||
facts: TechInsightFact[],
|
||||
lifecycle?: FactLifecycle,
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* @param ids - A collection of fact row identifiers
|
||||
|
||||
Reference in New Issue
Block a user