Skip to content

Commit

Permalink
Improve async
Browse files Browse the repository at this point in the history
  • Loading branch information
StorytellerCZ committed Aug 23, 2023
1 parent 3118b18 commit cbd9ebd
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions migrations_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ Meteor.startup(async function() {
log[level] = (message) => log(level, message)
});

if (process.env.MIGRATE) await Migrations.migrateTo(process.env.MIGRATE);
if (process.env.MIGRATE) {
try {
await Migrations.migrateTo(process.env.MIGRATE);
} catch (e) {
log.error('Failed to run migrations')
log.error(e.message || e.reason)
}
}
});

// Add a new migration:
Expand Down Expand Up @@ -172,7 +179,8 @@ Migrations._migrateTo = async function(version, rerun) {
return;
}

if (lock() === false) {
const isLock = await lock()
if (isLock === false) {
log.info('Not migrating, control is locked.');
return;
}
Expand All @@ -181,7 +189,7 @@ Migrations._migrateTo = async function(version, rerun) {
log.info('Rerunning version ' + version);
migrate('up', this._findIndexByVersion(version));
log.info('Finished migrating.');
unlock();
await unlock();
return;
}

Expand Down Expand Up @@ -248,17 +256,17 @@ Migrations._migrateTo = async function(version, rerun) {
for (let i = startIdx; i < endIdx; i++) {
migrate('up', i + 1);
currentVersion = self._list[i + 1].version;
updateVersion();
await updateVersion();
}
} else {
for (let i = startIdx; i > endIdx; i--) {
migrate('down', i);
currentVersion = self._list[i - 1].version;
updateVersion();
await updateVersion();
}
}

unlock();
await unlock();
log.info('Finished migrating.');
};

Expand Down

0 comments on commit cbd9ebd

Please sign in to comment.