@@ -34,6 +34,7 @@ var toolbelt = function (jobDoc) {
3434 check ( key , String )
3535 var docId = this . document . _id
3636
37+
3738 if ( getLatestFromDatabase ) {
3839 // Get the latest doc
3940 doc = Utilities . collection . findOne ( docId ) ;
@@ -47,6 +48,86 @@ var toolbelt = function (jobDoc) {
4748 return this . document . data [ key ] || null ;
4849 }
4950
51+ this . push = function ( key , value ) {
52+ check ( key , String )
53+
54+ var docId = this . document . _id ;
55+
56+ var update = Utilities . collection . update ( docId , {
57+ $push : {
58+ [ "data." + key ] : value
59+ }
60+ } )
61+
62+
63+ }
64+
65+ this . pull = function ( key , value ) {
66+ check ( key , String )
67+
68+ var docId = this . document . _id ;
69+
70+ var update = Utilities . collection . update ( docId , {
71+ $pull : {
72+ [ "data." + key ] : value
73+ }
74+ } )
75+ }
76+
77+ this . pullAll = function ( key , value ) {
78+ check ( key , String )
79+
80+ var docId = this . document . _id ;
81+
82+ var update = Utilities . collection . update ( docId , {
83+ $pullAll : {
84+ [ "data." + key ] : value
85+ }
86+ } )
87+ }
88+
89+ this . inc = function ( key , value ) {
90+ check ( key , String )
91+ check ( value , Number )
92+ value = value || 1
93+
94+ var docId = this . document . _id ;
95+
96+ var update = Utilities . collection . update ( docId , {
97+ $inc : {
98+ [ "data." + key ] : value
99+ }
100+ } )
101+ }
102+
103+ this . dec = function ( key , value ) {
104+ check ( key , String )
105+ check ( value , Number )
106+ value = value || 1
107+
108+ var docId = this . document . _id ;
109+
110+ var update = Utilities . collection . update ( docId , {
111+ $dec : {
112+ [ "data." + key ] : value
113+ }
114+ } )
115+ }
116+
117+ this . addToSet = function ( key , value ) {
118+ check ( key , String )
119+ check ( value , Number )
120+ value = value || 1
121+
122+ var docId = this . document . _id ;
123+
124+ var update = Utilities . collection . update ( docId , {
125+ $addToSet : {
126+ [ "data." + key ] : value
127+ }
128+ } )
129+ }
130+
50131 this . success = function ( result ) {
51132 var docId = this . document . _id ;
52133
@@ -126,6 +207,22 @@ var toolbelt = function (jobDoc) {
126207 return removeDoc ;
127208 }
128209
210+ this . clearHistory = function ( ) {
211+ var docId = this . document . _id ;
212+
213+ var update = Utilities . collection . update ( docId , {
214+ $set : {
215+ history : [ {
216+ date : new Date ( ) ,
217+ state : "cleared" ,
218+ serverId : Utilities . config . getServerId ( )
219+ } ]
220+ }
221+ } )
222+
223+ return update ;
224+ }
225+
129226 this . checkForResolution = function ( ) {
130227 var docId = this . document . _id ;
131228 var queueName = this . document . name ;
0 commit comments