Last active
May 19, 2016 14:47
-
-
Save morsh/7ed0da763aa4c7e6d7379efeac226c1d to your computer and use it in GitHub Desktop.
ensure-folder-hierarchy.js
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
var fse = require('fs-extra'); | |
var path = require('path'); | |
// This will be the name that will appear in the Azure Portal | |
var workerName = 'worker'; | |
console.info('Checking if should create web job folders'); | |
// Making sure this is a web job in case we want this deployment to also | |
// contain web site roles | |
if (process.env.DEPLOYMENT_ROLE === 'webjob') { | |
// Creating folders for continuous web jobs | |
if (process.env.PIPELINE_WEBJOB_TYPE === 'continuous') { | |
var sourceFile = 'app.js'; | |
var targetFile = path.join('app_data', 'jobs', 'continuous', workerName, 'app.js'); | |
// If the web job already exists, delete it (ensures the web job will restart in Azure) | |
if (fse.existsSync(targetFile)) fse.removeSync(targetFile); | |
console.info('Remove irrelevant folders completed'); | |
fse.ensureLinkSync(sourceFile, targetFile); | |
console.info('Ensuring folders completed'); | |
// Creating folder for on demand web jobs | |
} else { | |
var sourceFile1 = 'app.js'; | |
// This file is where the CRON expression is defined for when the schedule will run | |
var sourceFile2 = 'settings.job'; | |
var targetFile1 = path.join('app_data', 'jobs', 'triggered', workerName, 'app.js'); | |
var targetFile2 = path.join('app_data', 'jobs', 'triggered', workerName, 'settings.job'); | |
// If the web job already exists, delete it (ensures the web job will restart in Azure) | |
if (fse.existsSync(targetFile1)) fse.removeSync(targetFile1); | |
if (fse.existsSync(targetFile2)) fse.removeSync(targetFile2); | |
console.info('Remove irrelevant folders completed'); | |
fse.ensureLinkSync(sourceFile1, targetFile1); | |
fse.ensureLinkSync(sourceFile2, targetFile2); | |
console.info('Ensure folders completed'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment