|
|
@@ -3,20 +3,6 @@ import { Cron, CronExpression } from '@nestjs/schedule';
|
|
|
import { ConfigService } from '@nestjs/config';
|
|
|
import { StatsAggregationService } from './stats-aggregation.service';
|
|
|
|
|
|
-type AggregationResult = {
|
|
|
- successCount: number;
|
|
|
- totalProcessed: number;
|
|
|
- errorCount: number;
|
|
|
-};
|
|
|
-
|
|
|
-type RerunRangeCapable = {
|
|
|
- rerunRange: (args: {
|
|
|
- fromSec: number;
|
|
|
- toSec: number;
|
|
|
- dryRun?: boolean;
|
|
|
- }) => Promise<unknown>;
|
|
|
-};
|
|
|
-
|
|
|
type DailyRefreshCapable = {
|
|
|
refreshDailyDerivedFromHourly: (args: {
|
|
|
fromSec: number;
|
|
|
@@ -141,35 +127,7 @@ export class StatsAggregationScheduler implements OnModuleInit {
|
|
|
this.logger.log(`${tag} start`);
|
|
|
|
|
|
try {
|
|
|
- // Preferred path: exact hour rerun (idempotent)
|
|
|
- if (this.hasRerunRange(this.statsAggregation)) {
|
|
|
- await this.statsAggregation.rerunRange({
|
|
|
- fromSec,
|
|
|
- toSec,
|
|
|
- dryRun: false,
|
|
|
- });
|
|
|
- this.logger.log(`${tag} rerunRange done`);
|
|
|
- } else {
|
|
|
- // Backward-compatible fallback
|
|
|
- const result = (await this.statsAggregation.aggregateAdsStats({
|
|
|
- windowDays: this.windowDays,
|
|
|
- })) as AggregationResult;
|
|
|
-
|
|
|
- this.logger.warn(
|
|
|
- `${tag} used fallback aggregateAdsStats(windowDays=${
|
|
|
- this.windowDays ?? 'all time'
|
|
|
- }) (${result.successCount}/${result.totalProcessed} updated, ${result.errorCount} errors)`,
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- // Optional daily refresh triggered after hourly
|
|
|
- if (this.hasDailyRefresh(this.statsAggregation)) {
|
|
|
- await this.statsAggregation.refreshDailyDerivedFromHourly({
|
|
|
- fromSec,
|
|
|
- toSec,
|
|
|
- });
|
|
|
- this.logger.log(`${tag} daily refresh done`);
|
|
|
- }
|
|
|
+ await this.statsAggregation.aggregateHourWindow({ fromSec, toSec });
|
|
|
|
|
|
this.lastHourlyWindowToSec = toSec;
|
|
|
|
|
|
@@ -259,12 +217,6 @@ export class StatsAggregationScheduler implements OnModuleInit {
|
|
|
return dayStartShifted - shift;
|
|
|
}
|
|
|
|
|
|
- private hasRerunRange(
|
|
|
- svc: StatsAggregationService,
|
|
|
- ): svc is StatsAggregationService & RerunRangeCapable {
|
|
|
- return typeof (svc as any)?.rerunRange === 'function';
|
|
|
- }
|
|
|
-
|
|
|
private hasDailyRefresh(
|
|
|
svc: StatsAggregationService,
|
|
|
): svc is StatsAggregationService & DailyRefreshCapable {
|