-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix gateway backups * Not querying backup if instance is not connected to Gateway
- Loading branch information
1 parent
fcba3d2
commit 5d5ce90
Showing
4 changed files
with
40 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const logger = require('../../utils/logger'); | ||
/** | ||
* @description Check if a backup is needed | ||
* @example | ||
* checkIfBackupNeeded(); | ||
*/ | ||
async function checkIfBackupNeeded() { | ||
if (!this.connected) { | ||
logger.info(`Instance not connected to Gladys Gateway, not backing up.`); | ||
return; | ||
} | ||
const backups = await this.getBackups(); | ||
let shouldBackup = false; | ||
if (backups.length === 0) { | ||
shouldBackup = true; | ||
} else { | ||
const lastBackupTimestamp = new Date(backups[0].created_at).getTime(); | ||
const yesterday = new Date().getTime() - 24 * 60 * 60 * 1000; | ||
if (lastBackupTimestamp <= yesterday) { | ||
shouldBackup = true; | ||
} | ||
} | ||
if (shouldBackup) { | ||
logger.info(`Trying to backup instance to Gladys Gateway`); | ||
await this.backup(); | ||
} else { | ||
logger.info(`Not backing up instance to Gladys Gateway, last backup is recent.`); | ||
} | ||
} | ||
|
||
module.exports = { | ||
checkIfBackupNeeded, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters