Skip to content

Commit

Permalink
Add legacy training complete sheet, will query google as required
Browse files Browse the repository at this point in the history
  • Loading branch information
Lan2u committed Sep 15, 2024
1 parent ed46727 commit 892dd65
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const Config = t.strict({
(5 * 60 * 1000) as t.Int
),
GOOGLE_SERVICE_ACCOUNT_KEY_JSON: t.union([t.undefined, t.string]),
LEGACY_TRAINING_COMPLETE_SHEET: withDefaultIfEmpty(t.string, '1Do4CbGZ7ndvK0955nBOi1psn7jVxgvRZHhlsQbZR3_Y'),
});

export type Config = t.TypeOf<typeof Config>;
Expand Down
3 changes: 2 additions & 1 deletion src/init-dependencies/init-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export const initDependencies = (
pullGoogleSheetData(auth),
deps,
logger,
conf.QUIZ_RESULT_REFRESH_COOLDOWN_MS
conf.QUIZ_RESULT_REFRESH_COOLDOWN_MS,
conf.LEGACY_TRAINING_COMPLETE_SHEET,
)
);
} else {
Expand Down
21 changes: 19 additions & 2 deletions src/training-sheets/training-sheets-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {StatusCodes} from 'http-status-codes';
import {Failure} from '../types';
import {DateTime} from 'luxon';
import {sheets_v4} from '@googleapis/sheets';
import { Config } from '../configuration';

const byEquipmentId: Ord<RegEvent> = pipe(
S.Ord,
Expand Down Expand Up @@ -125,11 +126,23 @@ const process =
);
};

const processLegacyTrainingCompleteSheet= async (
pullGoogleSheetData: PullSheetData,
deps: Dependencies,
logger: Logger,
): Promise<void> => {
logger.info('Checking legacy training complete sheet for results...');
const data = await pullGoogleSheetData(logger, deps)

LEGACY_TRAINING_COMPLETE_SHEET
}

export const updateTrainingQuizResults = async (
pullGoogleSheetData: PullSheetData,
deps: Dependencies,
logger: Logger,
refreshCooldownMs: T.Int
refreshCooldownMs: T.Int,
legacyTrainingSheetId: string,
): Promise<void> => {
try {
if (deps.trainingQuizRefreshRunning) {
Expand All @@ -151,7 +164,7 @@ export const updateTrainingQuizResults = async (

const start = performance.now();
logger.info(
'Running training sheets worker job. Getting existing events...'
'Running training sheets worker job...'
);
const newEvents = await pipe(
{
Expand Down Expand Up @@ -197,6 +210,10 @@ export const updateTrainingQuizResults = async (
);
}
logger.info('Finished commiting training sheet quiz results');
await processLegacyTrainingCompleteSheet(
pullGoogleSheetData, deps, logger
);
logger.info('Finished processing legacy training complete sheet')
logger.info(
`Took ${Math.round(
performance.now() - start
Expand Down
17 changes: 17 additions & 0 deletions tests/data/legacy_training_complete_data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { sheets_v4 } from "@googleapis/sheets";

interface ManualParsedEntry {

}

interface ManualParsed {
data: sheets_v4.Schema$Spreadsheet;
entries: ManualParsedEntry[];
};

export const LEGACY_TRAINING_COMPLETE: ManualParsed = {
data: JSON.parse(
readFileSync('./tests/data/legacy_training_sheet.json', 'utf8')
) as sheets_v4.Schema$Spreadsheet,
entries: []
}
3 changes: 2 additions & 1 deletion tests/training-sheets/process-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ describe('Training sheets worker', () => {
localPullGoogleSheetData,
deps,
deps.logger,
0 as T.Int
0 as T.Int,

);
expect(deps.commitedEvents).toHaveLength(0);
});
Expand Down

0 comments on commit 892dd65

Please sign in to comment.