Lux.Company.Objectives (Lux v0.5.0)

View Source

Context module for managing objectives within a company.

This module provides functions for:

  • Creating and managing objectives
  • Assigning agents to objectives
  • Tracking objective progress and status
  • Managing objective lifecycle (start, complete, fail)

Summary

Functions

Returns true if the objective is active (in progress).

Assigns an agent to the objective.

Returns true if the objective can be started.

Completes the objective if it's in progress.

Returns true if the objective is completed.

Creates a new objective with the given attributes.

Returns the duration of the objective if it has started. Returns nil if the objective hasn't started.

Marks the objective as failed with an optional reason.

Returns true if the objective has failed.

Starts the objective if it's in pending status and has assigned agents.

Updates the progress of an objective. Progress should be an integer between 0 and 100.

Functions

active?(objective)

Returns true if the objective is active (in progress).

assign_agent(objective, agent_id)

Assigns an agent to the objective.

Returns an error if the agent is already assigned.

Examples

iex> Objectives.assign_agent(objective, "agent-123")
{:ok, %Objective{}}

iex> Objectives.assign_agent(objective, "already-assigned")
{:error, :already_assigned}

can_start?(objective)

Returns true if the objective can be started.

complete(objective)

Completes the objective if it's in progress.

Examples

iex> Objectives.complete(in_progress_objective)
{:ok, %Objective{status: :completed}}

iex> Objectives.complete(pending_objective)
{:error, :invalid_status}

completed?(objective)

Returns true if the objective is completed.

create(attrs)

Creates a new objective with the given attributes.

Required Attributes

  • :name - The name of the objective (atom)
  • :description - A description of what needs to be achieved

Optional Attributes

  • :id - A unique identifier (generated if not provided)
  • :success_criteria - Criteria for determining success
  • :steps - List of steps to achieve the objective
  • :metadata - Additional metadata as a map

Examples

iex> Objectives.create(%{
...>   name: :create_blog_post,
...>   description: "Create a well-researched blog post",
...>   success_criteria: "Published post with >1000 views",
...>   steps: ["Research", "Write", "Edit", "Publish"]
...> })
{:ok, %Objective{}}

iex> Objectives.create(%{name: :invalid})
{:error, :invalid_attributes}

duration(objective)

Returns the duration of the objective if it has started. Returns nil if the objective hasn't started.

Examples

iex> Objectives.duration(started_objective)
3600  # seconds

iex> Objectives.duration(pending_objective)
nil

fail(objective, reason \\ nil)

Marks the objective as failed with an optional reason.

Examples

iex> Objectives.fail(objective, "Resource unavailable")
{:ok, %Objective{status: :failed}}

iex> Objectives.fail(completed_objective)
{:error, :invalid_status}

failed?(objective)

Returns true if the objective has failed.

start(objective)

Starts the objective if it's in pending status and has assigned agents.

Examples

iex> Objectives.start(objective_with_agents)
{:ok, %Objective{status: :in_progress}}

iex> Objectives.start(objective_without_agents)
{:error, :no_agents_assigned}

iex> Objectives.start(already_started_objective)
{:error, :invalid_status}

update_progress(objective, progress)

Updates the progress of an objective. Progress should be an integer between 0 and 100.

Examples

iex> Objectives.update_progress(objective, 50)
{:ok, %Objective{progress: 50}}

iex> Objectives.update_progress(objective, 101)
{:error, :invalid_progress}