Skip to content

Commit

Permalink
log state lock acquisition
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuss committed May 11, 2022
1 parent f03b487 commit 5d48f02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/services/GithubService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ export class GithubService {
const tokenSha = crypto.createHash('sha256').update(auth).digest().toString('base64');

console.log(
`Inferring identity (auth: ${auth} sha: ${tokenSha} owner: ${owner}, repo: ${repo}, workspace: ${workspace}, stateLockRequest: ${JSON.stringify(
`Inferring identity (auth: ${auth.substring(
0,
10,
)} sha: ${tokenSha} owner: ${owner}, repo: ${repo}, workspace: ${workspace}, stateLockRequest: ${JSON.stringify(
stateLockRequest,
)})`,
);
Expand Down
14 changes: 8 additions & 6 deletions src/services/StateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ export class StateService {
const lockedBy = crypto.createHash('sha256').update(identity.token, 'utf8').digest('base64');
const path = stateLockRequest.Path || '';

let stateLock = await this.stateLockModel.model.get(
StateLockModel.prefix('pk', identity.ownerId),
StateLockModel.prefix('sk', `${identity.repoId}_${identity.workspace}_${path}`),
);
const pk = StateLockModel.prefix('pk', identity.ownerId);
const sk = StateLockModel.prefix('sk', `${identity.repoId}_${identity.workspace}_${path}`);

console.log(`Acquiring state lock (pk: ${pk} sk: ${sk})`);

let stateLock = await this.stateLockModel.model.get(pk, sk);

if (stateLock && stateLock.attrs.lockedBy !== lockedBy) {
console.warn(
Expand All @@ -132,8 +134,8 @@ export class StateService {

// TODO Catch overwrite exception
stateLock = await this.stateLockModel.model.create({
pk: StateLockModel.prefix('pk', identity.ownerId),
sk: StateLockModel.prefix('sk', `${identity.repoId}_${identity.workspace}_${path}`),
pk,
sk,
ownerId: identity.ownerId,
owner: identity.owner,
repoId: identity.repoId,
Expand Down

0 comments on commit 5d48f02

Please sign in to comment.