-
Notifications
You must be signed in to change notification settings - Fork 976
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into SER-2099-do-a-small-product-frontend-improve…
…ment-for-alerts
- Loading branch information
Showing
34 changed files
with
497 additions
and
124 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
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,48 @@ | ||
const plugins = require("../../plugins/pluginManager.js"); | ||
const common = require('../utils/common'); | ||
const job = require("../parts/jobs/job.js"); | ||
const log = require("../utils/log.js")("job:ttlCleanup"); | ||
|
||
/** | ||
* Class for job of cleaning expired records inside ttl collections | ||
*/ | ||
class TTLCleanup extends job.Job { | ||
/** | ||
* Run the job | ||
*/ | ||
async run() { | ||
log.d("Started running TTL clean up job"); | ||
for (let i = 0; i < plugins.ttlCollections.length; i++) { | ||
const { | ||
db = "countly", | ||
collection, | ||
property, | ||
expireAfterSeconds = 0 | ||
} = plugins.ttlCollections[i]; | ||
let dbInstance; | ||
switch (db) { | ||
case "countly": dbInstance = common.db; break; | ||
case "countly_drill": dbInstance = common.drillDb; break; | ||
case "countly_out": dbInstance = common.outDb; break; | ||
} | ||
if (!dbInstance) { | ||
log.e("Invalid db selection:", db); | ||
continue; | ||
} | ||
|
||
log.d("Started cleaning up", collection); | ||
const result = await dbInstance.collection(collection).deleteMany({ | ||
[property]: { | ||
$lte: new Date(Date.now() - expireAfterSeconds * 1000) | ||
} | ||
}); | ||
log.d("Finished cleaning up", result.deletedCount, "records from", collection); | ||
|
||
// Sleep 1 second to prevent sending too many deleteMany queries | ||
await new Promise(res => setTimeout(res, 1000)); | ||
} | ||
log.d("Finished running TTL clean up job"); | ||
} | ||
} | ||
|
||
module.exports = TTLCleanup; |
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
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
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
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
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
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
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
Oops, something went wrong.