Skip to content

Commit

Permalink
Adds batching configuration with max batch size of 10,000. Throws an …
Browse files Browse the repository at this point in the history
…error if sync mode is not included and the destination does no operation
  • Loading branch information
nick-Ag committed Jul 30, 2024
1 parent a174a3c commit 907e77d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GlobalSetting } from '@segment/actions-core'
import { GlobalSetting, InputField } from '@segment/actions-core'

export const adAccountId: GlobalSetting = {
type: 'string',
Expand All @@ -7,6 +7,24 @@ export const adAccountId: GlobalSetting = {
required: true
}

export const enable_batching: InputField = {
label: 'Enable Batching',
description: 'Enable batching of requests.',
type: 'boolean',
default: true,
unsafe_hidden: true,
required: true
}

export const batch_size: InputField = {
label: 'Batch Size',
description: 'Maximum number of events to include in each batch. Actual batch sizes may be lower.',
type: 'number',
default: 10000,
unsafe_hidden: true,
required: true
}

// A hardcoded list of all possible schema properties that can be sent to Facebook.
// If the payloads do not contain a value for one of these schema properties, then empty string will be sent
export const SCHEMA_PROPERTIES = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { ActionDefinition } from '@segment/actions-core'
import { IntegrationError, ActionDefinition } from '@segment/actions-core'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
import FacebookClient from '../fbca-operations'
import { batch_size, enable_batching } from '../fbca-properties'

const action: ActionDefinition<Settings, Payload> = {
title: 'Sync Audience',
Expand Down Expand Up @@ -251,7 +252,9 @@ const action: ActionDefinition<Settings, Payload> = {
multiple: true,
label: 'Page IDs',
description: 'The page IDs of the user.'
}
},
enable_batching,
batch_size
},
perform: async (request, { settings, payload, hookOutputs, syncMode }) => {
const fbClient = new FacebookClient(request, settings.retlAdAccountId)
Expand All @@ -263,6 +266,8 @@ const action: ActionDefinition<Settings, Payload> = {
deleteUsers: syncMode === 'delete' ? true : false
})
}

throw new IntegrationError('Sync mode is required for perform', 'MISSING_REQUIRED_FIELD', 400)
},
performBatch: async (request, { settings, payload, hookOutputs, syncMode }) => {
const fbClient = new FacebookClient(request, settings.retlAdAccountId)
Expand All @@ -274,6 +279,8 @@ const action: ActionDefinition<Settings, Payload> = {
deleteUsers: syncMode === 'delete' ? true : false
})
}

throw new IntegrationError('Sync mode is required for performBatch', 'MISSING_REQUIRED_FIELD', 400)
}
}

Expand Down

0 comments on commit 907e77d

Please sign in to comment.