Skip to content

Commit

Permalink
Merge pull request bcc-code#12 from bcc-code/feat/fail-import-on-error
Browse files Browse the repository at this point in the history
No mv_ts, mv_hash update on import error
  • Loading branch information
u12206050 authored Jan 4, 2024
2 parents 1cab9cb + fc25c68 commit 36b4714
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/exportManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export class ExportManager {
await this._loadNextExporter(i + 1, merge);
if (finishUp) await finishUp();
} catch (e) {
this.logger.error(e);
this.logger.error(`Failed loading "${this.exporters[i]!.exporter.name}".`);
throw e;
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ const registerHook: HookConfig = async ({ action, init }, { env, services, datab

await updateManager.commitUpdates();
clearAdminSchema();
} catch (e) {
logger.error(e);
logger.info('Releasing lock...');
await updateManager.releaseLock();
} finally {
await attachExporters();
}
Expand Down
14 changes: 11 additions & 3 deletions src/updateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ export class UpdateManager {
if (rows.length) {
await trx(this.tableName).where('id', this.rowId).update({
mv_locked: true,
// We set this to newer than isoTS, while we do the migration
// If the migration fails, we can reset the lock
mv_ts: ExportHelper.utcTS(),
});
this._locked = {
hash: newHash,
Expand Down Expand Up @@ -74,6 +71,17 @@ export class UpdateManager {
return true;
}

public async releaseLock() {
if (!this._locked) return false;

await this.db(this.tableName).where('id', this.rowId).update({
mv_locked: false,
});

this._locked = false;
return true;
}

public async ensureInstalled() {
const tableName = 'directus_settings';

Expand Down

0 comments on commit 36b4714

Please sign in to comment.