Produced by Araxis Merge on 10/4/2017 8:04:34 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | rdk.zip\rdk\product\production\rdk\src\resources\cds-schedule | cds-schedule.js | Fri Aug 25 15:36:55 2017 UTC |
| 2 | rdk.zip\rdk\product\production\rdk\src\resources\cds-schedule | cds-schedule.js | Tue Oct 3 17:16:34 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 686 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | 'use stric t'; | |
| 2 | ||
| 3 | // set up the packag es we need | |
| 4 | var rdk = require('. ./../core/ rdk'); | |
| 5 | var _ = re quire('lod ash'); | |
| 6 | var Object Id = requi re('mongod b').Object ID; | |
| 7 | var testId = require ('../../ut ils/mongo- utils').va lidateMong oDBId; | |
| 8 | ||
| 9 | // Databas e | |
| 10 | var dbName = 'schedu le'; | |
| 11 | var exeCol lection = 'cdsjobs'; | |
| 12 | ||
| 13 | ||
| 14 | // /////// // | |
| 15 | // Job | |
| 16 | // /////// // | |
| 17 | ||
| 18 | ||
| 19 | /** | |
| 20 | * Retriev e a Schedu led job | |
| 21 | * | |
| 22 | * @api {g et} /resou rce/cds/sc hedule/job [?jobname= name] Requ est Schedu le Job | |
| 23 | * | |
| 24 | * @apiNam e getJob | |
| 25 | * @apiGro up CDS Sch eduler | |
| 26 | * | |
| 27 | * @apiPar am {String } [jobname ] Job name | |
| 28 | * | |
| 29 | * @apiSuc cess (Succ ess 200) { json[]} da ta A Job a rray | |
| 30 | * | |
| 31 | * @apiSuc cessExampl e Success- Response: HTTP/1.1 2 00 OK | |
| 32 | { | |
| 33 | "statu s": 200, | |
| 34 | "data" : [{ | |
| 35 | "_id": " 559cd12977 cbe259a740 c0c2", | |
| 36 | "name": | |
| 37 | "sendReque st", | |
| 38 | "data": { | |
| 39 | "cds name": "Ti meout", | |
| 40 | "url ": | |
| 41 | " IP /cds-resul ts-service /core/exec uteRulesJo b" | |
| 42 | }, | |
| 43 | "type": "normal", | |
| 44 | "priorit y": 0, | |
| 45 | "nextRun At": | |
| 46 | "2015-07-1 0T16:08:49 .203Z", | |
| 47 | "jobname ": "job1", | |
| 48 | "disable d": | |
| 49 | true, | |
| 50 | "lastMod ifiedBy": "CDS Jobs Queue", | |
| 51 | "lockedA t": | |
| 52 | null, | |
| 53 | "lastRun At": "2015 -07-08T07: 28:41.928Z ", | |
| 54 | "lastFin ishedAt": "2015-07-0 8T07:28:41 .929Z" | |
| 55 | }] | |
| 56 | } | |
| 57 | * | |
| 58 | * @apiErr or (Error 404) data The id or name speci fied does not exist | |
| 59 | * @apiErr orExample Error-Resp onse: HTTP /1.1 404 N ot Found | |
| 60 | * { "sta tus": 404, | |
| 61 | * "dat a": null } | |
| 62 | * | |
| 63 | */ | |
| 64 | function g etJob(req, res) { | |
| 65 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 66 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS sched ule resour ce is unav ailable.') ; | |
| 67 | } | |
| 68 | var st atus = rdk .httpstatu s.ok; | |
| 69 | var ma tch = {}; | |
| 70 | ||
| 71 | if (re q.query.jo bname) { | |
| 72 | ma tch.jobnam e = req.qu ery.jobnam e; | |
| 73 | } | |
| 74 | ||
| 75 | var ag enda = req .app.subsy stems.cds. getAgenda( ); | |
| 76 | agenda .jobs(matc h, functio n(err, job s) { | |
| 77 | // Work with jobs | |
| 78 | /* | |
| 79 | * This odd JSON parse logic to remove a c ircular re ference th at | |
| 80 | * crashes o ne of the outcepters in RDK as of the ti me of this | |
| 81 | * writing. | |
| 82 | * / | |
| 83 | va r message = (err === null) ? J SON.parse( JSON.strin gify(jobs) ) : err; | |
| 84 | if (err === null && _. isEmpty(jo bs)) { | |
| 85 | status = rdk.https tatus.not_ found; | |
| 86 | } | |
| 87 | re s.status(s tatus).rdk Send(messa ge); | |
| 88 | }); | |
| 89 | } | |
| 90 | ||
| 91 | ||
| 92 | /** | |
| 93 | * Create a schedule d job | |
| 94 | * | |
| 95 | * @api {p ost} /reso urce/cds/s chedule/jo b Create S chedule Jo b | |
| 96 | * | |
| 97 | * @apiNam e postJob | |
| 98 | * @apiGro up CDS Sch eduler | |
| 99 | * | |
| 100 | * @apiHea der {appli cation/jso n} Content -Type | |
| 101 | * @apiHea der {json} content J ob object | |
| 102 | * | |
| 103 | * @apiPar am {String } jobname Job name | |
| 104 | * @apiPar am {String } cdsname CDS Job na me | |
| 105 | * @apiPar am {String } [when] T he time th e CDS Job should run | |
| 106 | * @apiPar am {String } [interva l] The fre quency of running th e CDS Job | |
| 107 | * | |
| 108 | * @apiSuc cess (Succ ess 201) { json} data Job JSON document | |
| 109 | * @apiSuc cessExampl e Success- Response: HTTP/1.1 2 01 Created { "status ": 201, | |
| 110 | * "message ": "Send R equest que ued for Jo bName" } | |
| 111 | * | |
| 112 | * @apiErr or (Error 404) {json } error Mi ssing or i nvalid fie ld(s) | |
| 113 | * @apiErr orExample Error-Resp onse: HTTP /1.1 400 B ad Request { "status ": 404, | |
| 114 | * "error": " Missing re quired CDS job name" } | |
| 115 | * | |
| 116 | */ | |
| 117 | function p ostJob(req , res) { | |
| 118 | req.lo gger.debug ('cds-sche dule.postJ ob'); | |
| 119 | ||
| 120 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 121 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS sched ule resour ce is unav ailable.') ; | |
| 122 | } | |
| 123 | ||
| 124 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, null , function (error, db Connection ) { | |
| 125 | if (error) { | |
| 126 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 127 | } | |
| 128 | va r aj = {}; | |
| 129 | va r url = '' ; | |
| 130 | va r match = {}; | |
| 131 | va r jobname = ''; | |
| 132 | va r cdsname = ''; | |
| 133 | va r when = ' '; | |
| 134 | va r interval = ''; | |
| 135 | ||
| 136 | if (req.quer y.jobname) { | |
| 137 | jobname = req.quer y.jobname; | |
| 138 | match.jo bname = jo bname; | |
| 139 | } | |
| 140 | if (!jobname ) { | |
| 141 | return r es.status( rdk.httpst atus.not_f ound).rdkS end('Missi ng require d schedule job name' ); | |
| 142 | } | |
| 143 | if (req.quer y.cdsname) { | |
| 144 | cdsname = req.quer y.cdsname; | |
| 145 | } | |
| 146 | if (!cdsname ) { | |
| 147 | return r es.status( rdk.httpst atus.not_f ound).rdkS end('Missi ng require d CDS job name'); | |
| 148 | } | |
| 149 | ||
| 150 | ur l = req.qu ery.url || req.app.s ubsystems. cds.getInv ocationUrl (); | |
| 151 | ||
| 152 | if (req.quer y.when) { | |
| 153 | when = r eq.query.w hen; | |
| 154 | } | |
| 155 | if (req.quer y.interval ) { | |
| 156 | interval = req.que ry.interva l; | |
| 157 | } | |
| 158 | ||
| 159 | db Connection .collectio n(exeColle ction).fin dOne({ | |
| 160 | name: cd sname | |
| 161 | }, function( err, resul t) { | |
| 162 | if (!res ult) { | |
| 163 | retu rn res.sta tus(rdk.ht tpstatus.n ot_found). rdkSend('C DS Job \'' + cdsname + '\' doe s not exis t'); | |
| 164 | } | |
| 165 | ||
| 166 | var agen da = req.a pp.subsyst ems.cds.ge tAgenda(); | |
| 167 | ||
| 168 | agenda.j obs(match, function( err, resul t) { | |
| 169 | if ( err) { | |
| 170 | return res .status(rd k.httpstat us.bad_req uest).rdkS end(err); | |
| 171 | } el se if (!_. isEmpty(re sult)) { | |
| 172 | return res .status(rd k.httpstat us.conflic t).rdkSend ('Job \'' + jobname + '\' exis ts'); | |
| 173 | } | |
| 174 | aj = agenda.cr eate(req.a pp.subsyst ems.cds.ge tAgendaJob ProcessorN ame(), { | |
| 175 | cdsname: c dsname, | |
| 176 | url: url | |
| 177 | }); | |
| 178 | aj.a ttrs.jobna me = jobna me; | |
| 179 | ||
| 180 | if ( when) { | |
| 181 | aj.schedul e(req.quer y.when); | |
| 182 | } | |
| 183 | if ( interval) { | |
| 184 | aj.repeatE very(req.q uery.inter val); | |
| 185 | } | |
| 186 | if ( !when) { | |
| 187 | aj.disable (); | |
| 188 | } | |
| 189 | aj.s ave(); | |
| 190 | retu rn res.sta tus(rdk.ht tpstatus.c reated).rd kSend('Sen d Request queued for ' + cdsna me); | |
| 191 | }); | |
| 192 | }) ; | |
| 193 | }); | |
| 194 | } | |
| 195 | ||
| 196 | ||
| 197 | /** | |
| 198 | * Modify a schedule d job | |
| 199 | * | |
| 200 | * @api {p ut} /resou rce/cds/sc hedule/job Modify Sc hedule Job | |
| 201 | * | |
| 202 | * @apiNam e putJob | |
| 203 | * @apiGro up CDS Sch eduler | |
| 204 | * | |
| 205 | * @apiHea der {appli cation/jso n} Content -Type | |
| 206 | * @apiHea der {json} content J ob object | |
| 207 | * | |
| 208 | * @apiPar am {String } jobname Job name | |
| 209 | * @apiPar am {String } [when] T he time th e job is s cheduled t o run | |
| 210 | * @apiPar am {String } [interva l] The fre quency of running th e job | |
| 211 | * @apiPar am {String } [enable] Enable th e job to b e queued | |
| 212 | * @apiPar am {String } [disable ] Disable the job fr om being q ueued | |
| 213 | * | |
| 214 | * @apiSuc cess (Succ ess 200) { json} data update fl ag | |
| 215 | * @apiSuc cessExampl e Success- Response: HTTP/1.1 2 00 Success | |
| 216 | * { "sta tus": 200, | |
| 217 | * "dat a": 1 } | |
| 218 | * | |
| 219 | * @apiErr or (Error 400) {json } error Mi ssing or i nvalid fie ld(s) | |
| 220 | * @apiErr orExample Error-Resp onse: HTTP /1.1 400 B ad Request | |
| 221 | * { "sta tus": 400, | |
| 222 | * "mes sage": "Mi ssing or i nvalid fie ld(s)" } | |
| 223 | * | |
| 224 | * | |
| 225 | */ | |
| 226 | function p utJob(req, res) { | |
| 227 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 228 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS sched ule resour ce is unav ailable.') ; | |
| 229 | } | |
| 230 | var di sable = re q.query.ha sOwnProper ty('disabl e'); | |
| 231 | var en able = req .query.has OwnPropert y('enable' ); | |
| 232 | var jo bname = '' ; | |
| 233 | var wh en = ''; | |
| 234 | var in terval = ' '; | |
| 235 | ||
| 236 | if (di sable && e nable) { | |
| 237 | re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d('Cannot enable and disable a job at th e same tim e.'); | |
| 238 | } | |
| 239 | if (_. isEmpty(re q.query.jo bname)) { | |
| 240 | re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d('Missing required schedule j ob name'); | |
| 241 | } | |
| 242 | jobnam e = req.qu ery.jobnam e; | |
| 243 | ||
| 244 | if (re q.query.wh en) { | |
| 245 | wh en = req.q uery.when; | |
| 246 | } | |
| 247 | if (re q.query.in terval) { | |
| 248 | in terval = r eq.query.i nterval; | |
| 249 | } | |
| 250 | ||
| 251 | var ag enda = req .app.subsy stems.cds. getAgenda( ); | |
| 252 | agenda .jobs({ | |
| 253 | jo bname: job name | |
| 254 | }, fun ction(err, result) { | |
| 255 | if (!_.isEmp ty(err) || _.isEmpty (result)) { | |
| 256 | return r es.status( rdk.httpst atus.not_f ound).rdkS end('Job - ' + jobna me + ' not found'); | |
| 257 | } | |
| 258 | ||
| 259 | va r aj = res ult[0]; | |
| 260 | if (disable) { | |
| 261 | aj.disab le(); | |
| 262 | } else if (e nable) { | |
| 263 | aj.enabl e(); | |
| 264 | } | |
| 265 | if (!when && !interval && disabl e) { | |
| 266 | return r es.status( rdk.httpst atus.ok).r dkSend('Jo b - ' + jo bname + ' disabled = ' + disab le); | |
| 267 | } | |
| 268 | if (when) { | |
| 269 | aj.sched ule(req.qu ery.when); | |
| 270 | } | |
| 271 | if (interval ) { | |
| 272 | aj.repea tEvery(req .query.int erval); | |
| 273 | } | |
| 274 | aj .save(func tion(saveE rror) { | |
| 275 | if (save Error) { | |
| 276 | retu rn res.sta tus(rdk.ht tpstatus.i nternal_se rver_error ).rdkSend( 'Could not update jo b ' + jobn ame); | |
| 277 | } | |
| 278 | return r es.status( rdk.httpst atus.ok).r dkSend('Jo b - ' + jo bname + ' updated'); | |
| 279 | }) ; | |
| 280 | }); | |
| 281 | } | |
| 282 | ||
| 283 | ||
| 284 | /** | |
| 285 | * Delete a schedule d job | |
| 286 | * | |
| 287 | * @api {d elete} /re source/cds /schedule/ job?jobnam e=name Del ete Schedu le Job | |
| 288 | * | |
| 289 | * @apiNam e deleteJo b | |
| 290 | * @apiGro up CDS Sch eduler | |
| 291 | * | |
| 292 | * @apiDes cription T his call d eletes a s cheduled j ob. Either a jobname , an id, | |
| 293 | * o r both are required. | |
| 294 | * | |
| 295 | * @apiPar am {String } [jobname ] name of the job | |
| 296 | * @apiPar am {String } [id] 24 digit HEX number doc id | |
| 297 | * | |
| 298 | * @apiSuc cess (Succ ess 200) { Number} da ta Delete count | |
| 299 | * @apiSuc cessExampl e Success- Response: HTTP/1.1 2 00 OK { "s tatus" 200 , | |
| 300 | * "message ": 1 } | |
| 301 | * | |
| 302 | * @apiErr or (Error 404) {Numb er} data T he specifi ed job was not found | |
| 303 | * @apiErr orExample Error-Resp onse: HTTP /1.1 404 N ot Found { "error": 404, | |
| 304 | * "error": " Job not fo und" } | |
| 305 | * | |
| 306 | */ | |
| 307 | function d eleteJob(r eq, res) { | |
| 308 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 309 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS sched ule resour ce is unav ailable.') ; | |
| 310 | } | |
| 311 | var ma tch = {}; | |
| 312 | ||
| 313 | if (re q.query.jo bname) { | |
| 314 | ma tch.jobnam e = req.qu ery.jobnam e; | |
| 315 | } | |
| 316 | if (re q.query.id ) { | |
| 317 | va r message = testId(r eq.query.i d); | |
| 318 | if (message) { | |
| 319 | return r es.status( rdk.httpst atus.bad_r equest).rd kSend(mess age); | |
| 320 | } | |
| 321 | ma tch._id = new Object Id(req.que ry.id); | |
| 322 | } | |
| 323 | ||
| 324 | if (!m atch.hasOw nProperty( 'jobname') && !match .hasOwnPro perty('_id ')) { | |
| 325 | re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d('Missing or invali d required parameter .'); | |
| 326 | } | |
| 327 | ||
| 328 | var ag enda = req .app.subsy stems.cds. getAgenda( ); | |
| 329 | agenda .cancel(ma tch, funct ion(err, n umRemoved) { | |
| 330 | if (!_.isEmp ty(err)) { | |
| 331 | return r es.status( rdk.httpst atus.inter nal_server _error).rd kSend(err) ; | |
| 332 | } | |
| 333 | if (numRemov ed === 0) { | |
| 334 | return r es.status( rdk.httpst atus.not_f ound).rdkS end('Job n ot found') ; | |
| 335 | } | |
| 336 | re turn res.s tatus(rdk. httpstatus .ok).rdkSe nd(numRemo ved); | |
| 337 | }); | |
| 338 | } | |
| 339 | ||
| 340 | ||
| 341 | module.exp orts.getJo b = getJob ; | |
| 342 | module.exp orts.postJ ob = postJ ob; | |
| 343 | module.exp orts.putJo b = putJob ; | |
| 344 | module.exp orts.delet eJob = del eteJob; |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.