Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve continuous export failure recovery by moving the export operation "progress marker" from USB drive to VxScan store #4213

Merged
merged 5 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/central-scan/backend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ function dateTimeFromNoOffsetSqliteDate(noOffsetSqliteDate: string): DateTime {
export class Store {
private constructor(private readonly client: DbClient) {}

// Used by shared CVR export logic in libs/backend
// eslint-disable-next-line vx/gts-no-public-class-fields
readonly scannerType = 'central';

getDbPath(): string {
return this.client.getDatabasePath();
}
Expand Down
10 changes: 8 additions & 2 deletions apps/scan/backend/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ create table sheets (
);

create table system_settings (
-- enforce singleton table
-- Enforce singleton table
id integer primary key check (id = 1),
data text not null -- JSON blob
);

create table is_continuous_export_operation_in_progress (
-- Enforce singleton table
id integer primary key check (id = 1),
is_continuous_export_operation_in_progress boolean not null
);

create table export_directory_name (
-- enforce singleton table
-- Enforce singleton table
id integer primary key check (id = 1),
export_directory_name text not null
);
Expand Down
45 changes: 41 additions & 4 deletions apps/scan/backend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export class Store {
private readonly uiStringsStore: UiStringsStore
) {}

// Used by shared CVR export logic in libs/backend
// eslint-disable-next-line vx/gts-no-public-class-fields
readonly scannerType = 'precinct';

getDbPath(): string {
return this.client.getDatabasePath();
}
Expand Down Expand Up @@ -823,15 +827,44 @@ export class Store {
return safeParseSystemSettings(result.data).unsafeUnwrap();
}

isContinuousExportOperationInProgress(): boolean {
const row = this.client.one(
`
select
is_continuous_export_operation_in_progress as isContinuousExportOperationInProgress
from is_continuous_export_operation_in_progress
`
) as { isContinuousExportOperationInProgress: number } | undefined;
return Boolean(row?.isContinuousExportOperationInProgress);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added a type + basic utils to admin/backend/src/store.ts for being more explicit about these boolean conversions. What do you think about copying those or moving them to a shared library to use in this store file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice! Can move to a shared location

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a9caa14

}

setIsContinuousExportOperationInProgress(
isContinuousExportOperationInProgress: boolean
): void {
this.client.run('delete from is_continuous_export_operation_in_progress');
this.client.run(
`
insert into is_continuous_export_operation_in_progress (
is_continuous_export_operation_in_progress
) values (?)
`,
isContinuousExportOperationInProgress ? 1 : 0
);
}

/**
* Gets the name of the directory that we're continuously exporting to, e.g.
* TEST__machine_SCAN-0001__2023-08-16_17-02-24. Returns undefined if not yet set.
*/
getExportDirectoryName(): string | undefined {
const result = this.client.one(
'select export_directory_name as exportDirectoryName from export_directory_name'
const row = this.client.one(
`
select
export_directory_name as exportDirectoryName
from export_directory_name
`
) as { exportDirectoryName: string } | undefined;
return result?.exportDirectoryName;
return row?.exportDirectoryName;
}

/**
Expand All @@ -840,7 +873,11 @@ export class Store {
setExportDirectoryName(exportDirectoryName: string): void {
this.client.run('delete from export_directory_name');
this.client.run(
'insert into export_directory_name (export_directory_name) values (?)',
`
insert into export_directory_name (
export_directory_name
) values (?)
`,
exportDirectoryName
);
}
Expand Down