Created
May 2, 2017 14:00
-
-
Save skinofstars/920cb4e221ccd24ec8be0d209d0229a7 to your computer and use it in GitHub Desktop.
Simple sequelize migration retry script
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
#!/usr/bin/env node | |
'use strict'; | |
const program = require('commander'); | |
const exec = require('child_process').exec; | |
program | |
.version('0.0.1') | |
.arguments('<direction>') | |
.action(function (direction) { | |
if (direction === 'up') { | |
execAndLog('sequelize db:migrate', 0, 5); | |
} | |
if (direction === 'down') { | |
execAndLog('sequelize db:migrate:undo', 0, 5); | |
} | |
}); | |
program.parse(process.argv); | |
function execAndLog(cmd, index, retries) { | |
let buffer_size = 1024 * 1024 * 1; //1MB | |
exec(cmd, {maxBuffer: buffer_size}, function (error, stdout, stderr) { | |
if (error) { | |
if (retries === 0) { | |
throw error; | |
} | |
setTimeout(() => execAndLog(cmd, index, retries - 1), 3000); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment