Skip to content

Commit 762621e

Browse files
committed
add explicit release mutex functionality
1 parent 3abc0a9 commit 762621e

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

app/controllers/AnnotationController.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,4 +451,12 @@ class AnnotationController @Inject()(
451451
}
452452
}
453453

454+
def releaseMutex(id: ObjectId): Action[AnyContent] = sil.SecuredAction.async { implicit request =>
455+
logTime(slackNotificationService.noticeSlowRequest, durationThreshold = 1 second) {
456+
for {
457+
_ <- annotationMutexService.release(id, request.identity._id) ?~> "annotation.mutex.failed"
458+
} yield Ok
459+
}
460+
}
461+
454462
}

app/models/annotation/AnnotationMutexService.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ class AnnotationMutexService @Inject()(val lifecycle: ApplicationLifecycle,
6868
_ <- annotationMutexDAO.upsertOne(mutex.copy(expiry = Instant.in(defaultExpiryTime)))
6969
} yield MutexResult(canEdit = true, None)
7070

71+
def release(annotationId: ObjectId, userId: ObjectId): Fox[Unit] =
72+
for {
73+
mutex <- annotationMutexDAO.findOne(annotationId).shiftBox
74+
_ <- mutex match {
75+
case Full(mutex) if mutex.userId == userId =>
76+
annotationMutexDAO.deleteOne(annotationId).map(_ => ())
77+
case _ =>
78+
Fox.successful(())
79+
}
80+
} yield ()
81+
7182
def publicWrites(mutexResult: MutexResult): Fox[JsObject] =
7283
for {
7384
userOpt <- Fox.runOptional(mutexResult.blockedByUser)(user => userDAO.findOne(user)(GlobalAccessContext))
@@ -114,4 +125,6 @@ class AnnotationMutexDAO @Inject()(sqlClient: SqlClient)(implicit ec: ExecutionC
114125
def deleteExpired(): Fox[Int] =
115126
run(q"DELETE FROM webknossos.annotation_mutexes WHERE expiry < NOW()".asUpdate)
116127

128+
def deleteOne(annotationId: ObjectId): Fox[Int] =
129+
run(q"DELETE FROM webknossos.annotation_mutexes WHERE _annotation = $annotationId".asUpdate)
117130
}

conf/webknossos.latest.routes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ DELETE /annotations/:id
155155
POST /annotations/:id/merge/:mergedTyp/:mergedId controllers.AnnotationController.mergeWithoutType(id: ObjectId, mergedTyp: String, mergedId: ObjectId)
156156
GET /annotations/:id/download controllers.AnnotationIOController.downloadWithoutType(id: ObjectId, version: Option[Long], skipVolumeData: Option[Boolean], volumeDataZipFormat: Option[String])
157157
POST /annotations/:id/acquireMutex controllers.AnnotationController.tryAcquiringAnnotationMutex(id: ObjectId)
158+
DELETE /annotations/:id/mutex controllers.AnnotationController.releaseMutex(id: ObjectId)
158159

159160
GET /annotations/:typ/:id/info controllers.AnnotationController.info(typ: String, id: ObjectId, timestamp: Option[Long])
160161
DELETE /annotations/:typ/:id controllers.AnnotationController.cancel(typ: String, id: ObjectId)

frontend/javascripts/admin/rest_api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,12 @@ export async function acquireAnnotationMutex(
719719
return { canEdit, blockedByUser };
720720
}
721721

722+
export async function releaseAnnotationMutex(annotationId: string): Promise<void> {
723+
await Request.receiveJSON(`/api/annotations/${annotationId}/mutex`, {
724+
method: "DELETE",
725+
});
726+
}
727+
722728
export async function getTracingForAnnotationType(
723729
annotation: APIAnnotation,
724730
annotationLayerDescriptor: AnnotationLayerDescriptor,

0 commit comments

Comments
 (0)