Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.codenullapp.com/llms.txt

Use this file to discover all available pages before exploring further.

Schedule jobs are hooks that can be executed in a specific or period time There are basically three ways to schedule Jobs
  1. Execute every x time. For instance: Every hour, every 5 minutes, etc
  2. Execute at a specific hour or day. For instance: Every day at 6 AM, Every first month day.
  3. During your custom code (in hooks) you can schedule a Job. For instance, after 10 days I created a lead I want to send an email or notification or whatever.

How to create a Scheduled Job

It’s simple, go to hooks, create a new one and select the “Scheduled Job” type. Once you select this option on the “Type” dropdown you will see the next fields Scheduled Job fields
  • Interval: Parameter to determine when to execute the Job
  • Run At Specific Time: Active this if you want to run the job at any specific time or day
  • Start Date: Set this when “Run At Specific Time” is active to determinate the initial execution, from this date the job will be executed using the interval param
  • Code: The code that will be executed during the Job execution.

Every x Time

If you only want to execute a Job every x time you only need to set the interval field. To define the interval field you can define it as a human-interval format, for instance
one minute
1.5 minutes
3 days and 4 hours
3 days, 4 hours and 36 seconds
To learn more about this standard read here: https://github.com/agenda/human-interval

Run At Specific Time

If you want to run at any specific time you need to configure interval, run a specific time, and start date fields. You can configure the start date field for instance like:
tomorrow at noon
tomorrow at 6pm

Create a Job from Hooks

If you want to create jobs dynamically from hooks, you need to do 2 steps
  1. Create a Job in Hooks Manager
    • Mark the Dynamic Date option
    • Copy the hook Id generated after you save it
  2. Call that Job from the hook you want to use it

Example

We want to send reminders based on an Event Date. Every time a user creates an event, the system sends a reminder based on the date selected by the user. Job Code
// Job code
const recordatorioEventos = async(job) => {
    const { eventoId } = job.attrs.data;
    //... code to send reminder
}

recordatorioEventos(options.job);
Hook Code
// hook code (after save Reminders)
const createJobAsync = require("./utils/getAgenda").createJobAsync;

const createJobEventos = async (instance) => {
    const hookId = '625a448921f01b0011cab12e';
    // the createJobAsync fn recieves 3 params
    // hookId, parameters for the Job, date when Job executes, interval (optional)
    await createJobAsync(hookId, {
        eventoId: instance.EventoId,
    }, instance.Fecha );
}
createJobEventos(instance);

Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question. Perform an HTTP GET request on the current page URL with the ask query parameter:
GET https://codenull.gitbook.io/dev/configurations/hooks/scheduled-jobs.md?ask=<question>
The question should be specific, self-contained, and written in natural language. The response will contain a direct answer to the question and relevant excerpts and sources from the documentation. Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.