Skip to content

Commit

Permalink
feat(promo-manager): add debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
vanilla-wave committed Aug 28, 2024
1 parent 315d667 commit 99263e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/promo-manager/core/condition/condition-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const checkCondition = (
}

if (!result) {
logger.debug('Not pass condition', condition);
return false;
}
}
Expand Down
31 changes: 25 additions & 6 deletions src/promo-manager/core/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ export class Controller {

this.status = 'idle';

this.logger = createLogger(
this.options.logger ?? {
context: 'Promo manager',
},
);
this.logger.debug('Initialization started');

this.state = JSON.parse(
JSON.stringify({
base: {
Expand All @@ -86,12 +93,6 @@ export class Controller {
}),
) as PromoState;

this.logger = createLogger(
this.options.logger ?? {
context: 'Promo manager',
},
);

if (!options.progressState) {
this.fetchProgressState().catch((error) => {
this.logger.error(error);
Expand Down Expand Up @@ -134,13 +135,16 @@ export class Controller {
}

this.saveProgress = createDebounceHandler(async () => {
this.logger.debug('Save progress');
try {
this.assertProgressLoaded();
await this.options.onSave.progress(this.state.progress);
} catch (error) {
this.logger.error(error);
}
}, 100);

this.logger.debug('Initialized');
}

ensureInit = async () => {
Expand All @@ -151,13 +155,15 @@ export class Controller {
await this.initPromise;
this.status = 'initialized';
this.events.emit('init', {});
this.logger.debug('Initialized');

await this.triggerNextPromo();
};

dateNow = () => Date.now();

requestStart = async (slug: Nullable<PromoSlug>) => {
this.logger.debug('Request start preset', slug);
if (!slug) {
return false;
}
Expand All @@ -167,6 +173,7 @@ export class Controller {
}

if (!this.isAbleToRun(slug)) {
this.logger.debug('Not able to run promo', slug);
return false;
}

Expand All @@ -180,6 +187,7 @@ export class Controller {
};

finishPromo = (slug: Nullable<PromoSlug>, closeActiveTimeout = 0) => {
this.logger.debug('Finish promo', slug);
if (!slug) {
return;
}
Expand All @@ -194,6 +202,7 @@ export class Controller {
};

cancelPromo = (slug: Nullable<PromoSlug>, closeActiveTimeout = 0) => {
this.logger.debug('Cancel promo', slug);
if (!slug) {
return;
}
Expand All @@ -203,6 +212,7 @@ export class Controller {
};

cancelStart = (slug: Nullable<PromoSlug>) => {
this.logger.debug('Skip promo run', slug);
if (!slug) {
return;
}
Expand Down Expand Up @@ -305,7 +315,9 @@ export class Controller {
}

checkPromoConditions = (slug: PromoSlug): boolean => {
this.logger.debug('Check promo conditions', slug);
if (!this.checkConstraints()) {
this.logger.debug('Not pass constraints', slug);
return false;
}

Expand All @@ -328,6 +340,7 @@ export class Controller {
conditionsForType,
this.logger,
);
this.logger.debug('Condition result for promo type', resultForType);

const resultForSlug = checkCondition(
this.state,
Expand All @@ -341,6 +354,7 @@ export class Controller {
conditionsForSlug,
this.logger,
);
this.logger.debug('Condition result for slug', resultForSlug);

return resultForType && resultForSlug;
};
Expand Down Expand Up @@ -477,6 +491,8 @@ export class Controller {
this.cancelStart(hint.preset);
}
});

this.logger.debug('Onboarding integration applied');
};

private checkConstraints() {
Expand Down Expand Up @@ -523,6 +539,7 @@ export class Controller {
};

private activatePromo = (slug: PromoSlug) => {
this.logger.debug('Actibate promo', slug);
this.stateActions.setActivePromo(slug);
this.stateActions.removeFromQueue(slug);

Expand All @@ -546,6 +563,7 @@ export class Controller {
};

private addPromoToActiveQueue = (slug: PromoSlug) => {
this.logger.debug('Add promo to the queue', slug);
this.assertProgressLoaded();

if (
Expand Down Expand Up @@ -582,6 +600,7 @@ export class Controller {
};

private closePromo = (slug: PromoSlug) => {
this.logger.debug('Close promo', slug);
if (!this.isActive(slug)) {
return;
}
Expand Down

0 comments on commit 99263e5

Please sign in to comment.