Skip to content

Project

The Project class represents a project in WhatsNext and provides methods for managing jobs.

Usage

from whatsnext.api.client import Server

server = Server("http://localhost:8000")
project = server.get_project("my-project")

# Queue jobs
project.append(name="job-1", parameters={"key": "value"})

# Get next job from queue
job = project.pop()

# List all jobs
jobs = project.jobs

API Reference

Project

Represents a project that contains tasks and jobs.

A Project is a container for organizing related work. It holds tasks (templates) and jobs (instances of tasks to execute).

created_at property

created_at: datetime

Get the creation timestamp from the server.

description property

description: str

Get the project description from the server.

last_updated property

last_updated: datetime

Get the last update timestamp from the server.

name property

name: str

Get the project name from the server.

queue property

queue: List[Dict[str, Any]]

Get all jobs in the queue from the server.

status property

status: str

Get the project status from the server.

append_queue

append_queue(job: Job) -> bool

Add a job to the project's queue.

clear_queue

clear_queue() -> int

Clear all pending jobs from the queue.

RETURNS DESCRIPTION
int

Number of jobs deleted.

create_task

create_task(task_name: str) -> bool

Create a new task in this project.

extend_queue

extend_queue(jobs: List[Job]) -> List[int]

Add multiple jobs to the queue.

PARAMETER DESCRIPTION
jobs

List of Job objects to add.

TYPE: List[Job]

RETURNS DESCRIPTION
List[int]

List of created job IDs.

fetch_job

fetch_job(
    available_cpu: int = 0, available_accelerators: int = 0
) -> Job

Fetch the next pending job from the queue.

PARAMETER DESCRIPTION
available_cpu

Filter jobs by available CPU (0 = no filter).

TYPE: int DEFAULT: 0

available_accelerators

Filter jobs by available accelerators (0 = no filter).

TYPE: int DEFAULT: 0

RETURNS DESCRIPTION
Job

The next job to execute.

RAISES DESCRIPTION
EmptyQueueError

If no jobs are pending.

pop_queue

pop_queue(idx: int = 0) -> bool

Remove a job from the queue by index.

PARAMETER DESCRIPTION
idx

Index of the job to remove (0-based, by creation order).

TYPE: int DEFAULT: 0

RETURNS DESCRIPTION
bool

True if the job was removed, False otherwise.

remove_job

remove_job(job_id: int) -> bool

Remove a specific job from the queue.

PARAMETER DESCRIPTION
job_id

The ID of the job to remove.

TYPE: int

RETURNS DESCRIPTION
bool

True if the job was removed, False otherwise.

set_description

set_description(description: str) -> None

Update the project description on the server.