Skip to main content

Jobs

Jobs in Ductape are scheduled events that automate tasks at specific times or intervals. Use them for background processes, recurring tasks, and scheduled workflows.

Quick Example

import { JobEventTypes } from '@ductape/sdk/types';

await ductape.job.create({
name: 'Daily Report',
tag: 'daily-report',
event_type: JobEventTypes.ACTION,
event_tag: 'generate_report',
executions: 0, // 0 = unlimited
intervals: 86400000 // 24 hours
});

Creating a Job

await ductape.job.create({
name: 'Sync Inventory',
tag: 'sync-inventory',
event_type: JobEventTypes.ACTION,
event_tag: 'sync_stock',
executions: 0,
intervals: 3600000 // Every hour
});

Job Fields

FieldTypeDescription
namestringHuman-readable name
tagstringUnique identifier
event_typeJobEventTypesType of event to execute
event_tagstringTag of the event to run
executionsnumberRun count (0 = unlimited)
intervalsnumberMilliseconds between runs

Event Types

TypeWhat it does
ACTIONRuns an action
NOTIFICATIONSends a notification
DATABASE_ACTIONExecutes a database query
FUNCTIONRuns a cloud function
MESSAGEBROKERPublishes to a message broker

Updating a Job

await ductape.job.update('daily-report', {
name: 'Weekly Report',
intervals: 604800000 // 7 days
});

Fetching Jobs

// Get all jobs
const jobs = await ductape.job.fetchAll();

// Get specific job
const job = await ductape.job.fetch('daily-report');

Best Practices

  • Use descriptive names and tags
  • Set intervals thoughtfully to avoid overloading your system
  • Use executions: 0 only for jobs that should run continuously
  • Monitor job execution and failures

See Also