Documentation

Progress extends AbstractBaseApi
in package

Progress Class

Represents an asynchronous operation progress tracker in Canvas LMS. This class provides methods to track the status of long-running operations like content migrations, bulk updates, and file uploads.

Usage:

// Finding a progress by ID
$progress = Progress::find(123);

// Checking progress status
if ($progress->isCompleted()) {
    $results = $progress->results;
    echo "Operation completed successfully";
} elseif ($progress->isFailed()) {
    echo "Operation failed: " . $progress->message;
} else {
    echo "Progress: " . $progress->completion . "%";
}

// Polling until completion
$progress = Progress::find(123);
$completedProgress = $progress->waitForCompletion(300, 2); // 5 minutes max, 2 second intervals

// Cancelling an operation
$progress->cancel("User requested cancellation");

// LTI context progress
$progress = Progress::findInLtiContext(456, 123); // course_id, progress_id

// Static polling utility
$progress = Progress::pollUntilComplete(123, 300, 2);

Table of Contents

Constants

STATE_COMPLETED  = 'completed'
STATE_FAILED  = 'failed'
STATE_QUEUED  = 'queued'
Workflow state constants
STATE_RUNNING  = 'running'

Properties

$completion  : int|null
Percentage completed (0-100)
$contextId  : int|null
The ID of the object the job is associated with
$contextType  : string|null
The type of object (e.g., "Account", "Course", "User")
$createdAt  : DateTime|null
When the job was created
$id  : int|null
The unique identifier for the progress object
$message  : string|null
Optional descriptive message about current status
$results  : mixed
Optional results data when job completes
$tag  : string|null
Identifies the type of operation being performed
$updatedAt  : DateTime|null
When the progress was last updated
$url  : string|null
Endpoint URL for retrieving progress updates
$userId  : int|null
The ID of the user who initiated the job
$workflowState  : string|null
Current status of the job (queued, running, completed, failed)
$apiClient  : HttpClientInterface
$methodAliases  : array<string|int, mixed>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
Progress constructor.
all()  : array<string|int, static>
Get all pages of results
cancel()  : Progress
Cancel a running operation
find()  : Progress
Find a progress object by ID
findInLtiContext()  : Progress
Find a progress object in LTI context
get()  : array<string|int, Progress>
Required by ApiInterface - fetch all progress objects (not typically used)
getCompletion()  : int|null
Get the completion percentage
getCompletionPercentage()  : float
Get the completion percentage as a float (0.0 to 100.0)
getContextId()  : int|null
Get the context ID
getContextType()  : string|null
Get the context type
getCreatedAt()  : DateTime|null
Get the creation date
getId()  : int|null
Get the unique identifier
getMessage()  : string|null
Get the status message
getResults()  : mixed
Get the operation results
getStatusDescription()  : string
Get a human-readable status description
getTag()  : string|null
Get the operation tag
getUpdatedAt()  : DateTime|null
Get the last update date
getUrl()  : string|null
Get the progress URL
getUserId()  : int|null
Get the user ID
getWorkflowState()  : string|null
Get the workflow state
isCompleted()  : bool
Check if the progress is completed
isFailed()  : bool
Check if the progress has failed
isFinished()  : bool
Check if the operation is finished (completed or failed)
isInProgress()  : bool
Check if the operation is currently in progress (queued or running)
isQueued()  : bool
Check if the progress is in queued state
isRunning()  : bool
Check if the progress is in running state
isSuccessful()  : bool
Check if the operation completed successfully
paginate()  : PaginationResult
Get paginated results with metadata
pollUntilComplete()  : Progress
Static utility to poll a progress until completion
refresh()  : Progress
Refresh the progress object with latest data from API
setApiClient()  : void
Set the API client
setCompletion()  : void
Set the completion percentage
setContextId()  : void
Set the context ID
setContextType()  : void
Set the context type
setCreatedAt()  : void
Set the creation date
setId()  : void
Set the unique identifier
setMessage()  : void
Set the status message
setResults()  : void
Set the operation results
setTag()  : void
Set the operation tag
setUpdatedAt()  : void
Set the last update date
setUrl()  : void
Set the progress URL
setUserId()  : void
Set the user ID
setWorkflowState()  : void
Set the workflow state
waitForCompletion()  : Progress
Wait for operation to complete with configurable polling
castValue()  : DateTime|mixed
Cast a value to the correct type
checkApiClient()  : void
Check if the API client is set, if not, instantiate a new one
convertPaginatedResponseToModels()  : array<string|int, static>
Helper method to convert paginated response data to model instances
createConfiguredHttpClient()  : HttpClient
Create an HttpClient with configured middleware
createPaginationResult()  : PaginationResult
Helper method to create PaginationResult from paginated response
getEndpoint()  : string
Get the API endpoint for this resource
getPaginatedResponse()  : PaginatedResponse
Helper method to get paginated response from API endpoint
populate()  : void
Populate the object with new data
toDtoArray()  : array<string|int, mixed>
Convert the object to an array

Constants

STATE_COMPLETED

public mixed STATE_COMPLETED = 'completed'

STATE_FAILED

public mixed STATE_FAILED = 'failed'

STATE_QUEUED

Workflow state constants

public mixed STATE_QUEUED = 'queued'

STATE_RUNNING

public mixed STATE_RUNNING = 'running'

Properties

$completion

Percentage completed (0-100)

public int|null $completion = null

$contextId

The ID of the object the job is associated with

public int|null $contextId = null

$contextType

The type of object (e.g., "Account", "Course", "User")

public string|null $contextType = null

$createdAt

When the job was created

public DateTime|null $createdAt = null

$id

The unique identifier for the progress object

public int|null $id = null

$message

Optional descriptive message about current status

public string|null $message = null

$results

Optional results data when job completes

public mixed $results = null

$tag

Identifies the type of operation being performed

public string|null $tag = null

$updatedAt

When the progress was last updated

public DateTime|null $updatedAt = null

$url

Endpoint URL for retrieving progress updates

public string|null $url = null

$userId

The ID of the user who initiated the job

public int|null $userId = null

$workflowState

Current status of the job (queued, running, completed, failed)

public string|null $workflowState = null

$methodAliases

Define method aliases

protected static array<string|int, mixed> $methodAliases = ['get' => ['fetch', 'list', 'fetchAll'], 'all' => ['fetchAllPages', 'getAll'], 'paginate' => ['getPaginated', 'withPagination', 'fetchPage'], 'find' => ['one', 'getOne']]

Methods

__callStatic()

Magic method to handle function aliases

public static __callStatic(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
$name : string
$arguments : array<string|int, mixed>
Tags
throws
InvalidArgumentException

__construct()

Progress constructor.

public __construct([array<string|int, mixed> $data = [] ]) : mixed
Parameters
$data : array<string|int, mixed> = []

all()

Get all pages of results

public static all([array<string, mixed> $params = [] ]) : array<string|int, static>
Parameters
$params : array<string, mixed> = []

Query parameters

Return values
array<string|int, static>

cancel()

Cancel a running operation

public cancel([string|null $message = null ]) : Progress
Parameters
$message : string|null = null

Optional message to distinguish the cancellation reason

Tags
throws
CanvasApiException
Return values
Progress

Updated progress object

find()

Find a progress object by ID

public static find(int $id[, array<string|int, mixed> $params = [] ]) : Progress
Parameters
$id : int

Progress ID

$params : array<string|int, mixed> = []

Optional query parameters

Tags
throws
CanvasApiException
Return values
Progress

findInLtiContext()

Find a progress object in LTI context

public static findInLtiContext(int $courseId, int $id) : Progress
Parameters
$courseId : int

Course ID for LTI context

$id : int

Progress ID

Tags
throws
CanvasApiException
Return values
Progress

get()

Required by ApiInterface - fetch all progress objects (not typically used)

public static get([array<string|int, mixed> $params = [] ]) : array<string|int, Progress>
Parameters
$params : array<string|int, mixed> = []
Tags
throws
CanvasApiException
Return values
array<string|int, Progress>

getCompletion()

Get the completion percentage

public getCompletion() : int|null
Return values
int|null

getCompletionPercentage()

Get the completion percentage as a float (0.0 to 100.0)

public getCompletionPercentage() : float
Return values
float

getContextId()

Get the context ID

public getContextId() : int|null
Return values
int|null

getContextType()

Get the context type

public getContextType() : string|null
Return values
string|null

getCreatedAt()

Get the creation date

public getCreatedAt() : DateTime|null
Return values
DateTime|null

getId()

Get the unique identifier

public getId() : int|null
Return values
int|null

getMessage()

Get the status message

public getMessage() : string|null
Return values
string|null

getResults()

Get the operation results

public getResults() : mixed

getStatusDescription()

Get a human-readable status description

public getStatusDescription() : string
Return values
string

getTag()

Get the operation tag

public getTag() : string|null
Return values
string|null

getUpdatedAt()

Get the last update date

public getUpdatedAt() : DateTime|null
Return values
DateTime|null

getUrl()

Get the progress URL

public getUrl() : string|null
Return values
string|null

getUserId()

Get the user ID

public getUserId() : int|null
Return values
int|null

getWorkflowState()

Get the workflow state

public getWorkflowState() : string|null
Return values
string|null

isCompleted()

Check if the progress is completed

public isCompleted() : bool
Return values
bool

isFailed()

Check if the progress has failed

public isFailed() : bool
Return values
bool

isFinished()

Check if the operation is finished (completed or failed)

public isFinished() : bool
Return values
bool

isInProgress()

Check if the operation is currently in progress (queued or running)

public isInProgress() : bool
Return values
bool

isQueued()

Check if the progress is in queued state

public isQueued() : bool
Return values
bool

isRunning()

Check if the progress is in running state

public isRunning() : bool
Return values
bool

isSuccessful()

Check if the operation completed successfully

public isSuccessful() : bool
Return values
bool

pollUntilComplete()

Static utility to poll a progress until completion

public static pollUntilComplete(int $id[, int $maxWaitSeconds = 300 ][, int $intervalSeconds = 2 ]) : Progress
Parameters
$id : int

Progress ID to poll

$maxWaitSeconds : int = 300

Maximum time to wait in seconds (default: 300)

$intervalSeconds : int = 2

Initial polling interval in seconds (default: 2)

Tags
throws
CanvasApiException
Return values
Progress

The completed progress object

setCompletion()

Set the completion percentage

public setCompletion(int|null $completion) : void
Parameters
$completion : int|null

setContextId()

Set the context ID

public setContextId(int|null $contextId) : void
Parameters
$contextId : int|null

setContextType()

Set the context type

public setContextType(string|null $contextType) : void
Parameters
$contextType : string|null

setCreatedAt()

Set the creation date

public setCreatedAt(DateTime|null $createdAt) : void
Parameters
$createdAt : DateTime|null

setId()

Set the unique identifier

public setId(int|null $id) : void
Parameters
$id : int|null

setMessage()

Set the status message

public setMessage(string|null $message) : void
Parameters
$message : string|null

setResults()

Set the operation results

public setResults(mixed $results) : void
Parameters
$results : mixed

setTag()

Set the operation tag

public setTag(string|null $tag) : void
Parameters
$tag : string|null

setUpdatedAt()

Set the last update date

public setUpdatedAt(DateTime|null $updatedAt) : void
Parameters
$updatedAt : DateTime|null

setUrl()

Set the progress URL

public setUrl(string|null $url) : void
Parameters
$url : string|null

setUserId()

Set the user ID

public setUserId(int|null $userId) : void
Parameters
$userId : int|null

setWorkflowState()

Set the workflow state

public setWorkflowState(string|null $workflowState) : void
Parameters
$workflowState : string|null

waitForCompletion()

Wait for operation to complete with configurable polling

public waitForCompletion([int $maxWaitSeconds = 300 ][, int $intervalSeconds = 2 ]) : Progress
Parameters
$maxWaitSeconds : int = 300

Maximum time to wait in seconds (default: 300 = 5 minutes)

$intervalSeconds : int = 2

Initial polling interval in seconds (default: 2)

Tags
throws
CanvasApiException

If operation times out or fails

Return values
Progress

The completed progress object

castValue()

Cast a value to the correct type

protected castValue(string $key, mixed $value) : DateTime|mixed
Parameters
$key : string
$value : mixed
Tags
throws
Exception
Return values
DateTime|mixed

checkApiClient()

Check if the API client is set, if not, instantiate a new one

protected static checkApiClient() : void

convertPaginatedResponseToModels()

Helper method to convert paginated response data to model instances

protected static convertPaginatedResponseToModels(PaginatedResponse $paginatedResponse) : array<string|int, static>
Parameters
$paginatedResponse : PaginatedResponse
Return values
array<string|int, static>

getEndpoint()

Get the API endpoint for this resource

protected static getEndpoint() : string
Return values
string

getPaginatedResponse()

Helper method to get paginated response from API endpoint

protected static getPaginatedResponse(string $endpoint[, array<string|int, mixed> $params = [] ]) : PaginatedResponse
Parameters
$endpoint : string

The API endpoint path

$params : array<string|int, mixed> = []

Query parameters for the request

Return values
PaginatedResponse

populate()

Populate the object with new data

protected populate(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>
Tags
throws
Exception

toDtoArray()

Convert the object to an array

protected toDtoArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results