Skip to content

Commit

Permalink
processor: Switch to "promise style" for async-lock
Browse files Browse the repository at this point in the history
  • Loading branch information
kasbah committed Apr 13, 2024
1 parent c383c14 commit b13b1cc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"1-click-bom": "https://github.com/kitspace/npm-1-click-bom#22d119c1c3c299ee98ef4bc887c75ca12881c92b",
"@aws-sdk/client-s3": "^3.194.0",
"async-lock": "^1.3.2",
"async-lock": "^1.4.1",
"bullmq": "^1.91.1",
"cheerio": "^1.0.0-rc.10",
"globule": "^1.0.0",
Expand Down
11 changes: 3 additions & 8 deletions processor/src/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,14 @@ async function getGitHash(checkoutDir: string) {
const lock = new AsyncLock()
async function sync(gitDir, checkoutDir) {
await lock
.acquire(gitDir, async done => {
.acquire(gitDir, async () => {
log.info('Acquired sync lock for ', gitDir)

const registryHash = getRegistryHash(gitDir)

if (await exists(checkoutDir)) {
if (registryHash != null) {
// no need to pull if we aren't going to use the latest commit
done()
return
}

Expand All @@ -203,19 +202,16 @@ async function sync(gitDir, checkoutDir) {
"Your configuration specifies to merge with the ref 'refs/heads/master'\nfrom the remote, but no such ref was fetched.\n"
) {
log.warn('repo without any branches', checkoutDir)
done()
return

}
done(err)
return

}
} else {
log.debug('Cloning ', gitDir)
try {
await sh`git clone ${gitDir} ${checkoutDir}`
} catch (err) {
if (err.stderr) {
done(err)
return
}
}
Expand All @@ -230,7 +226,6 @@ async function sync(gitDir, checkoutDir) {
})
}
}
done()
})
.then(() => log.debug('Released sync lock for ', gitDir))
}
Expand Down
8 changes: 4 additions & 4 deletions processor/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1556,10 +1556,10 @@ assertion-error@^1.1.0:
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"
integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==

async-lock@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/async-lock/-/async-lock-1.3.2.tgz#56668613f91c1c55432b4db73e65c9ced664e789"
integrity sha512-phnXdS3RP7PPcmP6NWWzWMU0sLTeyvtZCxBPpZdkYE3seGLKSQZs9FrmVO/qwypq98FUtWWUEYxziLkdGk5nnA==
async-lock@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/async-lock/-/async-lock-1.4.1.tgz#56b8718915a9b68b10fce2f2a9a3dddf765ef53f"
integrity sha512-Az2ZTpuytrtqENulXwO3GGv1Bztugx6TT37NIo7imr/Qo0gsYiGtSdBa2B6fsXhTpVZDNfu1Qn3pk531e3q+nQ==

asynckit@^0.4.0:
version "0.4.0"
Expand Down

0 comments on commit b13b1cc

Please sign in to comment.