Skip to content

Commit

Permalink
fix: prevent subscribe task overrun
Browse files Browse the repository at this point in the history
  • Loading branch information
wwills2 committed Dec 20, 2024
1 parent c7d34ec commit 5315675
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/datalayer/persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ const getSubscriptions = async () => {
.send({});

const data = response.body;
logger.debug(`data returned from ${url}: ${data.store_ids}`);
logger.debug(`data returned from ${url}: ${JSON.stringify(data)}`);

if (data.success) {
return { success: true, storeIds: data.store_ids };
Expand Down
4 changes: 3 additions & 1 deletion src/datalayer/syncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ const getSubscribedStoreData = async (storeId) => {
);
const { confirmed } = await dataLayer.getRoot(storeId);
if (!confirmed) {
throw new Error(`Store not found in DataLayer: ${storeId}.`);
throw new Error(
`${storeId} has not yet been confirmed. cannot get root.`,
);
} else {
logger.debug(
`store data is confirmed available, proceeding to get data ${storeId}`,
Expand Down
6 changes: 2 additions & 4 deletions src/models/organizations/organizations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,7 @@ class Organization extends Model {
onTimeout(error);
}
logger.debug(`${error.message}. RETRYING`);
} finally {
await new Promise((resolve) => setTimeout(resolve, 300));
await new Promise((resolve) => setTimeout(resolve, 10000));
}
}

Expand All @@ -621,8 +620,7 @@ class Organization extends Model {
onTimeout(error);
}
logger.debug(`${error.message}. RETRYING`);
} finally {
await new Promise((resolve) => setTimeout(resolve, 300));
await new Promise((resolve) => setTimeout(resolve, 3000));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tasks/sync-default-organizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const task = new Task('sync-default-organizations', async () => {
const userDeletedOrgs = await Meta.getUserDeletedOrgUids();

for (const { orgUid } of defaultOrgRecords) {
if (userDeletedOrgs.includes(orgUid)) {
if (userDeletedOrgs?.includes(orgUid)) {
logger.verbose(
`default organization ${orgUid} has been explicitly removed from this instance. not adding or checking that it exists`,
);
Expand Down
6 changes: 3 additions & 3 deletions src/tasks/validate-organization-table-and-subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const task = new Task('validate-organization-table', async () => {
for (const organization of organizations) {
// this is in the loop to prevent this task from trying to operate on an organization that was deleted while it was running
const deletedOrganizations = await Meta.getUserDeletedOrgUids();
if (deletedOrganizations.includes(organization.orgUid)) {
if (deletedOrganizations?.includes(organization.orgUid)) {
continue;
}

Expand All @@ -46,7 +46,7 @@ const task = new Task('validate-organization-table', async () => {
} catch (error) {
logger.error(
`failed to validate default organization records and subscriptions. Error ${error.message}. ` +
`Retrying in ${CONFIG?.TASKS?.VALIDATE_ORGANIZATION_TABLE_TASK_INTERVAL || 30} seconds`,
`Retrying in ${CONFIG?.TASKS?.VALIDATE_ORGANIZATION_TABLE_TASK_INTERVAL || 900} seconds`,
);
}
});
Expand All @@ -61,7 +61,7 @@ const task = new Task('validate-organization-table', async () => {
*/
const job = new SimpleIntervalJob(
{
seconds: CONFIG?.TASKS?.VALIDATE_ORGANIZATION_TABLE_TASK_INTERVAL || 30,
seconds: CONFIG?.TASKS?.VALIDATE_ORGANIZATION_TABLE_TASK_INTERVAL || 900,
runImmediately: true,
},
task,
Expand Down

0 comments on commit 5315675

Please sign in to comment.