WorkItemRepository

uk.gov.hmrc.mongo.workitem.WorkItemRepository
abstract class WorkItemRepository[T](collectionName: String, mongoComponent: MongoComponent, itemFormat: Format[T], val workItemFields: WorkItemFields, replaceIndexes: Boolean, extraIndexes: Seq[IndexModel], extraCodecs: Seq[Codec[_]])(implicit ec: ExecutionContext) extends PlayMongoRepository[WorkItem[T]], Cancel, FindById[T], MetricSource

The repository to set and get the work item's for processing. See pushNew for creating work items, and pullOutstanding for retrieving them.

Value parameters

collectionName

the name of the mongo collection.

extraCodecs

optional - to support more types

extraIndexes

optional - to add additional indexes

itemFormat

a play Json format to map the item to mongo entities

replaceIndexes

optional - default is true If true, existing indices should be removed/updated to match the provided indices. If false, any old indices are left behind, and indices with changed definitions will throw IndexConflict exceptions.

workItemFields

the internal fields for WorkItem, allowing customisation

Attributes

Graph
Supertypes
trait MetricSource
trait FindById[T]
trait Cancel
class PlayMongoRepository[WorkItem[T]]
trait MongoDatabaseCollection
class Object
trait Matchable
class Any
Show all
Known subtypes

Members list

Value members

Abstract methods

def inProgressRetryAfter: Duration

Returns the timeout of any WorkItems marked as InProgress. WorkItems marked as InProgress will be hidden from pullOutstanding until this window expires.

Returns the timeout of any WorkItems marked as InProgress. WorkItems marked as InProgress will be hidden from pullOutstanding until this window expires.

Attributes

def now(): Instant

Returns the current date time for setting the updatedAt field. abstract to allow for test friendly implementations.

Returns the current date time for setting the updatedAt field. abstract to allow for test friendly implementations.

Attributes

Concrete methods

def cancel(id: ObjectId): Future[StatusUpdateResult]

Sets the ProcessingStatus of a WorkItem to Cancelled.

Sets the ProcessingStatus of a WorkItem to Cancelled.

Attributes

Returns

StatusUpdateResult.Updated if the WorkItem is cancelled, StatusUpdateResult.NotFound if it's not found, and StatusUpdateResult.NotUpdated if it's not in a cancellable ProcessingStatus.

def complete(id: ObjectId, newStatus: ResultStatus): Future[Boolean]

Sets the ProcessingStatus of a WorkItem to a ResultStatus. It will also update the updatedAt timestamp. It will return false if the WorkItem is not InProgress.

Sets the ProcessingStatus of a WorkItem to a ResultStatus. It will also update the updatedAt timestamp. It will return false if the WorkItem is not InProgress.

Attributes

def completeAndDelete(id: ObjectId): Future[Boolean]

Deletes the WorkItem. It will return false if the WorkItem is not InProgress.

Deletes the WorkItem. It will return false if the WorkItem is not InProgress.

Attributes

def count(state: ProcessingStatus): Future[Long]

Returns the number of WorkItems in the specified ProcessingStatus

Returns the number of WorkItems in the specified ProcessingStatus

Attributes

def findById(id: ObjectId): Future[Option[WorkItem[T]]]
def markAs(id: ObjectId, status: ProcessingStatus, availableAt: Option[Instant]): Future[Boolean]

Sets the ProcessingStatus of a WorkItem. It will also update the updatedAt timestamp.

Sets the ProcessingStatus of a WorkItem. It will also update the updatedAt timestamp.

Attributes

def metricPrefix: String
override def metrics(implicit ec: ExecutionContext): Future[Map[String, Int]]

Attributes

Definition Classes
MetricSource
def pullOutstanding(failedBefore: Instant, availableBefore: Instant): Future[Option[WorkItem[T]]]

Returns a WorkItem to be processed, if available. The item will be atomically set to ProcessingStatus.InProgress, so it will not be picked up by other calls to pullOutstanding until it's status has been explicitly marked as Failed or ToDo, or it's progress status has timed out (set by inProgressRetryAfter).

Returns a WorkItem to be processed, if available. The item will be atomically set to ProcessingStatus.InProgress, so it will not be picked up by other calls to pullOutstanding until it's status has been explicitly marked as Failed or ToDo, or it's progress status has timed out (set by inProgressRetryAfter).

A WorkItem will be considered for processing in the following order:

  1. Has ToDo status, and the availableAt field is before the availableBefore param.
  2. Has Failed status, and it was marked as Failed before the failedBefore param.
  3. Has InProgress status, and was marked as InProgress before the inProgressRetryAfter configuration. Basically a timeout to ensure WorkItems that don't advance from InProgress do not get stuck.

Value parameters

availableBefore

it will only consider WorkItems where the availableAt field is before the availableBefore

failedBefore

it will only consider WorkItems in FailedState if they were marked as Failed before the failedBefore. This can avoid retrying a failure immediately.

Attributes

def pushNew(item: T, availableAt: Instant, initialState: T => ProcessingStatus): Future[WorkItem[T]]

Creates a new WorkItem.

Creates a new WorkItem.

Value parameters

availableAt

when to defer processing until

initialState

defines the initial state of the WorkItem for the item

item

the item to store in the WorkItem

Attributes

def pushNewBatch(items: Seq[T], availableAt: Instant, initialState: T => ProcessingStatus): Future[Seq[WorkItem[T]]]

Creates a batch of new WorkItems.

Creates a batch of new WorkItems.

Value parameters

availableAt

when to defer processing until

initialState

defines the initial state of the WorkItems for the item

items

the items to store as WorkItems

Attributes

Inherited methods

def ensureIndexes(): Future[Seq[String]]

Attributes

Inherited from:
PlayMongoRepository
def ensureSchema(): Future[Unit]

Attributes

Inherited from:
PlayMongoRepository

Concrete fields

Inherited fields

lazy val collection: MongoCollection[WorkItem[T]]

Attributes

Inherited from:
PlayMongoRepository
final val domainFormat: Format[WorkItem[T]]

Attributes

Inherited from:
PlayMongoRepository
final val indexes: Seq[IndexModel]

Attributes

Inherited from:
PlayMongoRepository
lazy val initialised: Future[Unit]

Attributes

Inherited from:
PlayMongoRepository
final val optSchema: Option[BsonDocument]

Attributes

Inherited from:
PlayMongoRepository