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

CleanupJobs - Clean Up Completed Jobs

PreviousTopNext


MiniRobot Language (MRL) - MCP Task Management Commands

 

MCP.CleanupJobs

Remove Completed Jobs from Memory

 

Purpose

 

The MCP.CleanupJobs command removes completed and failed jobs from the MCP server's job tracking system, freeing up memory and resources. This is an important maintenance operation to prevent memory leaks from accumulated job data.

 

This command is particularly useful when:

• Freeing memory from completed job data

• Cleaning up before starting new batch operations

• Implementing periodic maintenance in long-running scripts

• Preventing job ID accumulation

 

Syntax

 

MCP.CleanupJobs

 

MCP.CleanupJobs|$$JOB_ID

 

Parameters

 

$$JOB_ID - (Optional) Specific job ID to clean up. If not provided, cleans up all completed and failed jobs.

 

Return Value

 

The command returns the number of jobs cleaned up, or 0 if no jobs were eligible for cleanup. Running jobs are not affected by cleanup operations.

 

Examples

 

' Example 1: Clean up all completed jobs

MCP.CleanupJobs|$$CleanedCount

PRT.Cleaned up $$CleanedCount jobs

 

' Example 2: Clean up specific job

MCP.RunCodeAsync|process_data()|python|$$JobId

MCP.WaitForJobResult|$$JobId|$$Result

' Use the result...

PRT.Result: $$Result

' Clean up this specific job

MCP.CleanupJobs|$$JobId

PRT.Job cleaned up

 

' Example 3: Periodic cleanup in a long-running script

LBL.ProcessLoop

' ... process items ...

MCP.RunCodeAsync|process_next_item()|python|$$CurrentJob

MCP.WaitForJobResult|$$CurrentJob|$$JobResult

' Clean up immediately after use

MCP.CleanupJobs|$$CurrentJob

' Check if more items to process

IVV.$$MoreItems!0

JMP.ProcessLoop

EIF.

 

' Example 4: Cleanup with check

MCP.GetJobIdList|$$JobList

LEN.$$JobList|$$JobCount

PRT.Before cleanup: $$JobCount jobs

MCP.CleanupJobs|$$Cleaned

MCP.GetJobIdList|$$JobListAfter

LEN.$$JobListAfter|$$JobCountAfter

PRT.After cleanup: $$JobCountAfter jobs (removed $$Cleaned)

 

Remarks

 

CleanupJobs removes job data from memory, freeing resources. Once a job is cleaned up, its result can no longer be retrieved. Make sure to extract any needed data before cleanup.

 

By default, CleanupJobs only removes completed and failed jobs. Running jobs are not affected and will continue executing. If you specify a job ID, that specific job will be cleaned up regardless of its status (use with caution for running jobs).

 

Regular cleanup is recommended in scripts that create many background jobs to prevent memory accumulation. Consider cleaning up jobs immediately after retrieving their results.

 

Error Conditions

 

The command will fail with an error if:

• The specified job ID does not exist

• The specified job ID is invalid

 

See also:

 

MCP.GetJobIdList - List All Job IDs

MCP.CheckJobResult - Check Job Result

MCP.GetJobResult - Get Job Result

MCP.RunCodeAsync - Execute Code Asynchronously