### Command Line Examples for Running Agenda Instances Source: https://github.com/hokify/agenda/blob/main/docs/agenda/3.1.0/index.html Illustrates various command-line invocations to start Agenda-based applications. Examples include running a server without job processing, a server processing specific jobs, and dedicated worker instances for different job types. ```Shell node server.js ``` ```Shell JOB_TYPES=email node server.js ``` ```Shell JOB_TYPES=email node worker.js ``` ```Shell JOB_TYPES=video-processing,image-processing node worker.js ``` -------------------------------- ### Running Agenda Server and Worker Instances Source: https://github.com/hokify/agenda/blob/main/docs/agenda/6.x/index.html Examples of shell commands to start the server and worker processes, demonstrating how to control which job types are processed using the `JOB_TYPES` environment variable. ```Shell node server.js JOB_TYPES=email node server.js JOB_TYPES=email node worker.js JOB_TYPES=video-processing,image-processing node worker.js ``` -------------------------------- ### Running Agenda Instances with Job Type Filtering Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.2.0/index.html Command-line examples for starting Agenda instances. It shows how to run a server without job processing, and how to run workers that process specific job types using the `JOB_TYPES` environment variable. ```shell node server.js ``` ```shell JOB_TYPES=email node server.js ``` ```shell JOB_TYPES=email node worker.js ``` ```shell JOB_TYPES=video-processing,image-processing node worker.js ``` -------------------------------- ### Running Agenda with Different Job Types Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.0.0/index.html Examples of command-line invocations to start Agenda, demonstrating how to control which job types an instance processes using the `JOB_TYPES` environment variable. This allows for flexible deployment where different servers can handle specific job categories, optimizing resource usage. ```bash node server.js ``` ```bash JOB_TYPES=email node server.js ``` ```bash JOB_TYPES=email node worker.js ``` ```bash JOB_TYPES=video-processing,image-processing node worker.js ``` -------------------------------- ### Run Agenda.js Instances with Specific Job Types Source: https://github.com/hokify/agenda/blob/main/docs/agenda/1.0.3/index.html Examples of command-line invocations to start Agenda.js instances, demonstrating how to control which job types a server or worker processes using the `JOB_TYPES` environment variable. ```bash node server.js ``` ```bash JOB_TYPES=email node server.js ``` ```bash JOB_TYPES=email node worker.js ``` ```bash JOB_TYPES=video-processing,image-processing node worker.js ``` -------------------------------- ### Agenda Instance Events and Start Source: https://github.com/hokify/agenda/blob/main/docs/agenda/6.x/index.html Details the events emitted by an Agenda instance, including `ready` (when the MongoDB connection is established and indices are created) and `error` (when a MongoDB connection error occurs). It also shows an example of `agenda.start()`. ```APIDOC Agenda Events: - ready: Event emitted when Agenda MongoDB connection is successfully opened and indices created. - error: Event emitted when Agenda MongoDB connection process has thrown an error. ``` ```JavaScript await agenda.start(); ``` -------------------------------- ### Install Agenda via NPM Source: https://github.com/hokify/agenda/blob/main/docs/agenda/6.x/index.html Provides instructions on how to install the Agenda job queue library using npm. This installation requires a working MongoDB v4+ database to be available for Agenda to connect to. ```bash npm install @hokify/agenda ``` -------------------------------- ### Configuring and Starting Agenda (lib/agenda.js) Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.2.0/index.html Shows how to initialize Agenda with connection options, dynamically load job definitions based on `JOB_TYPES` environment variable, and start the Agenda instance. It exports the configured Agenda instance for use elsewhere. ```javascript const Agenda = require('agenda'); const connectionOpts = {db: {address: 'localhost:27017/agenda-test', collection: 'agendaJobs'}}; const agenda = new Agenda(connectionOpts); const jobTypes = process.env.JOB_TYPES ? process.env.JOB_TYPES.split(',') : []; jobTypes.forEach(type => { require('./lib/jobs/' + type)(agenda); }); if (jobTypes.length) { agenda.start(); // Returns a promise, which should be handled appropriately } module.exports = agenda; ``` -------------------------------- ### Schedule Immediate Agenda Job Example Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.2.0/index.html Example of scheduling a job to run immediately using the `now` method. ```javascript agenda.now('do the hokey pokey'); ``` -------------------------------- ### Starting Agenda Instance Source: https://github.com/hokify/agenda/blob/main/docs/agenda/4.x/index.html This snippet demonstrates how to start the Agenda instance. Calling `agenda.start()` initiates the job processing and ensures the connection is ready. ```JavaScript await agenda.start(); ``` -------------------------------- ### Agenda: Schedule Immediate Job Example Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.0.0/index.html Example of scheduling a job, 'do the hokey pokey', to run immediately using `agenda.now`. ```javascript agenda.now('do the hokey pokey'); ``` -------------------------------- ### dbInit(collection, cb) - Initialize Job Collection Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.0.0/Agenda.html Setup and initialize the collection used to manage Jobs. ```APIDOC Method: dbInit(collection, cb) Description: Setup and initialize the collection used to manage Jobs. Parameters: collection: String - name or undefined for default 'agendaJobs' cb: function - called when the db is initialized Returns: undefined ``` -------------------------------- ### Agenda Configuration and Job Loading (lib/agenda.js) Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.0.0/index.html Configures the Agenda instance with MongoDB connection options, dynamically loads job definitions based on the `JOB_TYPES` environment variable, and starts the Agenda process. This setup allows for flexible deployment where different instances can process specific job categories. ```javascript const Agenda = require('agenda'); const connectionOpts = {db: {address: 'localhost:27017/agenda-test', collection: 'agendaJobs'}}; const agenda = new Agenda(connectionOpts); const jobTypes = process.env.JOB_TYPES ? process.env.JOB_TYPES.split(',') : []; jobTypes.forEach(type => { require('./lib/jobs/' + type)(agenda); }); if (jobTypes.length) { agenda.start(); // Returns a promise, which should be handled appropriately } module.exports = agenda; ``` -------------------------------- ### Initializing and Starting Agenda Instance Source: https://github.com/hokify/agenda/blob/main/docs/agenda/4.x/index.html Shows how to initialize Agenda with connection options, dynamically load job definitions based on environment variables, and start the Agenda instance, ensuring proper handling of the returned promise. ```JavaScript const Agenda = require('agenda'); const connectionOpts = {db: {address: 'localhost:27017/agenda-test', collection: 'agendaJobs'}}; const agenda = new Agenda(connectionOpts); const jobTypes = process.env.JOB_TYPES ? process.env.JOB_TYPES.split(',') : []; jobTypes.forEach(type => { require('./jobs/' + type)(agenda); }); if (jobTypes.length) { agenda.start(); // Returns a promise, which should be handled appropriately } module.exports = agenda; ``` -------------------------------- ### API Method: start() Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.0.0/Agenda.html Starts the job processing mechanism. This method resolves only if a database connection has been established beforehand. ```APIDOC start() → Promise ``` -------------------------------- ### Initialize Agenda Job Collection: dbInit Source: https://github.com/hokify/agenda/blob/main/docs/agenda/1.0.3/Agenda.html Setup and initialize the collection used to manage Jobs. ```APIDOC dbInit(collection, cb) → {undefined} collection: String - name or undefined for default 'agendaJobs' cb: function - called when the db is initialized ``` -------------------------------- ### Install Agenda via NPM Source: https://github.com/hokify/agenda/blob/main/docs/agenda/3.1.0/index.html Instructions for installing the Agenda job queue library using Node Package Manager (NPM). Requires a working MongoDB v3 database. ```NPM npm install agenda ``` -------------------------------- ### Install Agenda via NPM Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.0.0/index.html This command installs the Agenda library using Node Package Manager (NPM). Agenda requires a working MongoDB v3 database to function. ```bash npm install agenda ``` -------------------------------- ### Example Project Structure Diagram Source: https://github.com/hokify/agenda/blob/main/docs/agenda/6.x/index.html Illustrates a recommended project directory structure for an Agenda application, separating server, worker, libraries, controllers, jobs, and models. ```Text - server.js - worker.js lib/ - agenda.js controllers/ - user-controller.js jobs/ - email.js - video-processing.js - image-processing.js models/ - user-model.js - blog-post.model.js ``` -------------------------------- ### Agenda Start Method Implementation Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.2.0/agenda_start.js.html This Node.js module defines the `start` method for the Agenda job scheduler. It initiates job processing by setting up an interval to call `processJobs` periodically and immediately calls it once. It ensures that the database connection is ready before starting and prevents multiple calls to `start`. ```JavaScript 'use strict'; const debug = require('debug')('agenda:start'); const {processJobs} = require('../utils'); /** * Starts processing jobs using processJobs() methods, storing an interval ID * This method will only resolve if a db has been set up beforehand. * @name Agenda#start * @function * @returns {Promise} resolves if db set beforehand, returns undefined otherwise */ module.exports = async function() { if (this._processInterval) { debug('Agenda.start was already called, ignoring'); return this._ready; } await this._ready; debug('Agenda.start called, creating interval to call processJobs every [%dms]', this._processEvery); this._processInterval = setInterval(processJobs.bind(this), this._processEvery); process.nextTick(processJobs.bind(this)); }; ``` -------------------------------- ### Examples of `processEvery` Intervals Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.2.0/index.html This snippet provides various examples of how to use the `processEvery` method with different human-readable interval strings, demonstrating its flexibility for setting job processing frequencies. ```JavaScript agenda.processEvery('one minute'); agenda.processEvery('1.5 minutes'); agenda.processEvery('3 days and 4 hours'); agenda.processEvery('3 days, 4 hours and 36 seconds'); ``` -------------------------------- ### Define Agenda Job: define Source: https://github.com/hokify/agenda/blob/main/docs/agenda/1.0.3/Agenda.html Setup definition for a job. This method is used by consumers of the library to setup their functions. ```APIDOC define(name, options, processor) → {undefined} name: String - name of job options: Object - options for job to run processor: function - function to be called to run actual job ``` -------------------------------- ### Agenda API: start() Source: https://github.com/hokify/agenda/blob/main/docs/agenda/1.0.3/index.html Starts the Agenda job queue processing. This method initiates periodic checks for new jobs in the database and runs them according to their schedules. ```APIDOC agenda.start(): Promise ``` -------------------------------- ### Example of schedule Usage Source: https://github.com/hokify/agenda/blob/main/README.md This example shows how to use the schedule method on a job instance to set its next run time using a human-readable string. ```JavaScript job.schedule('tomorrow at 6pm'); await job.save(); ``` -------------------------------- ### Install Agenda via NPM Source: https://github.com/hokify/agenda/blob/main/docs/agenda/1.0.3/index.html This command installs the Agenda job scheduling library using npm. It is a prerequisite for using Agenda in a Node.js project and should be run in your project's root directory. ```Shell npm install agenda ``` -------------------------------- ### Agenda Human Interval Examples Source: https://github.com/hokify/agenda/blob/main/docs/agenda/6.x/index.html Illustrates various ways to specify job intervals using human-readable strings, leveraging the Human Interval library. Examples include simple units like 'one minute' and combinations of units like '3 days and 4 hours', providing flexibility in scheduling. ```javascript agenda.processEvery('one minute'); agenda.processEvery('1.5 minutes'); agenda.processEvery('3 days and 4 hours'); agenda.processEvery('3 days, 4 hours and 36 seconds'); ``` -------------------------------- ### Start Agenda job processing queue Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.0.0/index.html Initiates the job queue processing. Agenda will check for new jobs at intervals defined by `processEvery` and run them. ```APIDOC start: Starts the job queue processing, checking `processEvery` time to see if there are new jobs. ``` -------------------------------- ### Schedule Immediate Job with Agenda (now) Source: https://github.com/hokify/agenda/blob/main/docs/agenda/3.1.0/index.html Example of scheduling a job to execute immediately using the `now` method. ```JavaScript agenda.now('do the hokey pokey'); ``` -------------------------------- ### Initialize Syntax Highlighting Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.2.0/global.html Initializes the Highlight.js library to automatically highlight code blocks on page load, improving readability of code examples. ```JavaScript hljs.initHighlightingOnLoad(); ``` -------------------------------- ### Agenda Method: start() Source: https://github.com/hokify/agenda/blob/main/docs/agenda/3.1.0/Agenda.html Initiates the job processing mechanism, setting up an interval to regularly check and execute jobs. This method resolves only after a database connection has been established. ```APIDOC start(): Promise Description: Starts processing jobs using processJobs() methods, storing an interval ID This method will only resolve if a db has been set up beforehand. ``` -------------------------------- ### Agenda: Start Job Processing Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.0.0/index.html Example of calling `agenda.start()` to begin processing jobs. This method waits for the MongoDB connection to be opened and indices to be created before resolving. ```javascript await agenda.start(); ``` -------------------------------- ### Create and Save Job Instance with Agenda Source: https://github.com/hokify/agenda/blob/main/docs/agenda/3.1.0/index.html Example of creating a job instance and then explicitly saving it to the database for later processing. ```JavaScript const job = agenda.create('printAnalyticsReport', {userCount: 100}); await job.save(); console.log('Job successfully saved'); ``` -------------------------------- ### Initializing Agenda and Loading Job Definitions Source: https://github.com/hokify/agenda/blob/main/docs/agenda/3.1.0/index.html Configuration for lib/agenda.js, showing how to instantiate Agenda with connection options, dynamically load job definitions from the jobs directory based on the JOB_TYPES environment variable, and start the Agenda instance. ```JavaScript const Agenda = require('agenda'); const connectionOpts = {db: {address: 'localhost:27017/agenda-test', collection: 'agendaJobs'}}; const agenda = new Agenda(connectionOpts); const jobTypes = process.env.JOB_TYPES ? process.env.JOB_TYPES.split(',') : []; jobTypes.forEach(type => { require('./jobs/' + type)(agenda); }); if (jobTypes.length) { agenda.start(); // Returns a promise, which should be handled appropriately } module.exports = agenda; ``` -------------------------------- ### Initializing Agenda and Loading Job Definitions (lib/agenda.js) Source: https://github.com/hokify/agenda/blob/main/docs/agenda/6.x/index.html Shows how to initialize Agenda with connection options, dynamically load job definitions based on `JOB_TYPES` environment variable, and start the Agenda instance. It exports the configured Agenda instance for use elsewhere. ```JavaScript const Agenda = require('agenda'); const connectionOpts = {db: {address: 'localhost:27017/agenda-test', collection: 'agendaJobs'}}; const agenda = new Agenda(connectionOpts); const jobTypes = process.env.JOB_TYPES ? process.env.JOB_TYPES.split(',') : []; jobTypes.forEach(type => { require('./jobs/' + type)(agenda); }); if (jobTypes.length) { agenda.start(); // Returns a promise, which should be handled appropriately } module.exports = agenda; ``` -------------------------------- ### Running Agenda with Specific Job Types Source: https://github.com/hokify/agenda/blob/main/docs/agenda/4.x/index.html Examples of how to start Agenda instances from the command line, either as a server or a dedicated worker, filtering which job types they process using the `JOB_TYPES` environment variable. ```Bash node server.js ``` ```Bash JOB_TYPES=email node server.js ``` ```Bash JOB_TYPES=email node worker.js ``` ```Bash JOB_TYPES=video-processing,image-processing node worker.js ``` -------------------------------- ### Listen for Job Start Event (JavaScript) Source: https://github.com/hokify/agenda/blob/main/README.md The `start` event is called just before any job starts. The `start:job name` event is called just before the specified job starts. ```js agenda.on('start', job => { console.log('Job %s starting', job.attrs.name); }); ``` -------------------------------- ### API Method: agenda.start Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.2.0/Agenda.html Starts the job processing mechanism. This method initiates the interval for processing jobs and requires a database connection to be established beforehand to function correctly. ```APIDOC start() -> Promise Description: Starts processing jobs using processJobs() methods, storing an interval ID This method will only resolve if a db has been set up beforehand. ``` -------------------------------- ### start() API Method Source: https://github.com/hokify/agenda/blob/main/docs/agenda/1.0.3/Agenda.html Initiates the processing of jobs by calling processJobs() methods and storing an interval ID. This method will only resolve successfully if a database connection has been established beforehand. ```APIDOC start() → {Promise} ``` -------------------------------- ### Chainable Agenda Configuration Source: https://github.com/hokify/agenda/blob/main/docs/agenda/1.0.3/index.html This example highlights Agenda's chainable configuration methods, allowing multiple settings to be applied sequentially to an Agenda instance. It shows a common pattern for setting up database connections and processing intervals. ```JavaScript var agenda = new Agenda(); agenda .database(...) .processEvery('3 minutes') ...; ``` -------------------------------- ### Create and Repeat a Job Instance Source: https://github.com/hokify/agenda/blob/main/docs/agenda/4.x/index.html This example demonstrates how to explicitly create a job instance using `agenda.create()`, passing initial data. After starting Agenda, the created job is configured to repeat every week using `repeatEvery()` and then saved to the database, ensuring its persistence and scheduling. ```JavaScript (async function() { const weeklyReport = agenda.create('send email report', {to: 'example@example.com'}); await agenda.start(); await weeklyReport.repeatEvery('1 week').save(); })(); ``` -------------------------------- ### Agenda Events: Listen for Job Start Source: https://github.com/hokify/agenda/blob/main/docs/agenda/1.0.3/index.html Registers a listener for the 'start' event, which is emitted just before any job begins execution. A specific job name can be appended (e.g., 'start:job name') to listen for the start of a particular job. ```JavaScript agenda.on('start', function(job) { console.log('Job %s starting', job.attrs.name); }); ``` -------------------------------- ### Agenda Start Method Implementation Source: https://github.com/hokify/agenda/blob/main/docs/agenda/3.1.0/agenda_start.js.html This JavaScript code defines the `start` method for the Agenda class. It initiates the job processing mechanism by setting up an interval to call `processJobs` and ensures that processing starts immediately. It prevents multiple calls to `start`. ```JavaScript 'use strict'; const debug = require('debug')('agenda:start'); const {processJobs} = require('../utils'); /** * Starts processing jobs using processJobs() methods, storing an interval ID * This method will only resolve if a db has been set up beforehand. * @name Agenda#start * @function * @returns {Promise} resolves if db set beforehand, returns undefined otherwise */ module.exports = async function() { if (this._processInterval) { debug('Agenda.start was already called, ignoring'); return this._ready; } await this._ready; debug('Agenda.start called, creating interval to call processJobs every [%dms]', this._processEvery); this._processInterval = setInterval(processJobs.bind(this), this._processEvery); process.nextTick(processJobs.bind(this)); }; ``` -------------------------------- ### Create and Schedule a Repeating Job Instance Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.0.0/index.html This example demonstrates creating a job instance using `agenda.create()`, then configuring it to repeat every week using `repeatEvery()`, and finally saving it to the database to be processed by Agenda. ```javascript (async function() { const weeklyReport = agenda.create('send email report', {to: 'example@example.com'}); await agenda.start(); await weeklyReport.repeatEvery('1 week').save(); })(); ``` -------------------------------- ### Agenda Events: Job Start Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.0.0/index.html The `start` event is emitted just before any job begins execution. A more specific `start:job name` event is also available for individual job types. ```APIDOC Event: 'start' description: Called just before any job starts. Event: 'start:job name' description: Called just before the specified job starts. ``` ```javascript agenda.on('start', job => { console.log('Job %s starting', job.attrs.name); }); ``` -------------------------------- ### Listen for Job Start Event (JavaScript) Source: https://github.com/hokify/agenda/blob/main/docs/agenda/4.x/index.html Registers a listener for the 'start' event, which is emitted just before any job begins execution. This allows for logging or other actions to be performed at the start of a job. ```JavaScript agenda.on('start', job => { console.log('Job %s starting', job.attrs.name); }); ``` -------------------------------- ### Create and Schedule a Repeating Job Instance Source: https://github.com/hokify/agenda/blob/main/docs/agenda/1.0.3/index.html This snippet demonstrates creating a job instance and configuring it to repeat at a specified interval. It shows how to use the `create` method to instantiate a job and then chain `repeatEvery` and `save` to persist and schedule it. ```JavaScript (async function() { var weeklyReport = agenda.create('send email report', {to: 'another-guy@example.com'}) await agenda.start(); await weeklyReport.repeatEvery('1 week').save(); })(); ``` -------------------------------- ### Handle Job Start Event Source: https://github.com/hokify/agenda/blob/main/docs/agenda/6.x/index.html Listens for the 'start' event, which is emitted just before any job begins execution. Also supports specific job names ('start:job name'). Provides access to the job object. ```APIDOC Event: 'start' description: Called just before a job starts. parameters: job (Job object) Event: 'start:job name' description: Called just before the specified job starts. parameters: job (Job object) ``` ```javascript agenda.on('start', job => { console.log('Job %s starting', job.attrs.name);}); ``` -------------------------------- ### Agenda Start Method Implementation Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.0.0/agenda_start.js.html Implements the `start` method for the Agenda library, which begins processing jobs at a defined interval. It ensures the database is ready before starting the processing loop and prevents multiple calls to avoid redundant intervals. ```JavaScript 'use strict'; const debug = require('debug')('agenda:start'); const utils = require('../utils'); const processJobs = utils.processJobs; /** * Starts processing jobs using processJobs() methods, storing an interval ID * This method will only resolve if a db has been set up beforehand. * @name Agenda#start * @function * @returns {Promise} */ module.exports = async function() { if (this._processInterval) { debug('Agenda.start was already called, ignoring'); return this._ready; } await this._ready; debug('Agenda.start called, creating interval to call processJobs every [%dms]', this._processEvery); this._processInterval = setInterval(processJobs.bind(this), this._processEvery); process.nextTick(processJobs.bind(this)); }; ``` -------------------------------- ### Chain Agenda Configuration Methods Source: https://github.com/hokify/agenda/blob/main/docs/agenda/3.1.0/index.html Demonstrates the chainable nature of Agenda's configuration methods, allowing multiple settings to be applied sequentially to an Agenda instance for concise setup. ```JavaScript const agenda = new Agenda(); agenda .database(...) .processEvery('3 minutes') ...; ``` -------------------------------- ### Mixpanel Initialization and Tracking Setup Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.2.0/job_run.js.html Initializes the Mixpanel tracking library, handling URL hash parameters for editor state and setting up core tracking functions. It ensures the Mixpanel library is loaded asynchronously from a CDN. ```javascript hljs.initHighlightingOnLoad(); (function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=(\[^&\]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments, 0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" "); for(h=0;h Defined in src/index.ts:65 Parameters: fullDetails: boolean = false Returns: Promise ``` -------------------------------- ### Install Agenda via NPM Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.2.0/index.html This snippet shows the command to install the Agenda library using Node Package Manager (NPM). Agenda requires a MongoDB v3+ database to function. ```Shell npm install agenda ``` -------------------------------- ### Chainable Agenda Configuration Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.2.0/index.html This example illustrates the chainable nature of Agenda's configuration methods, allowing multiple settings like database connection and processing interval to be applied sequentially on the Agenda instance. ```JavaScript const agenda = new Agenda(); agenda .database(...) .processEvery('3 minutes') ...; ``` -------------------------------- ### Initialize Mixpanel for Documentation Analytics Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.2.0/agenda_default-concurrency.js.html Initializes the Mixpanel tracking library on the documentation page to collect analytics data. This script handles loading the Mixpanel library and setting up the initial project token. ```JavaScript hljs.initHighlightingOnLoad(); (function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=(\\S*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments, 0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" "); for(h=0;h { console.log('Job %s starting', job.attrs.name); }); ``` ```javascript agenda.on('complete', job => { console.log(`Job ${job.attrs.name} finished`); }); ``` ```javascript agenda.on('success:send email', job => { console.log(`Sent Email Successfully to ${job.attrs.data.to}`); }); ``` ```javascript agenda.on('fail:send email', (err, job) => { console.log(`Job failed with error: ${err.message}`); }); ``` -------------------------------- ### Initialize Mixpanel Analytics Source: https://github.com/hokify/agenda/blob/main/docs/agenda/2.0.0/Agenda.html Initializes the Mixpanel JavaScript SDK with a project token. This snippet sets up the global mixpanel object and loads the SDK asynchronously, allowing for tracking of user events and page views. ```JavaScript (function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=(\[^&\]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments, 0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" "); for(h=0;h