Skip to content

Instantly share code, notes, and snippets.

@mpobrien
Last active November 24, 2015 18:48
Show Gist options
  • Save mpobrien/e0f13d5830f295a266fc to your computer and use it in GitHub Desktop.
Save mpobrien/e0f13d5830f295a266fc to your computer and use it in GitHub Desktop.
function randomString(len, charSet) {
charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var randomString = '';
for (var i = 0; i < len; i++) {
var randomPoz = Math.floor(Math.random() * charSet.length);
randomString += charSet.substring(randomPoz,randomPoz+1);
}
return randomString;
}
// Be aware that this does *not* archive the task that was restarted,
// and does not update the build status. The build status should be
// re-synced correctly when it is picked up by the task runner, however.
function restartTask(t_id){
var updatedoc = {
"$set": {
activated:true,
secret:randomString(28),
status:"undispatched",
dispatch_time:ISODate("1970-01-01T00:00:00Z"),
start_time:ISODate("1970-01-01T00:00:00Z"),
scheduled_time:ISODate("1970-01-01T00:00:00Z"),
finish_time:ISODate("1970-01-01T00:00:00Z"),
test_results:[],
},
"$unset": {
details:1
}
}
db.tasks.update({_id:t_id}, updatedoc)
}
//
db.tasks.find({status:"failed", "details.type":"system", "details.timed_out":true, finish_time:{$gt:ISODate("2015-11-24T17:00:24.755Z")}},{branch:1, r:1}).forEach(function(x){
print("restarting task", x._id)
restartTask(x._id)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment