Don't fail to register for tokens when upstreams are offline

This commit is contained in:
Travis Ralston 2019-04-13 17:25:30 -06:00
parent 087d15eeaa
commit d36436eca4

View File

@ -72,6 +72,10 @@ export class ScalarService {
const upstreams = await Upstream.findAll(); const upstreams = await Upstream.findAll();
await Promise.all(upstreams.map(async upstream => { await Promise.all(upstreams.map(async upstream => {
if (!await ScalarStore.isUpstreamOnline(upstream)) {
LogService.warn("ScalarService", `Skipping registration for ${mxUserId} on upstream ${upstream.id} (${upstream.name}) because it is offline`);
return null;
}
const tokens = await UserScalarToken.findAll({where: {userId: mxUserId, upstreamId: upstream.id}}); const tokens = await UserScalarToken.findAll({where: {userId: mxUserId, upstreamId: upstream.id}});
if (!tokens || tokens.length === 0) { if (!tokens || tokens.length === 0) {
LogService.info("ScalarService", "Registering " + mxUserId + " for a token at upstream " + upstream.id + " (" + upstream.name + ")"); LogService.info("ScalarService", "Registering " + mxUserId + " for a token at upstream " + upstream.id + " (" + upstream.name + ")");
@ -84,7 +88,7 @@ export class ScalarService {
upstreamId: upstream.id, upstreamId: upstream.id,
}); });
} }
})); }).filter(token => !!token));
const dimensionToken = randomString({length: 25}); const dimensionToken = randomString({length: 25});
const dimensionScalarToken = await UserScalarToken.create({ const dimensionScalarToken = await UserScalarToken.create({