Developer guide
Developer guide

Schedule server logic

The API v1.0 scheduler invokes an exported function on a module using a cron expression. Check for an existing named job before creating one, because scheduleJob creates a schedule record.

async function ensureDailyJob({ weSystem }) {
  const jobName = 'Daily account check';
  const existing = await weSystem.getExistingJobs({ jobName });
  if (existing) return existing;

  return weSystem.scheduleJob({
    jobName,
    cronExpression: '0 0 10 * * *',
    module: { namespace: 'c', moduleName: 'account_jobs' },
    functionName: 'checkAccounts',
    payloadJson: {}
  });
}

async function checkAccounts({ weSystem }) {
  // Perform the scheduled operation using API v1.0.
  return { checked: true };
}

module.exports = { ensureDailyJob, checkAccounts };

module.namespace is c for a custom module or std for a standard module. moduleName must identify a loadable module and functionName must be an exported function. The scheduler validates these before inserting the job. A qualified module name of the form c__account_jobs is stored for the job. The current scheduler rejects expressions whose first segment is *, and computes a next-run time before saving.

getExistingJobs({ jobName }) returns the active cron job matching that name or null. abortJob({ jobName }) stops a named active cron job. Choose stable, distinct names. Put recurring work in a function that can safely handle retries or repeated runs.

The current shape is implemented in working/platformAPI/v1.0/index.js; working/environment_modules/custom/we_test/index.js shows a call from an after-update trigger.