Tutorial · 3 min read
Create, inspect and cancel local Jobs with the published CLI
Try one local Job with the published @sysiphus/cli 0.1.1 command-line tool and the repository Mock server. Answers and brands are fictional. No API key or live monitoring is involved.
Start the local Mock
You need Node.js 22 or later, Git and pnpm 11. Enter the repository and start Mock in one terminal. Keep it open. Installing dependencies and downloading the CLI require network access; task requests below go only to your machine.
git clone https://github.com/jiangqiusuo/OpenGEO.git
cd OpenGEO
pnpm install
pnpm mockCreate a Job in a second terminal
The examples use Windows PowerShell. npm.cmd avoids the execution-policy restrictions on npm.ps1. npm exec runs a pinned version without a global installation. Every command specifies the local endpoint. If OPENGEO_API_KEY is set for another project, use a terminal where that variable is unset.
$job = npm.cmd exec --yes --package=@sysiphus/cli@0.1.1 -- opengeo monitor --prompt "Demo Brand" --idempotency-key "cli-local-001" --base-url http://127.0.0.1:8787 | ConvertFrom-Json
if ($LASTEXITCODE -ne 0) { throw "创建任务失败" }
$job.id
$job.statusDefaults are search and best_effort, which the local Mock supports. Creation returns a job_mock_* ID and queued state. Keep the actual returned id. Its sequence number depends on Jobs already created in your Mock; do not copy an illustrative ID as your own.
Use the same ID for progress and results
npm.cmd exec --yes --package=@sysiphus/cli@0.1.1 -- opengeo job $job.id --base-url http://127.0.0.1:8787
npm.cmd exec --yes --package=@sysiphus/cli@0.1.1 -- opengeo job $job.id --base-url http://127.0.0.1:8787
npm.cmd exec --yes --package=@sysiphus/cli@0.1.1 -- opengeo items $job.id --base-url http://127.0.0.1:8787For a new simulated Job, the first job query advances it to running and the second to succeeded with complete results. Every observation returned by items should have job_id equal to $job.id. Reading items immediately after creation returns an empty array; this alone is not evidence of task failure.
Completion after two queries is a Mock teaching rule. For a live API, follow the returned state and set a polling interval and total waiting limit. CLI --wait 5 sends a preference for one request; it does not poll every five seconds or guarantee completion within five seconds.
Practice retrying and cancelling
Repeat creation with the same question and idempotency key to receive the same Job. Use a new key only for a different task. Reusing a key with another question causes a conflict. Restarting Mock clears its in-memory records, so do this exercise within one run.
$cancelJob = npm.cmd exec --yes --package=@sysiphus/cli@0.1.1 -- opengeo monitor --prompt "Cancel demo" --idempotency-key "cli-local-cancel-001" --base-url http://127.0.0.1:8787 | ConvertFrom-Json
if ($LASTEXITCODE -ne 0) { throw "创建待取消任务失败" }
npm.cmd exec --yes --package=@sysiphus/cli@0.1.1 -- opengeo cancel $cancelJob.id --base-url http://127.0.0.1:8787
npm.cmd exec --yes --package=@sysiphus/cli@0.1.1 -- opengeo job $cancelJob.id --base-url http://127.0.0.1:8787Create a new task here and cancel it before reading progress. Its state should remain cancelled. Cancelling a completed task cannot move it back from succeeded to cancelled. The local exercise has no billing or refund effects.
What to check when a request fails
On a connection error, check that Mock is running and the ports match. If you change OPEN_GEO_PORT, change every --base-url as well. HTTP 409 means an idempotency conflict, 422 means an unsupported Mock configuration, and 429 means the simulated task limit was reached. Restart Mock after your exercise to clear the fixtures if needed.
On macOS and Linux, use npm instead of npm.cmd. Run monitor, copy the returned id from JSON, then pass it to job, items or cancel. Repository developers can also use pnpm cli -- with the same subcommands. Stop Mock with Ctrl+C when finished. The CLI reference and polling Node tutorial provide further parameters and code.