Skip to content

Commit

Permalink
Streaming-only subs are now actually paused
Browse files Browse the repository at this point in the history
DB transfers in any direction now generate backups and associated logs are set to info
  • Loading branch information
Tzahi12345 committed Jun 27, 2022
1 parent 301451d commit 2dc6813
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,15 @@ function calculateSubcriptionRetrievalDelay(subscriptions_amount) {
}

async function watchSubscriptions() {
// auto pause deprecated streamingOnly mode
await db_api.updateRecords('subscriptions', {streamingOnly: true}, {paused: true});

let subscriptions = await subscriptions_api.getAllSubscriptions();

if (!subscriptions) return;

const valid_subscriptions = subscriptions.filter(sub => !sub.paused);
// auto pause deprecated streamingOnly mode
const streaming_only_subs = subscriptions.filter(sub => sub.streamingOnly);
subscriptions_api.updateSubscriptionPropertyMultiple(streaming_only_subs, {paused: true});

const valid_subscriptions = subscriptions.filter(sub => !sub.paused && !sub.streamingOnly);

let subscriptions_amount = valid_subscriptions.length;
let delay_interval = calculateSubcriptionRetrievalDelay(subscriptions_amount);
Expand Down
7 changes: 4 additions & 3 deletions backend/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ exports.backupDB = async () => {
const backup_file_name = `${using_local_db ? 'local' : 'remote'}_db.json.${Date.now()/1000}.bak`;
const path_to_backups = path.join(backup_dir, backup_file_name);

logger.verbose(`Backing up ${using_local_db ? 'local' : 'remote'} DB to ${path_to_backups}`);
logger.info(`Backing up ${using_local_db ? 'local' : 'remote'} DB to ${path_to_backups}`);

const table_to_records = {};
for (let i = 0; i < tables_list.length; i++) {
Expand Down Expand Up @@ -1032,10 +1032,11 @@ exports.transferDB = async (local_to_remote) => {
table_to_records[table] = await exports.getRecords(table);
}

logger.info('Backup up DB...');
await exports.backupDB(); // should backup always

using_local_db = !local_to_remote;
if (local_to_remote) {
logger.debug('Backup up DB...');
await exports.backupDB();
const db_connected = await exports.connectToDB(5, true);
if (!db_connected) {
logger.error('Failed to transfer database - could not connect to MongoDB. Verify that your connection URL is valid.');
Expand Down
2 changes: 1 addition & 1 deletion backend/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ async function updateSubscription(sub) {

async function updateSubscriptionPropertyMultiple(subs, assignment_obj) {
subs.forEach(async sub => {
await updateSubscriptionProperty(sub, assignment_obj, sub.user_uid);
await updateSubscriptionProperty(sub, assignment_obj);
});
}

Expand Down

0 comments on commit 2dc6813

Please sign in to comment.