add missing await, rename update to safeUpdate
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
386d0d138c
commit
50604a67ed
|
@ -36,7 +36,7 @@ const App = ({ghc, schema}) => {
|
|||
await ghc.db.addBuild({
|
||||
...ctx.params, build: ctx.request.body
|
||||
})
|
||||
await ghc.update(ctx.params)
|
||||
await ghc.safeUpdate(ctx.params)
|
||||
ctx.status = 201
|
||||
ctx.body = {status:'ok'}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ const App = ({ghc, schema}) => {
|
|||
|
||||
/* just re-render the comment */
|
||||
router.post('/builds/:repo/:pr/refresh', async (ctx) => {
|
||||
await ghc.update(ctx.params)
|
||||
await ghc.safeUpdate(ctx.params)
|
||||
ctx.status = 201
|
||||
ctx.body = {status:'ok'}
|
||||
})
|
||||
|
|
|
@ -59,7 +59,7 @@ class Comments {
|
|||
return rval.data.id
|
||||
}
|
||||
|
||||
async _update ({repo, pr}) {
|
||||
async update ({repo, pr}) {
|
||||
/* check if repo is in a whitelist */
|
||||
if (!this.repos.includes(repo)) {
|
||||
throw Error(`Repo not whitelisted: ${repo}`)
|
||||
|
@ -74,14 +74,14 @@ class Comments {
|
|||
}
|
||||
}
|
||||
|
||||
async update ({repo, pr}) {
|
||||
async safeUpdate ({repo, pr}) {
|
||||
/* we use a lock to avoid creating multiple comments */
|
||||
let key = repo + pr
|
||||
/* use existing lock for repo+pr or create a new one */
|
||||
this.locks[key] || ( this.locks[key] = new AwaitLock() )
|
||||
await this.locks[key].acquireAsync()
|
||||
try {
|
||||
this._update({repo, pr})
|
||||
await this.update({repo, pr})
|
||||
} finally {
|
||||
this.locks[key].release()
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ describe('App', () => {
|
|||
expect(ghc.db.addBuild).calledOnceWith({
|
||||
repo: 'REPO-1', pr: 'PR-1', build: sample.BUILD,
|
||||
})
|
||||
expect(ghc.update).calledOnceWith({
|
||||
expect(ghc.safeUpdate).calledOnceWith({
|
||||
repo: 'REPO-1', pr: 'PR-1'
|
||||
})
|
||||
})
|
||||
|
@ -65,7 +65,7 @@ describe('App', () => {
|
|||
expect(ghc.db.addBuild).not.calledOnceWith({
|
||||
repo: 'REPO-1', pr: 'PR-1', build: sample.BUILD
|
||||
})
|
||||
expect(ghc.update).calledOnceWith({
|
||||
expect(ghc.safeUpdate).calledOnceWith({
|
||||
repo: 'REPO-1', pr: 'PR-1',
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue