11import { Utilities } from "../../utilities"
22import { Operator } from "../../operator"
3- import { reschedule } from "../reschedule/ "
3+ import { reschedule } from "../reschedule"
44import { replicate } from "../replicate/"
55import { remove } from "../remove/"
66
7- var toolbelt = function ( jobDoc ) {
7+ let toolbelt = function ( jobDoc ) {
88 this . document = jobDoc ;
9- this . resolved = false ;
9+ this . resolved = false ;
1010
11- this . set = function ( key , value ) {
11+ this . set = function ( key , value ) {
1212 check ( key , String )
1313
14- var docId = this . document . _id ;
15- var patch = { }
14+ let docId = this . document . _id ;
15+ let patch = { }
1616 patch [ "data." + key ] = value ;
1717
1818 // first, update the document
19- var update = Utilities . collection . update ( docId , {
19+ let update = Utilities . collection . update ( docId , {
2020 $set : patch
2121 } )
2222
@@ -31,16 +31,16 @@ var toolbelt = function (jobDoc) {
3131
3232 this . get = function ( key , getLatestFromDatabase ) {
3333 check ( key , String )
34- var docId = this . document . _id
34+ let docId = this . document . _id
3535
3636
3737 if ( getLatestFromDatabase ) {
3838 // Get the latest doc
39- doc = Utilities . collection . findOne ( docId ) ;
39+ let doc = Utilities . collection . findOne ( docId ) ;
4040
4141 // Update the cached doc with the fresh copy
4242 if ( doc ) {
43- this . document = doc ;
43+ this . document = doc ;
4444 }
4545 }
4646
@@ -50,9 +50,9 @@ var toolbelt = function (jobDoc) {
5050 this . push = function ( key , value ) {
5151 check ( key , String )
5252
53- var docId = this . document . _id ;
53+ let docId = this . document . _id ;
5454
55- var update = Utilities . collection . update ( docId , {
55+ let update = Utilities . collection . update ( docId , {
5656 $push : {
5757 [ "data." + key ] : value
5858 }
@@ -64,9 +64,9 @@ var toolbelt = function (jobDoc) {
6464 this . pull = function ( key , value ) {
6565 check ( key , String )
6666
67- var docId = this . document . _id ;
67+ let docId = this . document . _id ;
6868
69- var update = Utilities . collection . update ( docId , {
69+ let update = Utilities . collection . update ( docId , {
7070 $pull : {
7171 [ "data." + key ] : value
7272 }
@@ -76,9 +76,9 @@ var toolbelt = function (jobDoc) {
7676 this . pullAll = function ( key , value ) {
7777 check ( key , String )
7878
79- var docId = this . document . _id ;
79+ let docId = this . document . _id ;
8080
81- var update = Utilities . collection . update ( docId , {
81+ let update = Utilities . collection . update ( docId , {
8282 $pullAll : {
8383 [ "data." + key ] : value
8484 }
@@ -90,9 +90,9 @@ var toolbelt = function (jobDoc) {
9090 check ( value , Number )
9191 value = value || 1
9292
93- var docId = this . document . _id ;
93+ let docId = this . document . _id ;
9494
95- var update = Utilities . collection . update ( docId , {
95+ let update = Utilities . collection . update ( docId , {
9696 $inc : {
9797 [ "data." + key ] : value
9898 }
@@ -104,9 +104,9 @@ var toolbelt = function (jobDoc) {
104104 check ( value , Number )
105105 value = value || 1
106106
107- var docId = this . document . _id ;
107+ let docId = this . document . _id ;
108108
109- var update = Utilities . collection . update ( docId , {
109+ let update = Utilities . collection . update ( docId , {
110110 $dec : {
111111 [ "data." + key ] : value
112112 }
@@ -118,22 +118,22 @@ var toolbelt = function (jobDoc) {
118118 check ( value , Number )
119119 value = value || 1
120120
121- var docId = this . document . _id ;
121+ let docId = this . document . _id ;
122122
123- var update = Utilities . collection . update ( docId , {
123+ let update = Utilities . collection . update ( docId , {
124124 $addToSet : {
125125 [ "data." + key ] : value
126126 }
127127 } )
128128 }
129129
130130 this . success = function ( result ) {
131- var docId = this . document . _id ;
131+ let docId = this . document . _id ;
132132
133- var update = Utilities . collection . update ( docId , {
133+ let update = Utilities . collection . update ( docId , {
134134 $set : {
135135 state : "success" ,
136- } ,
136+ } ,
137137 $push : {
138138 history : {
139139 date : new Date ( ) ,
@@ -150,14 +150,14 @@ var toolbelt = function (jobDoc) {
150150 }
151151
152152 this . failure = function ( result ) {
153- var docId = this . document . _id ;
154- var queueName = this . document . name ;
153+ let docId = this . document . _id ;
154+ let queueName = this . document . name ;
155155
156156 // Update the document
157- var update = Utilities . collection . update ( docId , {
157+ let update = Utilities . collection . update ( docId , {
158158 $set : {
159159 state : "failure" ,
160- } ,
160+ } ,
161161 $push : {
162162 history : {
163163 date : new Date ( ) ,
@@ -170,7 +170,7 @@ var toolbelt = function (jobDoc) {
170170
171171 // Stop the queue
172172 Utilities . logger ( [
173- "Job has failed: " + queueName + ", " + docId ,
173+ "Job has failed: " + queueName + ", " + docId ,
174174 "Queue was stopped; please correct your job function and restart the server"
175175 ] ) ;
176176
@@ -182,44 +182,44 @@ var toolbelt = function (jobDoc) {
182182 }
183183
184184 this . reschedule = function ( config ) {
185- var docId = this . document . _id ;
186- var newDate = reschedule ( docId , config ) ;
185+ const doc = this . document ;
186+ let newDate = reschedule ( doc . _id , config ) ;
187187
188188 if ( ! newDate ) {
189- Utilities . logger ( [ "Error rescheduling job: " + doc . name + "/" + docId , config ] ) ;
189+ Utilities . logger ( [ "Error rescheduling job: " + doc . name + "/" + doc . _id , config ] ) ;
190190 }
191191
192192 this . resolved = true ;
193- return newDate ;
193+ return newDate ;
194194 }
195195
196196 this . replicate = function ( config ) {
197- var doc = this . document ;
198- var newCopy = replicate ( doc , config )
197+ const doc = this . document ;
198+ const newCopy = replicate ( doc , config )
199199
200200 if ( ! newCopy ) {
201- Utilities . logger ( [ "Error cloning job: " + doc . name + "/" + docId , config ] ) ;
201+ Utilities . logger ( [ "Error cloning job: " + doc . name + "/" + doc . _id , config ] ) ;
202202 }
203203
204204 return newCopy ;
205205 }
206206
207207 this . remove = function ( ) {
208- var docId = this . document . _id ;
209- var removeDoc = remove ( docId )
208+ const doc = this . document ;
209+ let removeDoc = remove ( doc . _id )
210210
211211 if ( ! removeDoc ) {
212- Utilities . logger ( [ "Error removing job: " + doc . name + "/" + docId , config ] ) ;
212+ Utilities . logger ( [ "Error removing job: " + doc . name + "/" + doc . _id ] ) ;
213213 }
214214
215215 this . resolved = true ;
216216 return removeDoc ;
217217 }
218218
219219 this . clearHistory = function ( ) {
220- var docId = this . document . _id ;
220+ let docId = this . document . _id ;
221221
222- var update = Utilities . collection . update ( docId , {
222+ let update = Utilities . collection . update ( docId , {
223223 $set : {
224224 history : [ {
225225 date : new Date ( ) ,
@@ -233,12 +233,12 @@ var toolbelt = function (jobDoc) {
233233 }
234234
235235 this . checkForResolution = function ( result ) {
236- var docId = this . document . _id ;
237- var resolution = this . resolved ;
236+ let docId = this . document . _id ;
237+ let resolution = this . resolved ;
238238
239239
240240 if ( ! resolution ) this . success ( result )
241241 }
242242}
243243
244- export { toolbelt }
244+ export { toolbelt }
0 commit comments