2022-05-05 09:32:14 +02:00
|
|
|
import { Event } from "@budibase/types"
|
2022-05-10 11:33:59 +02:00
|
|
|
import { processors } from "./processors"
|
2022-05-23 23:14:44 +02:00
|
|
|
import * as identification from "./identification"
|
2022-05-31 22:04:41 +02:00
|
|
|
import * as backfill from "./backfill"
|
2022-04-01 22:29:44 +02:00
|
|
|
|
2022-05-25 01:15:52 +02:00
|
|
|
export const publishEvent = async (
|
|
|
|
event: Event,
|
|
|
|
properties: any,
|
|
|
|
timestamp?: string | number
|
|
|
|
) => {
|
2022-05-23 23:14:44 +02:00
|
|
|
// in future this should use async events via a distributed queue.
|
2022-05-24 21:01:13 +02:00
|
|
|
const identity = await identification.getCurrentIdentity()
|
2022-05-31 22:04:41 +02:00
|
|
|
|
|
|
|
const backfilling = await backfill.isBackfillingEvent(event)
|
|
|
|
// no backfill - send the event and exit
|
|
|
|
if (!backfilling) {
|
|
|
|
await processors.processEvent(event, identity, properties, timestamp)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// backfill active - check if the event has been sent already
|
|
|
|
const alreadySent = await backfill.isAlreadySent(event, properties)
|
|
|
|
if (alreadySent) {
|
|
|
|
// do nothing
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
// send and record the event
|
|
|
|
await processors.processEvent(event, identity, properties, timestamp)
|
|
|
|
await backfill.recordEvent(event, properties)
|
|
|
|
}
|
2022-04-01 22:29:44 +02:00
|
|
|
}
|