mirror of
https://github.com/veggiemonk/awesome-docker.git
synced 2025-01-25 05:56:48 -05:00
buildMetadata: use env var for fetching frequency
This commit is contained in:
parent
f5c411eb0c
commit
2b8dee31b8
@ -23,6 +23,8 @@ if (!process.env.TOKEN) {
|
|||||||
// --- ENV VAR ---
|
// --- ENV VAR ---
|
||||||
const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 10;
|
const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 10;
|
||||||
const DELAY = parseInt(process.env.DELAY, 10) || 3000;
|
const DELAY = parseInt(process.env.DELAY, 10) || 3000;
|
||||||
|
const INTERVAL = parseInt(process.env.INTERVAL, 10) || 1;
|
||||||
|
const INTERVAL_UNIT = process.env.INTERVAL_UNIT || 'days';
|
||||||
|
|
||||||
// --- FILENAME ---
|
// --- FILENAME ---
|
||||||
const README = 'README.md';
|
const README = 'README.md';
|
||||||
@ -105,30 +107,29 @@ async function batchFetchRepoMetadata(githubRepos) {
|
|||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
function shouldUpdate(fileLatestUpdate) {
|
function shouldUpdate(lastUpdateTime) {
|
||||||
LOG.debug({ fileLatestUpdate });
|
LOG.debug({ lastUpdateTime });
|
||||||
if (!fileLatestUpdate) return true;
|
if (!lastUpdateTime) return true;
|
||||||
|
|
||||||
const hours = fileLatestUpdate.slice(
|
const hours = lastUpdateTime.slice(
|
||||||
'data/YYYY-MM-DDT'.length,
|
'data/YYYY-MM-DDT'.length,
|
||||||
'data/YYYY-MM-DDTHH'.length,
|
'data/YYYY-MM-DDTHH'.length,
|
||||||
);
|
);
|
||||||
const latestUpdate = dayjs(
|
const latestUpdate = dayjs(
|
||||||
fileLatestUpdate.slice('data/'.length, 'data/YYYY-MM-DD'.length),
|
lastUpdateTime.slice('data/'.length, 'data/YYYY-MM-DD'.length),
|
||||||
).add(hours, 'hour');
|
).add(hours, 'hour');
|
||||||
|
|
||||||
LOG.debug({ latestUpdate: latestUpdate.format() });
|
LOG.debug({ latestUpdate: latestUpdate.format() });
|
||||||
|
|
||||||
const isMoreThanOneDay = dayjs().diff(latestUpdate, 'hours') >= 1;
|
return dayjs().diff(latestUpdate, INTERVAL_UNIT) >= INTERVAL;
|
||||||
return isMoreThanOneDay;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
const getLatest = await fs.readFile(LATEST_FILENAME, 'utf8');
|
const lastUpdateTime = await fs.readFile(LATEST_FILENAME, 'utf8');
|
||||||
|
|
||||||
LOG.debug('Checking if updating is needed');
|
LOG.debug('Checking if updating is needed');
|
||||||
if (!shouldUpdate(getLatest)) {
|
if (!shouldUpdate(lastUpdateTime)) {
|
||||||
LOG.debug('Last update was less than a day ago 😅. Exiting...');
|
LOG.debug('Last update was less than a day ago 😅. Exiting...');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user