Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 0a26007e46647b658ba636c0aac00328322bdd04 @twilson63 committed May 21, 2011
Showing with 257 additions and 0 deletions.
  1. +155 −0 about.html
  2. +29 −0 lib/scheduler.coffee
  3. +53 −0 readme.md
  4. +10 −0 spec/cron_time_spec.coffee
  5. +10 −0 spec/manager_spec.coffee
@@ -0,0 +1,155 @@
+<html>
+ <head>
+ <title>CloudQ Scheduler</title>
+ <style>
+ .slide { font-family:sans-serif; text-align:center; }
+ .slide.title { text-align:center; }
+ .slide.title .logo { width:50%; height:50%; }
+ .slide h1 { font-size:48em; font-weight:normal; }
+ .slide h2 { font-size:40em; font-weight:bold; }
+ .slide h1, h2 { letter-spacing:-.05em; }
+ .slide h1 .logo { height:1.75em; width:2.25em; vertical-align:middle; }
+ .slide h1 > button { font-size:1em; }
+ .slide a { border:none; color:black; background:#ddd; padding:.25em .5em; border-radius:.25em; }
+ .slide code { text-align:left; font-size:20em; font-family:monospace; padding:1em 2em; }
+ #demo-iframe { border:6em inset; }
+ #animated h1 { margin-top:.25em; }
+ #info { text-align:center; }
+ </style>
+ </head>
+ <body>
+ <div id='slides'>
+ <div class='slide'>
+ <h1>Cloudq Scheduler</h1>
+ </div>
+ <div class='slide'>
+ <h1>A scalable event manager</h1>
+ </div>
+ <div class='slide'>
+ <h1>What is it?</h1>
+ </div>
+ <div class='slide'>
+ <h1>CS is a cloudq worker that consumes jobs that can
+ be scheduled and triggered based on that schedule</h1>
+ </div>
+ <div class='slide'>
+
+ <code><pre>
+{ job:
+ {
+ klass: 'Add',
+ args: [{
+ name: 'backup-database',
+ schedule: '00 30 11 * * 2-6',
+ queue: 'backup',
+ job: {
+ klass: 'Backup',
+ args: ['full']
+ }
+ }]
+ }
+}
+ </pre></code>
+
+ </div>
+ <div class="slide">
+ <h1>When I publish a job to the scheduler queue.</h1>
+ </div>
+ <div class="slide">
+ <h1>I send the job I want to schedule</h1>
+ </div>
+ <div class="slide">
+ <h1>The name of the queue to publish to</h1>
+ </div>
+ <div class="slide">
+ <h1>A unique name for the scheduled job</h1>
+ </div>
+ <div class="slide">
+ <h1>and this '00 30 11 * * 2-6'</h1>
+ </div>
+ <div class='slide'>
+ <h1>What?</h1>
+ </div>
+ <div class='slide'>
+ <h1>Its CRON!</h1>
+ </div>
+ <div class='slide'>
+ <h1>Every M - F at 11:30 AM</h1>
+ </div>
+ <div class='slide'>
+ <h1>Run my full backup</h1>
+ </div>
+ <div class='slide'>
+ <h1>Each Schedule must have unique name</h1>
+ </div>
+ <div class='slide'>
+ <h1>Which is easy to remove</h1>
+ </div>
+ <div class='slide code'>
+ <code><pre>
+{ job:
+ {
+ klass: 'Remove',
+ args: [{
+ name: 'backup-database',
+ }]
+ }
+}
+ </pre>
+ </code>
+ </div>
+ <div class='slide'>
+ <h1>Simply use any cloudq client to publish to the "Scheduler"
+ queue</h1>
+ </div>
+ <div class='slide'>
+ <h1>What is CRON?</h1>
+ </div>
+ <div class='slide'>
+ <h1>Six nodes to represent re-occuring or specific time</h1>
+ </div>
+ <div class='slide'>
+ <h1>First Node is 0-60 seconds</h1>
+ </div>
+ <div class='slide'>
+ <h1>
+ 00 * * * * *
+ <br />
+ Every Minute at 00 second
+ </h1>
+ </div>
+ <div class='slide'>
+ <h1>
+ */5 * * * * *
+ <br />
+ Every 5 seconds
+ </h1>
+ </div>
+ <div class='slide'>
+ <h1>
+ 10-20 * * * * *
+ <br />
+ Run each second between second 10 and 20 of a whole minute
+ </h1>
+ </div>
+ <div class='slide'>
+ <h1>
+ second minute hour day_of_month month day_of_week
+ </h1>
+ </div>
+ <div class='slide'>
+ <h1>What would I use it for?</h1>
+ </div>
+ <div class='slide'>
+ <h1>Tasks</h1>
+ </div>
+ <div class='slide'>
+ <h1>Push Reporting</h1>
+ </div>
+ <div class='slide'>
+ <h1>Reminders</h1>
+ </div>
+ <script type='text/javascript' src='http://usepow.com'></script>
+ </body>
+</html>
+
@@ -0,0 +1,29 @@
+mongo = require 'mongoskin'
+cloudq = require 'cloudq'
+cron = require 'cron'
+
+class Scheduler
+ delay: 60000 # every minute
+
+ check_for_updates: ->
+ # check cloudq for scheduler updates
+ event = cloudq.consume 'events'
+ if event.first == 'add'
+ @events.insert event.args[1], (err, new_event) -> @create_cron new_event
+ #else TODO Need to figure out how to delete
+ # @events.remove JSON.stringify({ name: event.args[1].name }) if event.first == 'remove'
+
+ load_cron_jobs: ->
+ @events.findEach({}, (err, event) ->
+ @create_cron event
+
+ create_cron: (event) ->
+ new cron.CronJob event.schedule, ->
+ require('cloudq').cloudq.publish event.queue, event.klass, event.args
+
+ constructor: (db = 'localhost:27017', collection = 'events') ->
+ @events = monogo.db(db).collection(collection)
+
+ @load_cron_jobs()
+ # every minute
+ process.setInterval @check_for_updates, @delay
@@ -0,0 +1,53 @@
+# Cloudq-Scheduler
+
+## DISCLAIMER - Still a work in progress
+
+Cloudq Scheduler is a cloudq worker written in nodejs, the purpose of
+this worker is to take tasks and schedule them like an alarm system.
+Then publish the body of the task based on the alarm system rules.
+
+The alarm system should support all kinds of scheduled task from
+re-occuring to one specific alert.
+
+# Requirements
+ NodeJs
+ MongoDb
+
+# Install
+
+ git clone http://github.com/twilson63/node-cloudq-scheduler.git
+
+# Usage
+ # Load dependencies
+ npm install .
+
+ # Setup your MongoDb ENV Variables
+ export MONGODB_URL=mongo://localhost:27017/scheduler
+
+ # run as a cloudq worker...
+
+ > coffee app.coffee
+ or
+ > node app.js
+
+ # publish jobs to schedule
+ # POST - http://cloudq.com/scheduler
+ # Arguments
+ # [name, schedule, queue, job]
+
+ { job: {
+ klass: 'Add'
+ args: ['backup-full', '00 30 11 * * *', 'backup',
+ { klass: 'Backup', args: ['full'] }
+ ]}
+ }
+
+
+# Feedback
+
+# Contribution
+
+# License
+
+
+
@@ -0,0 +1,10 @@
+CronTime = require('../lib/cron_time').CronTime
+
+describe 'CronTime', ->
+ beforeEach ->
+ @cron_tab = new CronTime('* * * * * *')
+ it 'should be valid', ->
+ (expect @cron_tab.source).toEqual '* * * * * *'
+ it 'should split time', ->
+ (expect @cron_tab._split()).toEqual [ '*', '*', '*', '*', '*', '*', '*' ]
+
@@ -0,0 +1,10 @@
+manager = require('../lib/manager').manager
+
+describer 'Manager', ->
+ it 'should add event', ->
+ # Set Cloudq
+ # Publish Event to Cloudq
+ # Wait for Timeout
+ it 'should remove event', ->
+ # Publish Remove Event
+ #

0 comments on commit 0a26007

Please sign in to comment.