@@ -9,15 +9,15 @@ const toolbelt = function (jobDoc) {
99 instance . document = jobDoc ;
1010 instance . resolved = false ;
1111
12- instance . set = ( key , value ) => {
12+ instance . set = async ( key , value ) => {
1313 check ( key , String )
1414
1515 let docId = instance . document . _id ;
1616 let patch = { }
1717 patch [ "data." + key ] = value ;
1818
1919 // first, update the document
20- let update = Utilities . collection . update ( docId , {
20+ let update = await Utilities . collection . updateAsync ( docId , {
2121 $set : patch
2222 } )
2323
@@ -30,30 +30,30 @@ const toolbelt = function (jobDoc) {
3030 return update ;
3131 }
3232
33- instance . get = ( key , getLatestFromDatabase ) => {
33+ instance . get = async ( key , getLatestFromDatabase ) => {
3434 check ( key , String )
3535
3636 let docId = instance . document . _id
3737
3838 if ( getLatestFromDatabase ) {
3939 // Get the latest doc
40- let doc = Utilities . collection . findOne ( docId ) ;
41-
40+ let doc = await Utilities . collection . findOneAsync ( docId ) ;
41+
4242 // Update the cached doc with the fresh copy
4343 if ( doc ) instance . document = doc ;
4444 }
45-
45+
4646 if ( instance . document . data && instance . document . data [ key ] ) {
47- return instance . document . data && instance . document . data [ key ] ;
47+ return instance . document . data && instance . document . data [ key ] ;
4848 }
4949 }
5050
51- instance . push = ( key , value ) => {
51+ instance . push = async ( key , value ) => {
5252 check ( key , String )
5353
5454 let docId = instance . document . _id ;
5555
56- let update = Utilities . collection . update ( docId , {
56+ let update = await Utilities . collection . updateAsync ( docId , {
5757 $push : {
5858 [ "data." + key ] : value
5959 }
@@ -62,76 +62,76 @@ const toolbelt = function (jobDoc) {
6262
6363 }
6464
65- instance . pull = ( key , value ) => {
65+ instance . pull = async ( key , value ) => {
6666 check ( key , String )
6767
6868 let docId = instance . document . _id ;
6969
70- let update = Utilities . collection . update ( docId , {
70+ let update = await Utilities . collection . updateAsync ( docId , {
7171 $pull : {
7272 [ "data." + key ] : value
7373 }
7474 } )
7575 }
7676
77- instance . pullAll = ( key , value ) => {
77+ instance . pullAll = async ( key , value ) => {
7878 check ( key , String )
7979
8080 let docId = instance . document . _id ;
8181
82- let update = Utilities . collection . update ( docId , {
82+ let update = await Utilities . collection . updateAsync ( docId , {
8383 $pullAll : {
8484 [ "data." + key ] : value
8585 }
8686 } )
8787 }
8888
89- instance . inc = ( key , value ) => {
89+ instance . inc = async ( key , value ) => {
9090 check ( key , String )
9191 check ( value , Number )
9292 value = value || 1
9393
9494 let docId = instance . document . _id ;
9595
96- let update = Utilities . collection . update ( docId , {
96+ let update = await Utilities . collection . updateAsync ( docId , {
9797 $inc : {
9898 [ "data." + key ] : value
9999 }
100100 } )
101101 }
102102
103- instance . dec = ( key , value ) => {
103+ instance . dec = async ( key , value ) => {
104104 check ( key , String )
105105 check ( value , Number )
106106 value = value || 1
107107
108108 let docId = instance . document . _id ;
109109
110- let update = Utilities . collection . update ( docId , {
110+ let update = await Utilities . collection . updateAsync ( docId , {
111111 $dec : {
112112 [ "data." + key ] : value
113113 }
114114 } )
115115 }
116116
117- instance . addToSet = ( key , value ) => {
117+ instance . addToSet = async ( key , value ) => {
118118 check ( key , String )
119119 check ( value , Number )
120120 value = value || 1
121121
122122 let docId = instance . document . _id ;
123123
124- let update = Utilities . collection . update ( docId , {
124+ let update = await Utilities . collection . updateAsync ( docId , {
125125 $addToSet : {
126126 [ "data." + key ] : value
127127 }
128128 } )
129129 }
130130
131- instance . success = ( result ) => {
131+ instance . success = async ( result ) => {
132132 let docId = instance . document . _id ;
133133
134- let update = Utilities . collection . update ( docId , {
134+ let update = await Utilities . collection . updateAsync ( docId , {
135135 $set : {
136136 state : "success" ,
137137 } ,
@@ -150,12 +150,12 @@ const toolbelt = function (jobDoc) {
150150 return update ;
151151 }
152152
153- instance . failure = ( result ) => {
153+ instance . failure = async ( result ) => {
154154 let docId = instance . document . _id ;
155155 let queueName = instance . document . name ;
156156
157157 // Update the document
158- let update = Utilities . collection . update ( docId , {
158+ let update = await Utilities . collection . updateAsync ( docId , {
159159 $set : {
160160 state : "failure" ,
161161 } ,
@@ -182,9 +182,9 @@ const toolbelt = function (jobDoc) {
182182 return update ;
183183 }
184184
185- instance . reschedule = ( config ) => {
185+ instance . reschedule = async ( config ) => {
186186 const doc = instance . document ;
187- let newDate = reschedule ( doc . _id , config ) ;
187+ let newDate = await reschedule ( doc . _id , config ) ;
188188
189189 if ( ! newDate ) {
190190 Utilities . logger ( [ "Error rescheduling job: " + doc . name + "/" + doc . _id , config ] ) ;
@@ -194,9 +194,9 @@ const toolbelt = function (jobDoc) {
194194 return newDate ;
195195 }
196196
197- instance . replicate = ( config ) => {
197+ instance . replicate = async ( config ) => {
198198 const doc = instance . document ;
199- const newCopy = replicate ( doc , config )
199+ const newCopy = await replicate ( doc , config )
200200
201201 if ( ! newCopy ) {
202202 Utilities . logger ( [ "Error cloning job: " + doc . name + "/" + doc . _id , config ] ) ;
@@ -205,9 +205,9 @@ const toolbelt = function (jobDoc) {
205205 return newCopy ;
206206 }
207207
208- instance . remove = ( ) => {
208+ instance . remove = async ( ) => {
209209 const doc = instance . document ;
210- let removeDoc = remove ( doc . _id )
210+ let removeDoc = await remove ( doc . _id )
211211
212212 if ( ! removeDoc ) {
213213 Utilities . logger ( [ "Error removing job: " + doc . name + "/" + doc . _id ] ) ;
@@ -217,10 +217,10 @@ const toolbelt = function (jobDoc) {
217217 return removeDoc ;
218218 }
219219
220- instance . clearHistory = ( ) => {
220+ instance . clearHistory = async ( ) => {
221221 let docId = instance . document . _id ;
222222
223- let update = Utilities . collection . update ( docId , {
223+ let update = await Utilities . collection . updateAsync ( docId , {
224224 $set : {
225225 history : [ {
226226 date : new Date ( ) ,
0 commit comments