API Jobs - Krystian-L-Lis/Stage GitHub Wiki
#API #Jobs
Type: Interface
Extends: I_Debug
Description:
Represents an object responsible for scheduling and managing the execution of jobs.
Type: Method
Description:
Defers the job by moving it to the end of the queue.
Returns:
-
Ok
– Success -
Err.Itf0
–iJob = 0
-
Err.NoMatch
–iJob.Worker <> THIS^
Signature:
METHOD Defer : Result
VAR_INPUT
iJob : I_Job;
END_VAR
Type: Method
Description:
Removes the job from the queue and resets it.
Returns:
-
Ok
– Success -
Err.Itf0
–iJob = 0
-
Err.NoMatch
–iJob.Worker <> THIS^
-
Err.IncArg
–iJob.State = TaskState.Idle
Signature:
METHOD Dequeue : Result
VAR_INPUT
iJob : I_Job;
END_VAR
Type: Method
Description:
Adds a job to the queue.
Returns:
-
Ok
– Success -
Err.Itf0
–iJob = 0
-
Err.NoMatch
–iJob.Worker <> THIS^
-
Err.IncArg
–iJob.State <> TaskState.Idle
Signature:
METHOD Enqueue : Result
VAR_INPUT
iJob : I_Job;
END_VAR
Type: Property
Accessors: Get
Description:
Returns the first job in the queue.
Signature: PROPERTY First : I_Job
Type: Function Block
Implements: I_Worker
Description:
Manages adding, removing, deferring, and running I_Job
instances. This function block is not intended for standalone use. It must be wrapped by a higher-level controller or scheduler that manages when jobs are enqueued, dequeued, deferred, or executed. See: LoopWorker
, BlockingWorker
.
Type: Property
Accessors: Get
Description: Returns the first job currently in the queue.
Signature: PROPERTY First : I_Job
Type: Method
Description:
Moves the given job to the end of the queue.
Returns:
-
Ok
– Success -
Err.Itf0
–iJob
is null -
Err.NoMatch
–iJob.Worker
does not matchTHIS^
Signature:
METHOD Defer : Result
VAR_INPUT
iJob : I_Job;
END_VAR
Type: Method
Description:
Removes a job from the queue and finalizes it depending on its state.
Returns:
-
Ok
– Success -
Err.Itf0
–iJob
is null -
Err.NoMatch
–iJob.Worker
does not matchTHIS^
-
Err.IncArg
–iJob.State = JobState.Idle
Signature:
METHOD Dequeue : Result
VAR_INPUT
iJob : I_Job;
END_VAR
Type: Method
Description:
Adds a job to the end of the queue.
Returns:
-
Ok
– Success -
Err.Itf0
–iJob
is null -
Err.NoMatch
–iJob.Worker
does not matchTHIS^
-
Err.IncArg
–iJob.State <> JobState.Idle
Signature:
METHOD Enqueue : Result
VAR_INPUT
iJob : I_Job;
END_VAR
Type: Method
Description:
Executes the Run
method of a job if it is in the Ready
state.
Returns:
-
Ok
– Success -
Err.Itf0
–iJob
is null -
Err.IncArg
– Invalid job state for execution (Error
,Idle
,Running
)
Signature:
METHOD Run : Result
VAR_INPUT
iJob : I_Job;
END_VAR
Type: Function Block
Description:
A wrapper worker that runs a single Job
per call and defers it, ensuring all enqueued jobs get a chance to execute. This distributes workload across multiple PLC cycles, with execution occurring once per cycle.
Type: Property
Accessors: Get
Description:
Returns the internal scheduler instance that manages job execution.
Signature: PROPERTY Base : I_Worker
Type: Method
Description:
Executes the first job in the queue. If the job is completed or aborted, it is removed.
Otherwise, it is executed and deferred for future cycles. Invalid states trigger a debug message.
Signature: METHOD Run
Type: Function Block
Description:
A worker wrapper that runs a Job
continuously until it completes. It attempts to finish the active job before moving on, which may block execution for multiple cycles depending on job duration.
Type: Property
Accessors: Get
Description:
Returns the internal scheduler instance that manages job execution.
Signature: PROPERTY Base : I_Worker
Type: Method
Description:
Runs the first job in the queue until it completes. If the job is in a terminal state (Completed or Aborted), it is dequeued. Invalid job states trigger a debug message.
Signature: METHOD Run
Type: Enum
Description:
Represents the various states a job can be in during its lifecycle.
Signature:
{attribute 'qualified_only'}
{attribute 'strict'}
TYPE JobState :
(
Error, // Incorrect state
Idle, // Not in queue
Enqueue, // Enqueued and wating for worker response
Ready, // Ready to be processed
Running, // Currently processed by worker
Aborted, // Aborted, wating to be dequeued
Completed // Completed, wating to be dequeued
) BYTE := Idle;
END_TYPE
Type: Interface
Extends: I_Debug
Description:
Provides an interface for starting and aborting jobs. Designed for external components to interact with the job scheduler.
Type: Method
Description:
Starts the job and adds it to the worker queue.
Results:
-
Ok
upon successful start. -
Err.IncArg
if the job is not in theIdle
state. -
Err.Itf0
if the worker is not assigned (Worker = 0
).
Signature: METHOD Start : Result
Type: Method
Description:
Notifies the scheduler to abort the current job.
Results:
-
Err.IncArg
if the job is already in theIdle
state.
Signature: METHOD Abort : Result
Type: Function Block
Implements: I_Job
Description:
An abstract representation of a system job, providing the foundation for implementing job-specific behaviour. Manages its state and offers default behaviour for its lifecycle methods, allowing overriding only where necessary.
Type: Property
Accessors: Get, Set
Description:
Gets or sets the I_Worker
handling this job. Can only be set when the job is in Idle
state.
Signature: PROPERTY Worker : I_Worker
Type: Property
Accessors: Get
Description:
Returns the current state of the job.
Signature: PROPERTY State : JobState
Type: Method
From: I_Job
Description:
Starts the job and queues it with the assigned worker.
Results:
-
Ok
upon success. -
Err.IncArg
if state is notIdle
. -
Err.Itf0
if worker is not assigned.
Signature: METHOD Start : Result
Type: Method
From: I_Job
Description:
Requests abortion of the job.
Results:
-
Err.IncArg
if the job is already in theIdle
state.
Signature:METHOD Abort : Result
Type: Method
Access: Protected
Description:
Notifies that the job has completed.
Results:
-
Ok
upon success. -
Err.IncArg
if state is notRunning
.
Signature: METHOD PROTECTED Done : Result
Type: Method
Access: Protected
Description:
Executed when the job is started. Override for custom behaviour.
Signature: METHOD PROTECTED OnStart
Type: Method
Access: Protected
Description:
Executed when the job runs. Override for job-specific logic.
Signature: METHOD PROTECTED OnRun
Type: Method
Access: Protected
Description:
Executed when the job is marked as done.
Signature: METHOD PROTECTED OnDone
Type: Method
Access: Protected
Description:
Executed when the job is aborted.
Signature: METHOD PROTECTED OnAbort
Type: Method
Access: Protected
Description:
Executed when the job exits or is removed from the queue.
Signature: METHOD PROTECTED OnExit