mirror of
https://fast.feibisi.com/https://github.com/parcelvoy/platform.git
synced 2025-08-28 11:46:02 +08:00
Adds additional campaign generation logic (#646)
This commit is contained in:
parent
a7c855e8db
commit
d368613818
2 changed files with 8 additions and 1 deletions
|
@ -2,6 +2,7 @@ import PushJob from '../providers/push/PushJob'
|
|||
import WebhookJob from '../providers/webhook/WebhookJob'
|
||||
import TextJob from '../providers/text/TextJob'
|
||||
import EmailJob from '../providers/email/EmailJob'
|
||||
import { logger } from '../config/logger'
|
||||
import { User } from '../users/User'
|
||||
import { UserEvent } from '../users/UserEvent'
|
||||
import Campaign, { CampaignCreateParams, CampaignDelivery, CampaignParams, CampaignPopulationProgress, CampaignProgress, CampaignSend, CampaignSendParams, CampaignSendReferenceType, CampaignSendState, SentCampaign } from './Campaign'
|
||||
|
@ -288,6 +289,7 @@ export const generateSendList = async (campaign: SentCampaign) => {
|
|||
// Clear any aborted sends
|
||||
await clearCampaign(campaign)
|
||||
|
||||
const now = Date.now()
|
||||
const cacheKey = CacheKeys.populationProgress(campaign)
|
||||
|
||||
const stream = UserList.query()
|
||||
|
@ -295,11 +297,14 @@ export const generateSendList = async (campaign: SentCampaign) => {
|
|||
.whereIn('list_id', campaign.list_ids ?? [])
|
||||
.stream()
|
||||
|
||||
logger.debug({ campaign: campaign.id, elapsed: Date.now() - now }, 'campaign:generate:progress:started')
|
||||
|
||||
let count = 0
|
||||
const limit = 10_000
|
||||
|
||||
for await (const user of stream) {
|
||||
if (count % limit === 0) {
|
||||
logger.debug({ count, campaign: campaign.id, elapsed: Date.now() - now }, 'campaign:generate:progress')
|
||||
await recipientPartialQuery({
|
||||
campaign,
|
||||
project,
|
||||
|
@ -317,6 +322,8 @@ export const generateSendList = async (campaign: SentCampaign) => {
|
|||
count++
|
||||
}
|
||||
|
||||
logger.debug({ count, campaign: campaign.id, elapsed: Date.now() - now }, 'campaign:generate:progress:finished')
|
||||
|
||||
await Campaign.update(qb => qb.where('id', campaign.id), { state: 'scheduled' })
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ export default class CampaignStateJob extends Job {
|
|||
|
||||
// Fetch anything that is currently running, has finished
|
||||
// within the last two days or has activity since last run
|
||||
const openedCampaignIds = await App.main.redis.smembers(CacheKeys.pendingStats).then(ids => ids.map(parseInt))
|
||||
const openedCampaignIds = await App.main.redis.smembers(CacheKeys.pendingStats).then(ids => ids.map(parseInt).filter(x => x))
|
||||
const campaigns = await Campaign.query()
|
||||
.whereIn('state', ['scheduled', 'running'])
|
||||
.orWhere(function(qb) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue