Schedulers (Cron Jobs)

Schedulers enable you to automate actions at defined intervals using cron expressions. They're ideal for tasks such as automatic data updates, periodic notifications, and report generation.


Actions Supported by Schedulers

Modifying Database Data

Automatically update records or perform periodic data transformations.

Sending Emails

Dispatch notifications, reports, or alerts to designated recipients at scheduled intervals.


How It Works

  • Setting the Schedule
    Users define the desired schedule using cron expressions to specify the exact timing (e.g., daily, weekly, monthly).

  • Defining the Action
    The scheduler executes the predefined action, such as calling an API, triggering a script, or running a database query, when the scheduled time is reached.

Schedulers are a powerful tool for automating workflows and ensuring timely execution of critical tasks.


Sample Implementation

async function customizeERP(apiOperations) {
  const tableName = "Your Table Name";
  const payload = {
    __d3__filterdata: {
      where: {} // Add conditions if needed
    }
  };
 
  const { readOp } = apiOperations;
  const rowsData = await readOp(tableName, payload);
  return rowsData;
}

Example Code

async function customizeERP(apiOperations) {
  const tableName = "table_name"; // Replace with your actual table
  const { readOp, updateOp } = apiOperations;
 
  // 1. Read records where status is 'active' but expiry date is in the past
  const expiredRecords = await readOp(tableName, {
    __d3__filterdata: {
      where: {
        status: "active",
        expiry_date: { $lt: new Date().toISOString() }
      }
    }
  });
 
  // 2. Update each expired record to mark it as 'expired'
  const updatedResults = await Promise.all(
    expiredRecords.rows.map(async (record) => {
      return await updateOp(tableName, {
        __d3__id: record.id,
        __d3__newData: {
          status: "expired"
        }
      });
    })
  );
 
  return {
    result: {
      totalChecked: expiredRecords.count,
      totalUpdated: updatedResults.length
    }
  };
}

Example Output

{
  "response": {
    "__d3__result": {
      "result": {
        "totalChecked": 5,
        "totalUpdated": 3
      }
    },
    "__d3__error": false,
    "printConsole": []
  }
}
Last updated on
Transform Data into Decisions with Supista – Your Intelligent Data Partner
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Cookie Policy. Learn More.