Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add elapsed time to data migration entity #1438

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@boostercloud/framework-core",
"comment": "Add elapsed time to data migration entities",
"type": "minor"
}
],
"packageName": "@boostercloud/framework-core"
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
import { DataMigrationStatus } from '@boostercloud/framework-types'
import { BoosterDataMigrationEntityDuration, DataMigrationStatus } from '@boostercloud/framework-types'
import { BoosterDataMigrationStarted } from '../events/booster-data-migration-started'
import { BoosterDataMigrationFinished } from '../events/booster-data-migration-finished'

export class BoosterDataMigrationEntity {
public constructor(public id: string, public status: DataMigrationStatus, public lastUpdated: string) {}
public constructor(
public id: string,
public status: DataMigrationStatus,
public lastUpdated: string,
public duration?: BoosterDataMigrationEntityDuration
) {}

public static started(
event: BoosterDataMigrationStarted,
currentDataMigration: BoosterDataMigrationEntity
): BoosterDataMigrationEntity {
return new BoosterDataMigrationEntity(event.name, DataMigrationStatus.RUNNING, event.lastUpdated)
const duration = {
start: new Date().toISOString(),
}
return new BoosterDataMigrationEntity(event.name, DataMigrationStatus.RUNNING, event.lastUpdated, duration)
}

public static finished(
event: BoosterDataMigrationFinished,
currentDataMigration: BoosterDataMigrationEntity
): BoosterDataMigrationEntity {
const current = new Date()
if (currentDataMigration.duration?.start) {
const start = currentDataMigration.duration.start
const end = current.toISOString()
const startTime = Date.parse(start)
const endTime = current.getTime()
const elapsedTime = endTime - startTime
const duration: BoosterDataMigrationEntityDuration = {
start: start,
end: end,
elapsedMilliseconds: elapsedTime,
}
return new BoosterDataMigrationEntity(event.name, DataMigrationStatus.FINISHED, event.lastUpdated, duration)
}
return new BoosterDataMigrationEntity(event.name, DataMigrationStatus.FINISHED, event.lastUpdated)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,10 @@ describe('Entities end-to-end tests', () => {
})
},
(result) => {
const count = result?.data?.ListDataMigrationsReadModels?.count
const resultReadModels = result?.data?.ListDataMigrationsReadModels
const count = resultReadModels?.count
if (count < 2) {
return `Waiting for ${count} migrations. Done ${count} migrations`
return `Waiting for at least 2 migrations. Done ${count} migrations. ${JSON.stringify(resultReadModels)}`
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import { BoosterDataMigrationEntity, Projects, ReadModel } from '@boostercloud/framework-core'
import { ProjectionResult } from '@boostercloud/framework-types'
import { BoosterDataMigrationEntityDuration, ProjectionResult } from '@boostercloud/framework-types'

@ReadModel({
authorize: 'all',
})
export class DataMigrationsReadModel {
public constructor(readonly id: string, readonly status: string, readonly lastUpdated: string) {}
public constructor(
readonly id: string,
readonly status: string,
readonly lastUpdated: string,
readonly duration?: BoosterDataMigrationEntityDuration
) {}

@Projects(BoosterDataMigrationEntity, 'id')
public static updated(
migration: BoosterDataMigrationEntity,
_oldMigration?: DataMigrationsReadModel
): ProjectionResult<DataMigrationsReadModel> {
return new DataMigrationsReadModel(migration.id, migration.status.toString(), migration.lastUpdated)
return new DataMigrationsReadModel(
migration.id,
migration.status.toString(),
migration.lastUpdated,
migration.duration
)
}
}
6 changes: 6 additions & 0 deletions packages/framework-types/src/concepts/data-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ export interface DataMigrationMetadata {
readonly class: DataMigrationInterface
migrationOptions: DataMigrationParameters
}

export interface BoosterDataMigrationEntityDuration {
start: string
end?: string
elapsedMilliseconds?: number
}
Loading