Last active
July 28, 2019 13:02
-
-
Save marttp/7381c7d7136f6ab70cbcc79315aba3c1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const config = require('../../configs/server.config'); | |
const { JOB_SCHEDULE } = config; | |
const moment = require('moment'); | |
const cron = require('node-cron'); | |
const { | |
moveFileToAnother, | |
readDirectory, | |
createUniqueFormatDirectory | |
} = require('./file.util'); | |
const { IMAGE_PATH, TMP_PATH } = require('../../configs/file.config'); | |
cron.schedule(JOB_SCHEDULE, async () => { | |
const fileList = await readDirectory(TMP_PATH); | |
if (fileList.length) { | |
const currentProcessDirectoryName = moment().format('YYYYMMDDHHmm'); | |
const eachMinutePath = await createUniqueFormatDirectory( | |
currentProcessDirectoryName, | |
IMAGE_PATH | |
); | |
await Promise.all( | |
fileList.map(async file => { | |
await moveFileToAnother(TMP_PATH, eachMinutePath, file); | |
}) | |
); | |
console.log(`Move files success at ${currentProcessDirectoryName}`); | |
} else { | |
console.log(`File not found. Nothing to do`); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment