Created
November 27, 2014 04:56
-
-
Save alexanderscott/c4ad46a7e1b16735df5d to your computer and use it in GitHub Desktop.
Simple example using Punctual - a Redis-backed task scheduler for node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use strict"; | |
| var util = require('util'), | |
| Punctual = require('punctual'); | |
| /** | |
| * Define a simple TaskRunner for logging to console | |
| */ | |
| function ConsolePrinter(){ | |
| ConsolePrinter.super_.call(this, {}); | |
| this.taskTypes = ['consolePrint']; | |
| } | |
| util.inherits( ConsolePrinter, Punctual.TaskRunner ); | |
| ConsolePrinter.prototype.runTask = function(task){ | |
| console.log("Processing Task ", task.id); | |
| }; | |
| /** | |
| * Instantiate a TaskScheduler to persist, fetch, and route tasks | |
| */ | |
| var scheduler = Punctual.TaskScheduler.create({ | |
| pollIntervalLength : 5000, | |
| taskRunners : { | |
| consolePrinter: new ConsolePrinter() | |
| } | |
| }); | |
| scheduler.start(); | |
| /** | |
| * Insert sample tasks on an interval to be processed | |
| */ | |
| setInterval(function(){ | |
| var task = Punctual.Task.create({ | |
| type: 'consolePrint', | |
| scheduledFor: (new Date().getTime() + (3000)) | |
| }); | |
| return scheduler.scheduleTask(task); | |
| }, 1000); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment