C3 AI Documentation Home

Console Reference: c3MonitorJob

c3MonitorJob monitors and periodically reports the status of a job. A job is a long-running asynchronous process in your application, for example, a cron job or a MapReduce operation over a large dataset. To learn more about jobs, see Create Long-Running Jobs and Implement Parallel Batch Jobs.

Parameters

NameRequiredTypeDescription
jobTypeThe job you want to monitor
periodnumberJob status report interval in milliseconds. Defaults to 10 secs.

Returns

A numerical interval id for the reporting function.

Example

The following examples use a custom Temperature Type. To see the CronJob and CronSchedule snippet in context, take a look at Schedule a Job with CronJob.

To begin, create a job or acquire a reference to one:

JavaScript
// Create and persist the job
// The Type and method to run
const action = ActionRef.fromTypeAction(Temperature, 'recordTemperature');

// On which schedule to run the action
const schedule = CronSchedule.make({
  startTime: null,                  // Start immediately
  endTime: null,                    // Run indefinitely
  cronExpression: "0 0/5 * * * ?",  // Every five minutes
  timeZone: "America/Los_Angeles"   // (Optional) Pacific Time
});

// Create and persist the job
const job = CronJob.make({
  name: "Capture weather data",
  description: "Collects weather data for San Jose",
  action: action,                 // The method to run
  inputs: {city: "San Jose"},     // Parameters to the method
  concurrent: false,              // Only run one instance at a time
  inactive: false,                // Start running immediately
  scheduleDef: schedule
}).create();

Monitor the job every ten seconds:

JavaScript
c3MonitorJob(job); // reports status every 10 seconds

// Logs the following:
// Job Capture weather data: <id> status: <status> <progress>

Alternatively, monitor the job every hour:

JavaScript
c3MonitorJob(job, 1_800_1000); // reports status every 30 minutes

// Logs the following:
// Job Capture weather data: <id> status: <status> <progress>

See also

Was this page helpful?