{"id":36334,"date":"2016-07-26T16:22:45","date_gmt":"2016-07-26T10:52:45","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=36334"},"modified":"2016-07-26T16:22:45","modified_gmt":"2016-07-26T10:52:45","slug":"setcronjob-nodejs-client-module","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/setcronjob-nodejs-client-module\/","title":{"rendered":"SetCronJob Nodejs Client Module"},"content":{"rendered":"<p><strong>What is SetCronJob<\/strong><\/p>\n<p><span style=\"font-weight: 400\">SetCronJob is a module that provides you with the ability to manage your application scheduler online. Modern applications require some kind of a scheduler as part of the application to perform tasks on particular instances. Managing this scheduler on the server, either locally or on a distributed system \u00a0is tricky task. Also, if machine restarts all the servers need to be reconfigured again. SetCronJob solves this problem \u00a0by managing all the schedulers on their servers and by eliminating developer responsibility to manage those schedulers.<\/span><\/p>\n<p><strong><span style=\"font-weight: 400\">SetCronJob helps you maintain multiple schedulers for your application, thereby reducing developer headache. It also provides you with the facility to monitor scheduler log and statistics.<\/span><\/strong><\/p>\n<p><strong><span style=\"font-weight: 400\">SetCronJob website has a web management dashboard that provides the facility to manage your scheduler and execution log. You can also \u00a0schedule\/delete\/reset any of the schedulers if required from the management console. SetcronJob application management console looks as follows:<\/span><\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-37885\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Screenshot-from-2016-07-14-1522251.png\" alt=\"Screenshot from 2016-07-14 15:22:25\" width=\"1366\" height=\"768\" \/><\/p>\n<p><strong>Why SetCronJob<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">SetCronJob manages all the jobs on their server so application performance increases as no local job needs to be managed<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Locally created cron jobs have to be reconfigured again or at least once when the server\/machine restarts, which involves overhead for developers as they have to re-configure all the jobs again. Setcronjob manages all the jobs on their server \u00a0so that the machine or system restart issue is resolved.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Managing cron jobs in a cluster environment is always an issue \u00a0as many clusters can execute the same cron job at the same time. This issue is resolved as SetCronJob executes only once on the server.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">SetCronJob is capable of holding data, that can again be passed into the application once the scheduler executes.This is useful in performing data cleaning tasks timely.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">SetCronJob web management console helps you to add, update, delete, re-run cron jobs that provide admin functionality in the application.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Managing timezone with any scheduler has always been an issue. Setronob resolves this as it has a timezone parameter that works for all the timezones.<\/span><\/li>\n<\/ul>\n<p><strong>NodeJs SetCronJob NPM Module<\/strong><\/p>\n<p><span style=\"font-weight: 400\">SetCronJob \u00a0contains REST APIs which can be used to create\/update\/delete the scheduler. SetCronJob has different types of APIs for managing CronJob, Group, Account, and Server. Complete Documentation can be found <\/span><a href=\"https:\/\/www.setcronjob.com\/documentation\/api\"><span style=\"font-weight: 400\">here<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p>\n<p><strong><span style=\"font-weight: 400\">Setcronjob npm module provides a wrapper to the <\/span><a href=\"https:\/\/www.gitbook.com\/book\/princesoni1989\/twitter\/edit#\"><span style=\"font-weight: 400\">SetCronJob<\/span><\/a><span style=\"font-weight: 400\"> API for Node.js. It provides a feature to set online schedulers for your application. These schedulers can call any API or task on your server corresponding to different time settings. You can retrieve your daily logs with respective execution results and can enable or disable schedulers easily. Setcronjob APIs are categorized in four parts as follows:<\/span><\/strong><\/p>\n<ul>\n<li>Server<\/li>\n<li>Group<\/li>\n<li>Cron<\/li>\n<li>Account<\/li>\n<\/ul>\n<p>For more information on the API request and responses visit the\u00a0<a href=\"https:\/\/www.gitbook.com\/book\/princesoni1989\/twitter\/edit#\">SetCronJob API docs<\/a>\u00a0.<br \/>\nSetCronJob <strong>npm<\/strong> module can be found <a title=\"here\" href=\"https:\/\/www.npmjs.com\/package\/setcronjob\">here<\/a>.<\/p>\n<p><strong>Module Usage<\/strong><\/p>\n<p><strong><span style=\"font-weight: 400\">You need a valid SetCronJob Token to work with this module, which you can obtain after signing up \u00a0<\/span><a href=\"https:\/\/www.setcronjob.com\/\"><span style=\"font-weight: 400\">here<\/span><\/a><span style=\"font-weight: 400\">. Once the token is received it can be used \u00a0to instantiate this module and make the API call.<\/span><\/strong><\/p>\n<p>Lets look into process of creating online scheduler using Setcronjob npm Module.<\/p>\n<p><strong>Installation<\/strong><\/p>\n<p>[code]<\/p>\n<p>npm install setcronjob \/\/install locally<\/p>\n<p>npm install -g setcronjob \/\/install globally<\/p>\n<p>npm install setcronjob &#8211;save \/\/install locally and save to package json<\/p>\n<p>[\/code]<\/p>\n<p><strong>Initilzation<\/strong><\/p>\n<p>[code]<br \/>\nvar setCronJob = require(&#8216;setcronjob&#8217;);<br \/>\nvar cronJob = new setCronJob(&#8216;xxxxxxxx&#8217;);<\/p>\n<p>[\/code]<\/p>\n<p><strong>Creating Schedular<\/strong><\/p>\n<p>[code]<br \/>\n\/\/Add cron job<br \/>\nvar params = {<br \/>\n month: 3,<br \/>\n day: 25,<br \/>\n hour: 18,<br \/>\n minute: 0,<br \/>\n url: &#8216;https:\/\/test.com:9000\/api\/v1\/\/execute&#8217;,<br \/>\n timezone: &#8216;Asia\/Kolkata&#8217;,<br \/>\n postData: &#8216;{&quot;postId&quot;:&quot;xyz&quot;}&#8217;,<br \/>\n httpMethod: &#8216;POST&#8217;<br \/>\n};<br \/>\ncronJob.cron.add(params, function (err, result) {<br \/>\n   if (err) {<br \/>\n    console.log(&quot;Error : &quot;, err)<br \/>\n   } else {<br \/>\n    console.log(&quot;Result : &quot;, result)<br \/>\n   }<br \/>\n});<br \/>\n[\/code]<\/p>\n<p>Once a schedule is created it will give you complete information about time and data passed to it, response looks like &#8211;<\/p>\n<p>[code]<br \/>\n{&quot;data&quot;:{&quot;id&quot;:132,&quot;groupId&quot;:0,&quot;minute&quot;:[&quot;41&quot;],&quot;hour&quot;:[&quot;3&quot;],&quot;day&quot;:[&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;10&quot;,&quot;11&quot;,&quot;12&quot;,&quot;13&quot;,&quot;14&quot;,&quot;15&quot;,&quot;16&quot;,&quot;17&quot;,&quot;18&quot;,&quot;19&quot;,&quot;20&quot;,&quot;21&quot;,&quot;22&quot;,&quot;23&quot;,&quot;24&quot;,&quot;25&quot;,&quot;26&quot;,&quot;27&quot;,&quot;28&quot;,&quot;29&quot;,&quot;30&quot;,&quot;31&quot;],&quot;month&quot;:[&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;10&quot;,&quot;11&quot;,&quot;12&quot;],&quot;weekday&quot;:[&quot;2&quot;],&quot;timezone&quot;:&quot;Europe\\\/London&quot;,&quot;url&quot;:&quot;http:\\\/\\\/example.com\\\/cron.php&quot;,&quot;postData&quot;:&quot;&quot;,&quot;fail&quot;:0,&quot;status&quot;:0,&quot;name&quot;:&quot;weekly&quot;,&quot;notify&quot;:0,&quot;points&quot;:1},&quot;info&quot;:[],&quot;status&quot;:&quot;success&quot;,&quot;code&quot;:0}<\/p>\n<p>[\/code]<\/p>\n<p><strong>Update\u00a0<\/strong><b>scheduler<\/b>\u00a0&#8211; Scheduler id can be used to update \u00a0scheduler.<\/p>\n<p>[code]<br \/>\n\/\/Edit cron<br \/>\nvar params = {<br \/>\n\u00a0 \u00a0id: &#8216;xyz&#8217;,<br \/>\n\u00a0 \u00a0month: 4,<br \/>\n\u00a0 \u00a0day: 26,<br \/>\n\u00a0 \u00a0hour: 19,<br \/>\n\u00a0 \u00a0minute: 20,<br \/>\n\u00a0 \u00a0url: &#8216;https:\/\/daytest.com:9000\/api\/v1\/\/execute&#8217;,<br \/>\n\u00a0 \u00a0timezone: &#8216;Asia\/Kolkata&#8217;,<br \/>\n\u00a0 \u00a0postData: &#8216;{&quot;postId&quot;:&quot;xyz&quot;}&#8217;,<br \/>\n\u00a0 \u00a0httpMethod: &#8216;POST&#8217;<br \/>\n};<br \/>\ncronJob.cron.edit(params, function (err, result) {<br \/>\n\u00a0 \u00a0if (err) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0console.log(&quot;Error : &quot;, err)<br \/>\n\u00a0 \u00a0 \u00a0} else {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 console.log(&quot;Result : &quot;, result)<br \/>\n\u00a0 \u00a0}<br \/>\n});<\/p>\n<p>[\/code]<\/p>\n<p><strong>List\/Get Schedular<\/strong><\/p>\n<p>[code]<\/p>\n<p>\/\/list cron for a token<br \/>\ncronJob.cron.list(function (err, result) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0if (err) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 console.log(&quot;Error : &quot;, err)<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0} else {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 console.log(&quot;Result : &quot;, result)<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0}<br \/>\n});<\/p>\n<p>\/\/get one cron job information<br \/>\nvar params = {<br \/>\n\u00a0 \u00a0 \u00a0id: &#8216;xxxxxx&#8217;<br \/>\n};<br \/>\ncronJob.cron.get(params, function (err, result) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0if (err) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0console.log(&quot;Error : &quot;, err)<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0} else {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 console.log(&quot;Result : &quot;, result)<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 }<br \/>\n});<\/p>\n<p>[\/code]<\/p>\n<p><strong>Delete\/Disable Schedular<\/strong><\/p>\n<p>[code]<\/p>\n<p>\/\/delete cron<br \/>\nvar params = {<br \/>\n   id: &#8216;xyz&#8217;<br \/>\n};<br \/>\ncronJob.cron.delete(params, function(err, result) {<br \/>\n   if (err) {<br \/>\n        console.log(&quot;Error : &quot;, err)<br \/>\n   } else {<br \/>\n        console.log(&quot;Result : &quot;, result)<br \/>\n   }<br \/>\n});<\/p>\n<p>\/\/get logs<br \/>\nvar params = {<br \/>\n  id: &#8216;xyz&#8217;<br \/>\n};<br \/>\ncronJob.cron.logs(params, function(err, result) {<br \/>\n    if (err) {<br \/>\n        console.log(&quot;Error : &quot;, err)<br \/>\n    } else {<br \/>\n        console.log(&quot;Result : &quot;, result)<br \/>\n    }<br \/>\n});<\/p>\n<p>[\/code]<\/p>\n<p>Complete example for all \u00a0APIs\u00a0can be found below &#8211;<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/princesoni1989\/SetCronJob\/blob\/master\/example\/cron.js\">Cron<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/princesoni1989\/SetCronJob\/blob\/master\/example\/group.js\">Group<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/princesoni1989\/SetCronJob\/blob\/master\/example\/server.js\">Server<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/princesoni1989\/SetCronJob\/blob\/master\/example\/account.js\">Account<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>What is SetCronJob SetCronJob is a module that provides you with the ability to manage your application scheduler online. Modern applications require some kind of a scheduler as part of the application to perform tasks on particular instances. Managing this scheduler on the server, either locally or on a distributed system \u00a0is tricky task. Also, [&hellip;]<\/p>\n","protected":false},"author":846,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":5},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/36334"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/846"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=36334"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/36334\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=36334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=36334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=36334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}