ScheduledLockService

uk.gov.hmrc.mongo.lock.ScheduledLockService
See theScheduledLockService companion object

A locking implementation for scheduled tasks that will only execute the body when a new lock has been acquired.

The lock's ttl is set to be schedulerInterval + 1 second, meaning that the instance that currently owns the lock will always have a chance to refresh the lock and extend the ttl.

If the lock is successfully refreshed, then body will not be executed, as being able to refresh the lock signals that the body of the previous invocation hasn't yet completed.

Once the body has completed it will either:

  • Release the lock immediately, when the body has taken longer than the schedulerInterval to complete
  • Disown the lock and amend the ttl to reflect the cadence of the scheduled task

In the event that the scheduled task ends in failure, the lock will be released immediately.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def withLock[T](body: => Future[T])(implicit ec: ExecutionContext): Future[Option[T]]

Runs body only when a new lock has been acquired, the instance that owns the lock will continue to refresh the lock until the body has completed.

Runs body only when a new lock has been acquired, the instance that owns the lock will continue to refresh the lock until the body has completed.

Once the body has completed, the lock will either be released immediately or abandoned depending upon how long body took to complete.

Attributes

Abstract fields

val lockId: String
val schedulerInterval: Duration