This repository has been archived by the owner on Sep 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
64 lines (49 loc) · 1.83 KB
/
index.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
require("dotenv").config();
const AsyncAirtable = require('asyncairtable');
const issues = require('./issues')
const asyncAirtable = new AsyncAirtable(process.env.AIRTABLE_KEY, process.env.AIRTABLE_BASE);
const TABLE_NAME = "Data Sources"
async function createIssues() {
console.log('Starting create issues task...')
const approvedRecords = await asyncAirtable.select(TABLE_NAME, {
filterByFormula: 'Stage = "Approved"'
});
approvedRecords.forEach(async (r) => {
let fields = r.fields
let banned_fields = ['fetch_issue_id', 'parse_issue_id', 'normalize_issue_id']
let required_fields = ['Runner Path', 'Source Link']
for (const field of banned_fields) {
if (fields.hasOwnProperty(field)) {
console.log(`Record ${r.id} already has field ${field}, bailing!`)
return
}
}
for (const field of required_fields) {
if (!fields.hasOwnProperty(field)) {
console.log(`Record ${r.id} doesn't have field ${field}, bailing!`)
return
}
}
let runnerPath = fields['Runner Path']
let url = fields['Source Link']
// make issue
let fetchNum = await issues.createFetchIssue(runnerPath, url)
let parseNum = await issues.createParseIssue(runnerPath, fetchNum)
let normalizeNum = await issues.createNormalizeIssue(runnerPath, parseNum)
// TODO: add backoff-retry to airtable update. Without this, highly
// parallel jobs tend to overwhelm the airtable API throttling,
// resulting in issues being created but not noted in airtable.
// Alternatively, restructure to diminish airtable calls.
let res = await asyncAirtable.updateRecord(TABLE_NAME, {
id: r.id, fields: {
fetch_issue_id: fetchNum.toString(),
parse_issue_id: parseNum.toString(),
normalize_issue_id: normalizeNum.toString()
}
});
console.log(`Issues successfully created for ${runnerPath}.`)
})
}
(async () => {
createIssues()
})();