Skip to content 

IAgentScheduler Interface

Packages > @fluidframework/runtime-definitions > IAgentScheduler

Agent scheduler distributes a set of tasks/variables across connected clients.

Signature:

export interface IAgentScheduler extends IProvideAgentScheduler 

Extends: IProvideAgentScheduler

Methods

List of methods of this class
Method Description
on(event, listener) Event when ownership of task changes
pick(taskId, worker) Attempts to pick a set of tasks. A client will only run the task if it's chosen based on consensus. Resolves when the tasks are assigned to one of the connected clients.This method should only be called once per task. Duplicate calls will be rejected.
pickedTasks() Returns a list of all tasks running on this client
register(taskUrls) Registers a set of new tasks to distribute amongst connected clients. Only use this if a client wants a new agent to run but does not have the capability to run the agent inside the host. Client can call pick() later if the capability changes.This method should only be called once per task. Duplicate calls will be rejected.
release(taskUrls) Releases a set of tasks for other clients to grab. Resolves when the tasks are released.Only previously picked tasks are allowed. Releasing non picked tasks will get a rejection. App can call pickedTasks() to get the picked list first.

Methods

on

Event when ownership of task changes

Signature:

on(event: "picked" | "released" | "lost", listener: (taskId: string) => void): this;

Parameters

List of parameters
Parameter Type Description
event "picked" | "released" | "lost" name of the event: "picked" - the task has been assigned to this client, in response to pick() being called If client loses this task (due to disconnect), it will attempt to pick it again (on connection) automatically, unless release() is called "released" - the task was successfully released back to the pool. Client will not attempt to re-acquire the task, unless pick() is called. "lost" - task is lost due to disconnect or data store / container being attached. Task will be picked up again by some connected client (this client will try as well, unless release() is called)
listener (taskId: string) => void callback notified when change happened for particular key

Returns:

this

pick

Attempts to pick a set of tasks. A client will only run the task if it’s chosen based on consensus. Resolves when the tasks are assigned to one of the connected clients.

This method should only be called once per task. Duplicate calls will be rejected.

Signature:

pick(taskId: string, worker: () => Promise<void>): Promise<void>;

Parameters

List of parameters
Parameter Type Description
taskId string
worker () => Promise callback to run when task is picked up.

Returns:

Promise<void>

pickedTasks

Returns a list of all tasks running on this client

Signature:

pickedTasks(): string[];

Returns:

string[]

register

Registers a set of new tasks to distribute amongst connected clients. Only use this if a client wants a new agent to run but does not have the capability to run the agent inside the host. Client can call pick() later if the capability changes.

This method should only be called once per task. Duplicate calls will be rejected.

Signature:

register(...taskUrls: string[]): Promise<void>;

Parameters

List of parameters
Parameter Type Description
taskUrls string[]

Returns:

Promise<void>

release

Releases a set of tasks for other clients to grab. Resolves when the tasks are released.

Only previously picked tasks are allowed. Releasing non picked tasks will get a rejection. App can call pickedTasks() to get the picked list first.

Signature:

release(...taskUrls: string[]): Promise<void>;

Parameters

List of parameters
Parameter Type Description
taskUrls string[]

Returns:

Promise<void>