Anvil.Assignment (Anvil v0.1.1)

View Source

Represents a labeling task assigned to a specific labeler.

Tracks the lifecycle of an assignment from creation through completion, expiration, or skipping.

Summary

Functions

Completes an assignment with a label ID.

Expires an assignment that has passed its deadline.

Returns the labeling time in seconds, or nil if not completed.

Creates a new pending assignment.

Checks if the assignment is past its deadline.

Skips an assignment with an optional reason.

Starts an assignment, transitioning from :pending to :in_progress.

Types

status()

@type status() :: :pending | :in_progress | :completed | :expired | :skipped

t()

@type t() :: %Anvil.Assignment{
  attempts: non_neg_integer(),
  completed_at: DateTime.t() | nil,
  created_at: DateTime.t(),
  deadline: DateTime.t() | nil,
  expired_at: DateTime.t() | nil,
  id: String.t(),
  label_id: String.t() | nil,
  labeler_id: String.t(),
  queue_id: String.t(),
  sample_id: String.t(),
  skip_reason: String.t() | nil,
  skipped_at: DateTime.t() | nil,
  started_at: DateTime.t() | nil,
  status: status()
}

Functions

complete(assignment, label_id)

@spec complete(t(), String.t()) :: {:ok, t()} | {:error, term()}

Completes an assignment with a label ID.

expire(assignment)

@spec expire(t()) :: {:ok, t()} | {:error, term()}

Expires an assignment that has passed its deadline.

labeling_time_seconds(assignment)

@spec labeling_time_seconds(t()) :: non_neg_integer() | nil

Returns the labeling time in seconds, or nil if not completed.

new(opts)

@spec new(keyword()) :: t()

Creates a new pending assignment.

past_deadline?(assignment)

@spec past_deadline?(t()) :: boolean()

Checks if the assignment is past its deadline.

skip(assignment, reason \\ nil)

@spec skip(t(), String.t() | nil) :: {:ok, t()} | {:error, term()}

Skips an assignment with an optional reason.

start(assignment, timeout_seconds)

@spec start(t(), pos_integer()) :: {:ok, t()} | {:error, term()}

Starts an assignment, transitioning from :pending to :in_progress.