Skip to content

Commit 07d267f

Browse files
authored
Merge pull request #641 from jkbschmid/jkbschmid-licensee-parallel
Make licensee's max degree of parallism configurable
2 parents a75dbd5 + c26d67a commit 07d267f

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

config/cdConfig.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ const maxRequeueAttemptCount = config.get('CRAWLER_MAX_REQUEUE_ATTEMPTS') || 5
2121
const fetchedCacheTtlSeconds = config.get('CRAWLER_FETCHED_CACHE_TTL_SECONDS') || 60 * 60 * 8 //8 hours
2222
const azqueueVisibilityTimeoutSeconds = parseInt(config.get('CRAWLER_HARVESTS_QUEUE_VISIBILITY_TIMEOUT_SECONDS'))
2323

24+
function getPositiveNum(configName, defaultValue) {
25+
const num = Number(config.get(configName))
26+
return num > 0 ? num : defaultValue
27+
}
28+
2429
module.exports = {
2530
provider: 'memory', // change this to redis if/when we want distributed config
2631
searchPath: [module],
@@ -68,7 +73,9 @@ module.exports = {
6873
},
6974
gem: { githubToken },
7075
go: { githubToken },
71-
licensee: {},
76+
licensee: {
77+
processes: getPositiveNum('CRAWLER_LICENSEE_PARALLELISM', 10)
78+
},
7279
maven: { githubToken },
7380
npm: { githubToken },
7481
nuget: { githubToken },

providers/process/licensee.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ class LicenseeProcessor extends AbstractProcessor {
5050
const root = request.document.location
5151
const subfolders = await this.getFolders(root, ['/.git'])
5252
const paths = ['', ...trimAllParents(subfolders, root)]
53+
const { processes } = this.options
5354
try {
5455
const results = (
55-
await Promise.all(paths.map(throat(10, path => this._runOnFolder(path, root, parameters))))
56+
await Promise.all(paths.map(throat(processes, path => this._runOnFolder(path, root, parameters))))
5657
).filter(x => x)
5758
const licenses = uniqBy(flatten(results.map(result => result.licenses)), 'spdx_id')
5859
const matched_files = flatten(results.map(result => result.matched_files))

test/unit/providers/process/licenseeTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('Licensee process', () => {
6969
})
7070

7171
function setup(fixture, error, versionError) {
72-
const options = { logger: { log: sinon.stub() } }
72+
const options = { logger: { log: sinon.stub() }, processes: 10 }
7373
const testRequest = new request('npm', 'cd:/npm/npmjs/-/test/1.1')
7474
testRequest.document = { _metadata: { links: {} }, location: path.resolve(`test/fixtures/licensee/${fixture}`) }
7575
testRequest.crawler = { storeDeadletter: sinon.stub() }

0 commit comments

Comments
 (0)