Skip to content

Instantly share code, notes, and snippets.

@swcho
Created May 20, 2016 06:00
Show Gist options
  • Save swcho/de8448f84951e22eb5c41d113d2a9bbb to your computer and use it in GitHub Desktop.
Save swcho/de8448f84951e22eb5c41d113d2a9bbb to your computer and use it in GitHub Desktop.
promise 2 generator
(async function setup() {
let j = jenkins.getJenkins();
let Family = aApp.models['Family'];
let Project = aApp.models['Project'];
let Job = aApp.models['Job'];
try {
await Family.destroyAll();
await Project.destroyAll();
await Job.destroyAll();
for (let family_id of j.getFamilyNames()) {
let family = await Family.create({ id: family_id });
console.log('F: ' + family.id);
for (let project_id of j.getProjectNames(family_id)) {
let project = await family.projects.create({id: project_id});
console.log('P: ' + project.id);
for (let job_id of j.getJobNames(project.id)) {
let job = await project.jobs.create({id: job_id});
console.log('J: ' + job.id);
}
}
}
} catch(err) {
console.log(err);
}
}());
var j = jenkins.getJenkins();
var Family = aApp.models['Family'];
var Project = aApp.models['Project'];
var Job = aApp.models['Job'];
var q = Family.destroyAll();
q = q.then(function(){
logger.debug('Family Destroyed');
return Project.destroyAll();
});
q = q.then(function(){
logger.debug('Project Destroyed');
return Job.destroyAll();
});
j.getFamilyNames().forEach(function(family_id) {
q = q.then(function() {
return Family.create({ id: family_id }).then(function(family) {
logger.debug(util.format('Family %s', family.id));
var q = Q.resolve<any>(null);
j.getProjectNames(family_id).forEach(function(project_id) {
q = q.then(function() {
return family.projects.create({id: project_id});
});
q = q.then(function(project) {
logger.debug(util.format('Project %s', project.id));
var jobs = [];
j.getJobNames(project.id).forEach(function(job_id) {
jobs.push({
id: job_id
});
});
return project.jobs.create(jobs);
});
q.then(function(jobs){
_.forEach(jobs, function(item) {
logger.debug(util.format('Job: %s', item.id));
});
});
});
return q;
})
;
});
});
q.then(function() {
logger.profile('updateDatabase');
done(null, {});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment