MCP Commands - Task Management

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Internet and Network > MCP. - MCP (Model-Context Protocol) server operations > Task Management - Execute code and scripts >

MCP Commands - Task Management

WaitForJobResult - Wait for Job Completion

PreviousTopNext


MiniRobot Language (MRL) - MCP Task Management Commands

 

MCP.WaitForJobResult

Block Until Job Completes

 

Purpose

 

The MCP.WaitForJobResult command blocks robot execution until a background job completes or fails. Unlike CheckJobResult which returns immediately, this command waits for the job to finish, making it ideal when you need to ensure a job is done before continuing.

 

This command is particularly useful when:

• You need to wait for a background job to complete

• Simplifying code by avoiding polling loops

• Ensuring job completion before subsequent steps

• Implementing simple sequential async workflows

 

Syntax

 

MCP.WaitForJobResult|$$JOB_ID|$$RETURN_VAR

 

MCP.WaitForJobResult|$$JOB_ID|$$RETURN_VAR|$$TIMEOUT

 

Parameters

 

$$JOB_ID - The unique job ID returned by RunCodeAsync or RunScriptAsync.

 

$$RETURN_VAR - The variable that will receive the job result or error message.

 

$$TIMEOUT - (Optional) Maximum time to wait in milliseconds. If not specified, waits indefinitely.

 

Return Value

 

The command returns the job result when the job completes successfully. If the job fails, it returns the error message. If a timeout is specified and reached before completion, it returns a timeout error.

 

Examples

 

' Example 1: Simple wait for completion

MCP.RunCodeAsync|import time; time.sleep(3)|python|$$JobId

PRT.Waiting for job to complete...

MCP.WaitForJobResult|$$JobId|$$Result

PRT.Job completed with result: $$Result

 

' Example 2: Wait with timeout

MCP.RunScriptAsync|C:\Scripts\data_processing.py|$$ProcessJob

' Wait up to 30 seconds (30000 ms)

MCP.WaitForJobResult|$$ProcessJob|$$ProcessResult|30000

PRT.Processing result: $$ProcessResult

 

' Example 3: Multiple sequential async jobs

' Start first job

MCP.RunCodeAsync|process_part_1()|python|$$Job1

' Start second job

MCP.RunCodeAsync|process_part_2()|python|$$Job2

' Wait for both to complete

MCP.WaitForJobResult|$$Job1|$$Result1

MCP.WaitForJobResult|$$Job2|$$Result2

PRT.Both jobs completed

 

Remarks

 

This is a blocking command - robot execution stops until the job completes or the timeout is reached. This makes it simpler to use than CheckJobResult with polling loops, but it freezes the robot during the wait.

 

If the job is already completed when WaitForJobResult is called, it returns immediately with the result. If the job does not exist (was never created or was cleaned up), it returns an error.

 

Always use a timeout for jobs that might hang or run indefinitely to prevent the robot from being stuck forever.

 

Error Conditions

 

The command will fail with an error if:

• The job ID parameter is missing

• The return variable parameter is missing

• The job ID does not exist

• The timeout is reached before job completion

 

See also:

 

MCP.CheckJobResult - Check Job Result

MCP.GetJobResult - Get Job Result

MCP.RunCodeAsync - Execute Code Asynchronously