SmythOS SDK
    Preparing search index...

    Class SchedulerInstance

    SDK wrapper for Scheduler operations. Provides a simplified interface for scheduling and managing jobs.

    const scheduler = new SchedulerInstance('LocalScheduler', {}, AccessCandidate.agent('my-agent'));

    await scheduler.add('cleanup', Schedule.every('1h'), new Job(
    async () => console.log('Cleanup'),
    { name: 'Cleanup Job' }
    ));

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _readyPromise: ControlledPromise<any>

    Accessors

    Methods

    • Add or update a scheduled job. If a job with the same ID exists, it will be updated.

      Parameters

      • jobId: string

        Unique identifier for the job

      • job: Job

        Job instance with execution function and metadata

      • schedule: Schedule

        Schedule definition (interval or cron)

      Returns Promise<boolean>

      Promise that resolves when the job is scheduled

      await scheduler.add('backup',
      Schedule.every('6h'),
      new Job(async () => {
      console.log('Running backup...');
      }, {
      name: 'Backup Job',
      retryOnFailure: true
      })
      );
    • Schedule an agent skill execution with chainable syntax. Requires an agent to be associated with this scheduler instance.

      Parameters

      • skillName: string

        Name of the skill to execute

      • Optionalargs: any[] | Record<string, any>

        Arguments to pass to the skill

      • Optionalmetadata: IJobMetadata

        Optional job metadata (name, description, retryOnFailure, etc.)

      Returns SchedulerJobCommand

      SchedulerJobBuilder that can be chained with .every() or .cron()

      Error if no agent is associated with this scheduler

      // Schedule a skill to run every 5 seconds
      await scheduler.call('processData', { input: 'test' }, { name: 'Data Processor' }).every('5s');

      // Schedule with cron expression
      await scheduler.call('backup', {}, { retryOnFailure: true }).cron('0 0 * * *');
    • Delete a scheduled job. This removes the job permanently and stops all scheduled executions.

      Parameters

      • jobId: string

        Unique identifier of the job to delete

      Returns Promise<void>

      Promise that resolves when the job is deleted

      await scheduler.delete('backup');
      console.log('Backup job deleted');
    • Get details of a specific scheduled job.

      Parameters

      • jobId: string

        Unique identifier of the job

      Returns Promise<IScheduledJob>

      Promise that resolves to the job details, or undefined if not found

      const job = await scheduler.get('backup');
      if (job) {
      console.log(`Status: ${job.status}`);
      console.log(`Next run: ${job.nextRun}`);
      }
    • List all scheduled jobs for this candidate.

      Returns Promise<IScheduledJob[]>

      Promise that resolves to an array of scheduled jobs

      const jobs = await scheduler.list();
      jobs.forEach(job => {
      console.log(`${job.metadata.name}: ${job.status}`);
      });
    • Pause a scheduled job. The job will not execute until resumed.

      Parameters

      • jobId: string

        Unique identifier of the job to pause

      Returns Promise<void>

      Promise that resolves when the job is paused

      await scheduler.pause('backup');
      console.log('Backup job paused');
    • Schedule an agent prompt execution with chainable syntax. Requires an agent to be associated with this scheduler instance.

      Parameters

      • prompt: string

        The prompt text to send to the agent

      • Optionalmetadata: IJobMetadata

        Optional job metadata (name, description, retryOnFailure, etc.)

      Returns SchedulerJobCommand

      SchedulerJobBuilder that can be chained with .every() or .cron()

      Error if no agent is associated with this scheduler

      // Schedule a prompt to run every hour
      await scheduler.prompt('Generate daily report', { name: 'Daily Report' }).every('1h');

      // Schedule with cron expression
      await scheduler.prompt('Summarize news', { name: 'News Summary' }).cron('0 9 * * *');
    • Resume a paused job. The job will start executing according to its schedule.

      Parameters

      • jobId: string

        Unique identifier of the job to resume

      Returns Promise<void>

      Promise that resolves when the job is resumed

      await scheduler.resume('backup');
      console.log('Backup job resumed');
    • Schedule an agent trigger execution with chainable syntax. Requires an agent to be associated with this scheduler instance.

      Parameters

      • triggerName: string

        Name of the trigger to execute

      • Optionalmetadata: IJobMetadata

        Optional job metadata (name, description, retryOnFailure, etc.)

      Returns SchedulerJobCommand

      SchedulerJobBuilder that can be chained with .every() or .cron()

      Error if no agent is associated with this scheduler

      // Schedule a trigger to run every day
      await scheduler.trigger('daily-sync', { name: 'Daily Sync' }).every('1d');

      // Schedule with cron expression
      await scheduler.trigger('weekly-report', { name: 'Weekly Report' }).cron('0 0 * * 0');