Schedule automated jobs | Viam Documentation

Schedule automated jobs

Schedule automated jobs that call methods on your machine’s components and services at specified intervals. Use jobs to automate routine tasks like reading sensors, capturing images, running calibration routines, or syncing data.

When to use jobs

Jobs are a good fit when you need to:

If you need conditional logic, coordination between multiple resources, or responses to events, write a logic module instead.

Add a job

You can add a job to a single machine or to a fragment. Adding a job to a fragment deploys it to every machine that uses that fragment, which is the recommended approach for fleet-wide scheduling.

  1. Navigate to your machine’s CONFIGURE tab, or navigate to your fragment’s page at app.viam.com/fragments.
  2. Click + and select Job.
  3. Enter a name for the job and click Create.

Configure the schedule

The job card has a Schedule section with three options:

Interval: run the job every N units of time. Select a number and a unit (milliseconds, seconds, minutes, hours, or days). For example, “every 5 minutes.”

Cron: run the job on a cron schedule. Enter a 5-field or 6-field cron expression. The UI shows a human-readable description of the schedule. Examples:

Cron schedules are evaluated in the machine’s local timezone.

Continuous: run the job in an infinite loop. Each invocation starts immediately after the previous one completes. Use this for tasks that should always be running.

Configure the action

In the Job section:

  1. Select a Resource from the dropdown. This lists all components and services on the machine.
  2. Enter the Method to call on that resource. For custom actions, use DoCommand.
  3. If the method is DoCommand, a Command editor appears. Enter the JSON command to send:
{
  "action": "calibrate",
  "mode": "full"
}

Configure logging

In the Log threshold section, set the minimum log level for this job’s output:

Job execution logs appear under rdk.job_manager.{job-name} in the machine’s logs. At the default Info level, “Job triggered” and “Job succeeded” messages are at debug level and will not appear. Set the log threshold to Debug to see them.

JSON configuration reference

In JSON mode, jobs are defined in the jobs array at the top level of the machine configuration:

{
  "jobs": [
    {
      "name": "hourly-reading",
      "schedule": "0 * * * *",
      "resource": "my-sensor",
      "method": "GetReadings"
    },
    {
      "name": "calibration",
      "schedule": "0 2 * * 0",
      "resource": "my-sensor",
      "method": "DoCommand",
      "command": {
        "action": "calibrate"
      },
      "log_configuration": {
        "level": "debug"
      }
    }
  ]
}
Field Type Required Description
name string Yes Unique name for the job.
schedule string Yes Cron expression (5 or 6 fields), Go duration string (for example, "30s", "5m", "1h"), or "continuous".
resource string Yes Name of the component or service to call.
method string Yes The API method to invoke on the resource.
command object No Arguments for DoCommand. Ignored for other methods.
log_configuration object No Set "level" to "debug", "info", "warn", or "error".

Verify a job is running

Check the machine’s LOGS tab and filter for job_manager. Successful execution produces:

debug rdk.job_manager.hourly-reading  Job triggered
debug rdk.job_manager.hourly-reading  Job succeeded  response map[...]

If the resource is not found:

warn rdk.job_manager.hourly-reading  Could not get resource  error could not find the resource for name my-sensor

Scheduling behavior

Interval and cron jobs are singleton: only one instance runs at a time.

Continuous jobs restart immediately after each invocation. If the job function exits unexpectedly, it restarts after a 5-second delay.

Limitations