-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed bug, added env variables (#712)
* fixed bug, added env variables * deleted json files
- Loading branch information
1 parent
ce6a8d5
commit 2804065
Showing
5 changed files
with
97 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,33 @@ | ||
const yargs = require('yargs'); | ||
const Command = require('../../Command'); | ||
const yargs = require("yargs"); | ||
const Command = require("../../Command"); | ||
|
||
const command = new Command({ | ||
command: 'offline-logs', | ||
root: true, | ||
description: 'Manages offline logs', | ||
webDocs: { | ||
category: 'Logs category', | ||
subCategory: 'Logs sub category', | ||
title: 'Archives old logs to file or collection.', | ||
}, | ||
builder: (yargs) => { | ||
// set options which are used in both sub-commands | ||
return yargs | ||
.option('uri', { | ||
describe: "Mongodb URI", | ||
demandOption: true, | ||
type: "string", | ||
}) | ||
.option('db', { | ||
describe: "Database name", | ||
demandOption: true, | ||
type: "string", | ||
}) | ||
.option('collections', { | ||
alias: "c", | ||
describe: "Source collections names", | ||
default: ["logs", "metadata"], | ||
array: true, | ||
type: "string", | ||
}) | ||
.option('cutoffDate', { | ||
alias: "cod", | ||
describe: | ||
"The date in ISO format (yyyy-MM-dd) from which logs will be archived (going backwards, including logs from that day).", | ||
demandOption: true, | ||
type: "string", | ||
}); | ||
}, | ||
handler: () => { | ||
yargs.showHelp(); | ||
}, | ||
command: "offline-logs", | ||
root: true, | ||
description: "Manages offline logs", | ||
webDocs: { | ||
category: "Logs category", | ||
subCategory: "Logs sub category", | ||
title: "Archives old logs to file or collection.", | ||
}, | ||
builder: (yargs) => { | ||
// set options which are used in both sub-commands | ||
return yargs | ||
.env("RUNTIME_MONGO") | ||
.option("uri", { | ||
describe: | ||
"Mongodb URI. If not provided, will be parsed from environment variables.", | ||
type: "string", | ||
}) | ||
.option("db", { | ||
describe: | ||
"Database name. If not provided, will be parsed from environment variables.", | ||
type: "string", | ||
}); | ||
}, | ||
handler: () => { | ||
yargs.showHelp(); | ||
}, | ||
}); | ||
|
||
module.exports = command; |
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 |
---|---|---|
@@ -1,24 +1,43 @@ | ||
const moment = require('moment'); | ||
const readline = require("readline"); | ||
const moment = require("moment"); | ||
|
||
const { join } = require('path'); | ||
const fs = require('fs'); | ||
const { join } = require("path"); | ||
const fs = require("fs"); | ||
|
||
const defaultCollections = ["logs", "metadata"]; | ||
|
||
// converts date to objectId for filter purposes | ||
const objectIdFromDate = function (date) { | ||
return Math.floor(date.getTime() / 1000).toString(16) + "0000000000000000"; | ||
return Math.floor(date.getTime() / 1000).toString(16) + "0000000000000000"; | ||
}; | ||
|
||
const writeLogsToFile = function(upperBound, lowerBound, collection, logsToArchive, path) { | ||
const date = moment(upperBound).subtract(1, "days") | ||
const fileDateRange = `${moment(lowerBound).format('YYYY-MM-DD')}-${date.format('YYYY-MM-DD')}` | ||
const writeLogsToFile = function ( | ||
upperBound, | ||
lowerBound, | ||
collection, | ||
logsToArchive, | ||
path | ||
) { | ||
const date = moment(upperBound).subtract(1, "days"); | ||
const fileDateRange = `${moment(lowerBound).format( | ||
"YYYY-MM-DD" | ||
)}-${date.format("YYYY-MM-DD")}`; | ||
const fileName = `${fileDateRange}-${collection}.json`; | ||
const absPath = join(path, fileName); | ||
const data = JSON.stringify(logsToArchive); | ||
fs.writeFileSync(absPath, data); | ||
console.info(`logs from collection '${collection}' were offloaded to '${absPath}'`) | ||
}; | ||
|
||
const checkRemnant = function (lowerBound, cutoffDateObj) { | ||
return Math.ceil(cutoffDateObj.diff(lowerBound, "days")); | ||
}; | ||
|
||
const checkRemnant = function(lowerBound, cutoffDateObj) { | ||
return Math.ceil(cutoffDateObj.diff(lowerBound , "days" )); | ||
} | ||
|
||
module.exports = {objectIdFromDate, writeLogsToFile, checkRemnant}; | ||
|
||
module.exports = { | ||
objectIdFromDate, | ||
writeLogsToFile, | ||
checkRemnant, | ||
defaultCollections, | ||
}; |
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