API Jobs - Krystian-L-Lis/Stage GitHub Wiki

#API #Jobs

I_Worker

Type: Interface
Extends: I_Debug
Description:
Represents an object responsible for scheduling and managing the execution of jobs.

Members

Defer

Type: Method
Description:
Defers the job by moving it to the end of the queue.
Returns:

  • Ok – Success
  • Err.Itf0iJob = 0
  • Err.NoMatchiJob.Worker <> THIS^

Signature:

METHOD Defer : Result
VAR_INPUT
    iJob : I_Job;
END_VAR

Dequeue

Type: Method
Description:
Removes the job from the queue and resets it.
Returns:

  • Ok – Success
  • Err.Itf0iJob = 0
  • Err.NoMatchiJob.Worker <> THIS^
  • Err.IncArgiJob.State = TaskState.Idle

Signature:

METHOD Dequeue : Result
VAR_INPUT
    iJob : I_Job;
END_VAR

Enqueue

Type: Method
Description:
Adds a job to the queue.
Returns:

  • Ok – Success
  • Err.Itf0iJob = 0
  • Err.NoMatchiJob.Worker <> THIS^
  • Err.IncArgiJob.State <> TaskState.Idle

Signature:

METHOD Enqueue : Result
VAR_INPUT
    iJob : I_Job;
END_VAR

First

Type: Property
Accessors: Get
Description:
Returns the first job in the queue.
Signature: PROPERTY First : I_Job


Worker

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.

Members


First

Type: Property
Accessors: Get
Description: Returns the first job currently in the queue.
Signature: PROPERTY First : I_Job


Defer

Type: Method
Description:
Moves the given job to the end of the queue.
Returns:

  • Ok – Success
  • Err.Itf0iJob is null
  • Err.NoMatchiJob.Worker does not match THIS^

Signature:

METHOD Defer : Result
VAR_INPUT
    iJob : I_Job;
END_VAR

Dequeue

Type: Method
Description:
Removes a job from the queue and finalizes it depending on its state.
Returns:

  • Ok – Success
  • Err.Itf0iJob is null
  • Err.NoMatchiJob.Worker does not match THIS^
  • Err.IncArgiJob.State = JobState.Idle

Signature:

METHOD Dequeue : Result
VAR_INPUT
    iJob : I_Job;
END_VAR

Enqueue

Type: Method
Description:
Adds a job to the end of the queue.
Returns:

  • Ok – Success
  • Err.Itf0iJob is null
  • Err.NoMatchiJob.Worker does not match THIS^
  • Err.IncArgiJob.State <> JobState.Idle

Signature:

METHOD Enqueue : Result
VAR_INPUT
    iJob : I_Job;
END_VAR

Run

Type: Method
Description:
Executes the Run method of a job if it is in the Ready state.
Returns:

  • Ok – Success
  • Err.Itf0iJob is null
  • Err.IncArg – Invalid job state for execution (Error, Idle, Running)

Signature:

METHOD Run : Result
VAR_INPUT
    iJob : I_Job;
END_VAR

LoopWorker

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.

Members

Base

Type: Property
Accessors: Get
Description:
Returns the internal scheduler instance that manages job execution.
Signature: PROPERTY Base : I_Worker


Run

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


BlockingWorker

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.

Members

Base

Type: Property
Accessors: Get
Description:
Returns the internal scheduler instance that manages job execution.
Signature: PROPERTY Base : I_Worker


Run

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


JobState

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


I_Job

Type: Interface
Extends: I_Debug
Description:
Provides an interface for starting and aborting jobs. Designed for external components to interact with the job scheduler.


Members

Start

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 the Idle state.
  • Err.Itf0 if the worker is not assigned (Worker = 0).

Signature: METHOD Start : Result


Abort

Type: Method
Description:
Notifies the scheduler to abort the current job.
Results:

  • Err.IncArg if the job is already in the Idle state.

Signature: METHOD Abort : Result


Job

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.

Members

Worker

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


State

Type: Property
Accessors: Get
Description:
Returns the current state of the job.

Signature: PROPERTY State : JobState


Start

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 not Idle.
  • Err.Itf0 if worker is not assigned.

Signature: METHOD Start : Result


Abort

Type: Method
From: I_Job
Description:
Requests abortion of the job.
Results:

  • Err.IncArg if the job is already in the Idle state.
    Signature: METHOD Abort : Result

Done

Type: Method
Access: Protected
Description:
Notifies that the job has completed.
Results:

  • Ok upon success.
  • Err.IncArg if state is not Running.

Signature: METHOD PROTECTED Done : Result


OnStart

Type: Method
Access: Protected
Description:
Executed when the job is started. Override for custom behaviour.
Signature: METHOD PROTECTED OnStart


OnRun

Type: Method
Access: Protected
Description:
Executed when the job runs. Override for job-specific logic.
Signature: METHOD PROTECTED OnRun


OnDone

Type: Method
Access: Protected
Description:
Executed when the job is marked as done.
Signature: METHOD PROTECTED OnDone


OnAbort

Type: Method
Access: Protected
Description:
Executed when the job is aborted.
Signature: METHOD PROTECTED OnAbort


OnExit

Type: Method
Access: Protected
Description:
Executed when the job exits or is removed from the queue.
Signature: METHOD PROTECTED OnExit


⚠️ **GitHub.com Fallback** ⚠️