This repository has been archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
schedule-tasks.js
98 lines (89 loc) · 2.51 KB
/
schedule-tasks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict';
var debug = require('debug')(__filename.slice(__dirname.length + 1));
var fs = require('fs');
var util = require('./crater-util');
var tc = require('taskcluster-client');
var Promise = require('promise');
var slugid = require('slugid');
var scheduler = require('./scheduler');
var crateIndex = require('./crate-index');
var db = require('./crater-db');
function main() {
var options = parseOptionsFromArgs();
if (!options) {
console.log("can't parse options");
process.exit(1);
}
debug("scheduling for toolchain %s", JSON.stringify(options));
var config = util.loadDefaultConfig();
crateIndex.updateCaches(config).then(function() {
if (options.type == "crate-build") {
db.connect(config).then(function(dbctx) {
Promise.resolve().then(function() {
return scheduler.createSchedule(options, config, dbctx);
}).then(function(schedule) {
return scheduler.scheduleBuilds(dbctx, schedule, config);
}).then(function(tasks) {
console.log("created " + tasks.length + " tasks");
}).then(function() {
db.disconnect(dbctx);
}).catch(function(e) {
console.log("error: " + e);
db.disconnect(dbctx);
}).done();
});
} else {
Promise.resolve().then(function() {
return scheduler.scheduleCustomBuild(options, config);
}).catch(function(e) {
console.log("error: " + e);
}).done();
}
}).catch(function(e) {
console.log("error: " + e);
}).done();
}
function parseOptionsFromArgs() {
var type = process.argv[2];
if (type == "crate-build") {
var toolchain = util.parseToolchain(process.argv[3])
var top = null;
var mostRecentOnly = false;
var crateName = null;
var skipExisting = false;
for (var i = 4; i < process.argv.length; i++) {
if (process.argv[i] == "--top") {
top = parseInt(process.argv[i + 1]);
}
if (process.argv[i] == "--most-recent-only") {
mostRecentOnly = true;
}
if (process.argv[i] == "--name") {
crateName = process.argv[i + 1];
}
if (process.argv[i] == "--skip-existing") {
skipExisting = true;
}
}
return {
type: "crate-build",
toolchain: toolchain,
top: top,
mostRecentOnly: mostRecentOnly,
crateName: crateName,
skipExisting: skipExisting
};
} else if (type == "custom-build") {
var gitRepo = process.argv[3];
var commitSha = process.argv[4];
if (!gitRepo || !commitSha) {
return null;
}
return {
type: "custom-build",
gitRepo: gitRepo,
commitSha: commitSha
};
}
}
main();