| 24 | } |
| 25 | |
| 26 | enqueue(body, where, config, auth, pushStatus) { |
| 27 | const limit = this.batchSize; |
| 28 | |
| 29 | where = applyDeviceTokenExists(where); |
| 30 | |
| 31 | // Order by objectId so no impact on the DB |
| 32 | const order = 'objectId'; |
| 33 | return Promise.resolve() |
| 34 | .then(() => { |
| 35 | return rest.find(config, auth, '_Installation', where, { |
| 36 | limit: 0, |
| 37 | count: true, |
| 38 | }); |
| 39 | }) |
| 40 | .then(({ results, count }) => { |
| 41 | if (!results || count == 0) { |
| 42 | return pushStatus.complete(); |
| 43 | } |
| 44 | pushStatus.setRunning(Math.ceil(count / limit)); |
| 45 | let skip = 0; |
| 46 | while (skip < count) { |
| 47 | const query = { |
| 48 | where, |
| 49 | limit, |
| 50 | skip, |
| 51 | order, |
| 52 | }; |
| 53 | |
| 54 | const pushWorkItem = { |
| 55 | body, |
| 56 | query, |
| 57 | pushStatus: { objectId: pushStatus.objectId }, |
| 58 | applicationId: config.applicationId, |
| 59 | }; |
| 60 | this.parsePublisher.publish(this.channel, JSON.stringify(pushWorkItem)); |
| 61 | skip += limit; |
| 62 | } |
| 63 | }); |
| 64 | } |
| 65 | } |