Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

sl45sms/couchdb_scheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

couchdb_scheduler

!!!WARNING!!! ugly code lives here!
This is a work in progress(not even alpha)...

Yes CouchDB it is database and databases normaly don't do anything except data manipulation, reading, search, writing rows etc.
But CouchDB is a lot more, it is a web server (Mochiweb) that can host applications writed with javascript and html.

One of the things may you miss when write your application is the ability to perform server side task at specific time.

One solution is to use external scheduler that operates as a client, but since you are already running a great server why not take advantage?

Here comes couchdb_scheduler, you can schedule a javascript function on your design document to execute at any time.

Examples

For example, you have a client and will need every month for the next 10 months to update the invoice with the charges.
curl -X POST http://127.0.0.1:5984/dbname/_design/webapp/_schedules/updateinvoicefun/R10%2FPT1M/customer_invoice_doc_id?charge=100

as you can imagine from the above url the module register a new type (_schedule) of design handler, there is defined the function "updateinvoicefun" that do the job.

{
   "_id": "_design/webapp",
   "_rev": "1-a3b0d2074c7d571efdc1a50112a54480",
   "rewrites": [

   ],
...
   "schedules": {
       "updateinvoicefun": "function(doc,req){
       if (!doc.Amount) doc.Amount = 100; doc.Amount += req.amount;
       var message = 'charge it!';
       return [doc, message];}"
   },
 ...
   "updates": {
   }
}

functions for schedules works the same as regular update functions.

more examples:

Schedule to run myfun one hour from now
curl -X POST http://127.0.0.1:5984/dbname/_design/webapp/_schedules/myfunc/PT1H/doc_id

Schedule to run myfun at 2100-1-1T0:0:0 !
curl -X POST http://127.0.0.1:5984/dbname/_design/webapp/_schedules/myfunc/2100/doc_id

time date and repeats specified using iso8601 syntax

English isn’t my first language, so please excuse any mistakes, typo corrections is more than welcome.

About

Schedule to update doc on specific time

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages