Anvil.Queue.Policy behaviour (Anvil v0.1.1)

View Source

Behaviour for queue assignment policies.

Policies control how samples are assigned to labelers.

Summary

Functions

Initializes policy state based on the policy type.

Returns the next sample for a labeler based on the policy.

Updates the policy state after an assignment.

Types

policy_state()

@type policy_state() :: map()

sample()

@type sample() :: map()

Callbacks

init(config)

@callback init(config :: map()) :: {:ok, policy_state()}

next_assignment(policy_state, labeler_id, available_samples)

@callback next_assignment(
  policy_state(),
  labeler_id :: String.t(),
  available_samples :: [sample()]
) :: {:ok, sample()} | {:error, atom()}

update_state(policy_state, sample)

@callback update_state(policy_state(), sample()) :: policy_state()

Functions

init_policy(module, config)

@spec init_policy(atom() | module(), map()) :: {:ok, map()}

Initializes policy state based on the policy type.

Dispatches to the appropriate policy module.

next_sample(module, state, labeler_id, available_samples)

@spec next_sample(atom() | module(), map(), String.t(), [map()]) ::
  {:ok, map()} | {:error, atom()}

Returns the next sample for a labeler based on the policy.

Dispatches to the appropriate policy module.

update_state(module, state, sample)

@spec update_state(atom() | module(), map(), map()) :: map()

Updates the policy state after an assignment.