Skip to content

Commit

Permalink
[AMSA-chore] hotfix sync history stats
Browse files Browse the repository at this point in the history
  • Loading branch information
NaLLiFFuNT committed Apr 17, 2019
1 parent 47065e1 commit 876d0e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/core/sync-apps/sync-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export interface SyncInfo {
export class SyncStats {

public readonly affectedApps = {
created: [],
updated: [],
deleted: [],
withErrors: []
created: new Map<string, AppInfo>(),
updated: new Map<string, AppInfo>(),
deleted: new Map<string, AppInfo>(),
withErrors: new Map<string, AppInfo>()
};

public id: string;
Expand All @@ -52,30 +52,35 @@ export class SyncStats {
}

appCreated (app: AppodealApp) {
this.affectedApps.created.push(app);
this.affectedApps.created.set(app.id, app);
}

appUpdated (app: AppodealApp) {
if (this.affectedApps.created.some(v => v.id === app.id)) {
if (this.affectedApps.created.has(app.id)) {
return;
}
this.affectedApps.updated.push(app);
this.affectedApps.updated.set(app.id, app);
}

appDeleted (app: AppodealApp) {
this.affectedApps.deleted.push(app);
this.affectedApps.deleted.set(app.id, app);
}

errorWhileSync (app: AppodealApp) {
this.affectedApps.withErrors.push(app);
this.affectedApps.withErrors.set(app.id, app);
}

toPlainObject (): SyncInfo {
return {
id: this.sync.id,
runner: this.sync.runner,
hasErrors: this.sync.hasErrors,
affectedApps: this.affectedApps,
affectedApps: {
created: [...this.affectedApps.created.values()],
updated: [...this.affectedApps.updated.values()],
deleted: [...this.affectedApps.deleted.values()],
withErrors: [...this.affectedApps.withErrors.values()]
},
startTs: this.startTs,
endTs: this.endTs,
terminated: this.terminated,
Expand Down
1 change: 1 addition & 0 deletions src/core/sync-apps/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export class Sync {
const adUnitsToDelete = this.getActiveAdmobAdUnitsCreatedByApp(app, adMobApp).map(adUnit => adUnit.adUnitId);
if (adUnitsToDelete.length) {
await this.deleteAdMobAdUnits(adUnitsToDelete);
this.context.removeAdMobAdUnits(adUnitsToDelete);
this.stats.appDeleted(app);
yield `${adUnitsToDelete.length} adUnits deleted`;
} else {
Expand Down

0 comments on commit 876d0e3

Please sign in to comment.