@@ -208,7 +208,7 @@ const handleWorker = async () => {
208208 const queueLastExecution = queueState . last_excution ?. toMillis ( )
209209 const now = admin . firestore . Timestamp . now ( ) . toMillis ( )
210210 if ( queueLastExecution && ( now - queueLastExecution >= 2 * 60 * 1000 ) && ( queueState . store_ids && queueState . store_ids . length ) ) {
211- logger . info ( ' Reset execution')
211+ logger . warn ( '> Reset execution')
212212 await queueControllerRef . doc ( queueController . id ) . set ( {
213213 running : false ,
214214 store_ids : [ ] ,
@@ -222,16 +222,17 @@ const handleWorker = async () => {
222222 }
223223 const query = notificationRef
224224 . where ( 'ready_at' , '<=' , now )
225- . orderBy ( 'ready_at' ) . limit ( 100 )
225+ . orderBy ( 'ready_at' ) . limit ( 600 )
226226
227+ const limitDocs = 50
227228 const notificationDocs = await query . get ( )
228229 const storeIds = [ ]
229230 if ( ! notificationDocs . empty ) {
230231 const docsToRun = [ ]
231- let queueSize = 30
232+ let limitQueueSize = limitDocs
232233 notificationDocs . forEach ( doc => {
233234 const data = doc . data ( )
234- if ( docsToRun . length < queueSize ) {
235+ if ( docsToRun . length < limitQueueSize ) {
235236 let isPushDoc = true
236237 if ( queueState && queueState . store_ids && ! queueState . store_ids . includes ( data . store_id ) ) {
237238 if ( ! storeIds . includes ( data . store_id ) ) {
@@ -240,21 +241,14 @@ const handleWorker = async () => {
240241 if ( data . resource === 'feed_import_image' ) {
241242 // queue size depends on the amount of images
242243 const quantityImgs = data . body ?. imageLinks ?. length
243- queueSize -= quantityImgs || 0
244+ limitQueueSize -= quantityImgs || 0
244245 } else if ( data . resource === 'feed_import_table' ) {
245246 // import one table at a time
246- isPushDoc = queueSize > 20
247- queueSize = isPushDoc ? 0 : queueSize
247+ isPushDoc = limitQueueSize > ( limitDocs - 10 )
248+ limitQueueSize = isPushDoc ? 0 : limitQueueSize
248249 }
249250 if ( isPushDoc ) {
250- docsToRun . push (
251- run ( doc , data )
252- . catch ( ( err ) => {
253- // Todo: remove debug
254- logger . error ( err )
255- throw err
256- } )
257- )
251+ docsToRun . push ( run ( doc , data ) )
258252 }
259253 }
260254 }
0 commit comments