-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add elapsed time to data migration entity (#1438)
* Add elapsed time to data migration entity * rush change * fix elapsed time calculation
- Loading branch information
1 parent
57bc3b8
commit b37bb44
Showing
5 changed files
with
57 additions
and
8 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...anges/@boostercloud/framework-core/add_elapsed_time_data_migrations_2023-10-04-08-36.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
28 changes: 25 additions & 3 deletions
28
...framework-core/src/core-concepts/data-migration/entities/booster-data-migration-entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 13 additions & 3 deletions
16
packages/framework-integration-tests/src/read-models/data-migrations-read-model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters