Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions docs/manage/software/scheduled-jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ date: "2025-06-17"
cost: "0"
---

Viam's machine job scheduler allows you to configure automated jobs that run on your machines at specified intervals. This enables you to automate routine tasks such as data collection, sensor readings, maintenance operations, and system checks.
Viam's machine job scheduler allows you to configure automated jobs that run on your machines at specified intervals.
This enables you to automate routine tasks such as data collection, sensor readings, maintenance operations, and system checks.

The job scheduler is built into `viam-server` and executes configured jobs according to their specified schedules. Each job targets a specific resource on your machine and calls a designated method at the scheduled intervals.
The job scheduler is built into `viam-server` and executes configured jobs according to their specified schedules.
Each job targets a specific resource on your machine and calls a designated component or service API method at the scheduled intervals.

## Configure a job

Expand All @@ -31,7 +33,7 @@ The job scheduler is built into `viam-server` and executes configured jobs accor

1. For the **Schedule**, select **Interval** or **Cron** and specify the interval the job should be run in.

1. For **Job**, select a **Resource**, and a **method**.
1. For **Job**, select a **Resource**, and a component or service API **method**.
For the `DoCommand` method also specify the command parameters.

{{% /tab %}}
Expand Down Expand Up @@ -143,7 +145,7 @@ Jobs are configured as part of your machine's configuration. Each job requires t
| `name` | string | **Required** | Unique identifier for the job within the machine. |
| `schedule` | string | **Required** | Schedule specification using unix-cron format or Golang duration. Accepts <ul><li>Unix-cron expressions for time-based scheduling:<ul><li>`"0 */6 * * *"`: Every 6 hours</li><li>`"0 0 * * 0"`: Every Sunday at midnight</li><li>`"*/15 * * * *"`: Every 15 minutes</li><li>`"0 9 * * 1-5"`: Every weekday at 9 AM</li></ul></li><li>Golang duration strings for interval-based scheduling:<ul><li>`"5m"`: Every 5 minutes</li><li>`"1h"`: Every hour</li><li>`"30s"`: Every 30 seconds</li><li>`"24h"`: Every 24 hours</li></ul></li></ul>Job schedules are evaluated in the machine's local timezone. |
| `resource` | string | **Required** | Name of the target resource (component or service). |
| `method` | string | **Required** | gRPC method to call on the target resource. |
| `method` | string | **Required** | Component or service API method to call on the target resource. |
| `command` | object | Optional | Command parameters for `DoCommand` operations. |

## Monitoring and troubleshooting
Expand All @@ -162,9 +164,9 @@ Monitor job execution through `viam-server` logs. Look for `rdk.job_manager`:
- Jobs only run when `viam-server` is running.
- If a unix-cron job is scheduled to start but a previous invocation is still running, the job will be skipped. The job will next run once the previous invocation has finished running and the next scheduled time is reached.
- If a Golang duration job is scheduled to run but a previous invocation is still running, the next invocation will not run until the previous invocation finishes, at which point it will run immediately.
- Jobs can only support using arguments for `DoCommand` method.
Other methods are only supported if they have no required arguments.
To avoid this limitation, a generic service can be written as a module to encapsulate API calls in a DoCommand API.
- `DoCommand` is currently the only supported component and service API method that you can invoke with arguments.
Aside from `DoCommand`, Jobs currently only support component and service API methods that do not require arguments.
To avoid this limitation, you create a module and encapsulate API calls in a DoCommand API call.
- Jobs run locally on each machine and are not coordinated across multiple machines.
- Job execution depends on `viam-server` running.
- Failed jobs do not retry.
8 changes: 4 additions & 4 deletions docs/operate/hello-world/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ For a step-by-step guide, see [Run control logic](/operate/modules/control-logic
The control logic for the project might look like this:

```python {class="line-numbers linkable-line-numbers" data-line=""}
async def sand_at(motion, world_state, arm, x_min, x_max, y_min, y_max):
async def _sand_at(motion, world_state, arm, x_min, x_max, y_min, y_max):
# simple sanding logic that moves the arm from x_min, y_min to x_max, y_max
start_pose = translate_x_y_to_coord(x_min, y_min)
end_pose = translate_x_y_to_coord(x_max, y_max)
Expand All @@ -350,15 +350,15 @@ async def sand_at(motion, world_state, arm, x_min, x_max, y_min, y_max):
return True


async def on_loop(self):
async def _on_loop(self):
self.logger.info("Executing control logic")
# Check vision service for detections of the color of the pencil markings
# on the wood
detections = self.vision_service.get_detections_from_camera(
self.camera_name)

for d in detections:
await sand_at(
await _sand_at(
self.motion_service,
self.world_state,
self.arm_name,
Expand All @@ -379,7 +379,7 @@ async def do_command(
result = {key: False for key in command.keys()}
for name, args in command.items():
if name == "action" and args == "run_control_logic":
await self.on_loop()
await self._on_loop()
result[name] = True
return result
```
Expand Down
20 changes: 10 additions & 10 deletions docs/operate/modules/control-logic.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ To add the control logic, use the `DoCommand()` method.
The method accepts arbitrary JSON objects as commands.

The following code checks the command object and for the `start` command it sets the `running` parameter to `True` and for the `stop` command to `False`.
A third command, `on_loop`, results in the `on_loop()` method being called, but only if `running` is `True`.
A third command, `on_loop`, results in the `_on_loop()` method being called, but only if `running` is `True`.

The `on_loop()` method increments the counter.
The `_on_loop()` method increments the counter.

```python
async def on_loop(self):
async def _on_loop(self):
try:
self.logger.info("Executing control logic")
self.counter += 1
Expand All @@ -140,7 +140,7 @@ The `on_loop()` method increments the counter.
result[name] = True
if name == "action" and args == "on_loop":
if self.running:
await self.on_loop()
await self._on_loop()
result[name] = True
result["counter"] = self.counter
return result
Expand Down Expand Up @@ -199,7 +199,7 @@ class ControlLogic(Generic, EasyResource):
self.running = False
return super().reconfigure(config, dependencies)

async def on_loop(self):
async def _on_loop(self):
try:
self.logger.info("Executing control logic")
self.counter += 1
Expand All @@ -225,7 +225,7 @@ class ControlLogic(Generic, EasyResource):
result[name] = True
if name == "action" and args == "on_loop":
if self.running:
await self.on_loop()
await self._on_loop()
result[name] = True
result["counter"] = self.counter
return result
Expand Down Expand Up @@ -334,7 +334,7 @@ Update your logic in the `do_command` method to use the board:
result[name] = True
if name == "action" and args == "on_loop":
if self.running:
await self.on_loop()
await self._on_loop()
result[name] = True
result["counter"] = self.counter
return result
Expand Down Expand Up @@ -412,7 +412,7 @@ class ControlLogic(Generic, EasyResource):
self.running = False
return super().reconfigure(config, dependencies)

async def on_loop(self):
async def _on_loop(self):
try:
self.logger.info("Executing control logic")
self.counter += 1
Expand Down Expand Up @@ -442,7 +442,7 @@ class ControlLogic(Generic, EasyResource):
result[name] = True
if name == "action" and args == "on_loop":
if self.running:
await self.on_loop()
await self._on_loop()
result[name] = True
result["counter"] = self.counter
return result
Expand Down Expand Up @@ -499,7 +499,7 @@ On the **CONTROL** or the **CONFIGURE** tab, use the `DoCommand` panel:
}
```

To run the control logic loop `on_loop`, copy and paste the following command input:
To run the control logic loop method `_on_loop`, copy and paste the following command input:

```json {class="line-numbers linkable-line-numbers"}
{
Expand Down
Loading