Minor tweaks to users table (#107)

And add retry to jobs
This commit is contained in:
Chris Anderson 2023-04-01 17:47:59 -05:00 committed by GitHub
parent c525d4826a
commit 1740669f95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 9 deletions

View file

@ -41,9 +41,11 @@ export interface SegmentContext {
name: string
version: string
}
timezone: string
locale: string
timezone?: string
}
// https://segment.com/docs/connections/spec/common/
export type SegmentPostEvent = {
event: string
anonymousId: string
@ -53,7 +55,6 @@ export type SegmentPostEvent = {
traits?: Record<string, any>
type: 'track' | 'alias' | 'identify'
timestamp: string
locale: string
} & (
{
type: 'track',

View file

@ -14,6 +14,11 @@ interface EventPostTrigger {
export default class EventPostJob extends Job {
static $name = 'event_post'
options = {
delay: 0,
attempts: 1,
}
static from(data: EventPostTrigger): EventPostJob {
return new this(data)
}
@ -23,7 +28,7 @@ export default class EventPostJob extends Job {
const user = await getUserFromClientId(project_id, { anonymous_id, external_id } as ClientIdentity)
if (!user) {
logger.error({ project_id, event }, 'job:event_post:unknown-user')
return
throw new Error('job:event_post:unknown-user')
}
// Create event for given user

View file

@ -82,7 +82,7 @@ router.post('/segment', async ctx => {
email: event.traits.email,
phone: event.traits.phone,
timezone: event.context.timezone,
locale: event.locale,
locale: event.context.locale,
data: event.traits,
},
}))

View file

@ -2,6 +2,7 @@ import App from '../app'
interface JobOptions {
delay?: number
attempts?: number
}
export interface EncodedJob {
@ -12,7 +13,10 @@ export interface EncodedJob {
export default class Job implements EncodedJob {
data: any
options: JobOptions = { delay: 0 }
options: JobOptions = {
delay: 0,
attempts: 3,
}
static $name: string = Job.constructor.name

View file

@ -22,7 +22,16 @@ export default class RedisQueueProvider implements QueueProvider {
constructor(config: RedisConfig, queue: Queue) {
this.queue = queue
this.config = config
this.bull = new BullQueue('parcelvoy', { connection: config })
this.bull = new BullQueue('parcelvoy', {
connection: config,
defaultJobOptions: {
attempts: 3,
backoff: {
type: 'exponential',
delay: 1000,
},
},
})
}
async enqueue(job: Job): Promise<void> {
@ -51,6 +60,7 @@ export default class RedisQueueProvider implements QueueProvider {
age: 24 * 3600, // keep up to 24 hours
},
delay: job.options.delay,
attempts: job.options.attempts,
},
}
}

View file

@ -42,7 +42,7 @@ export const getUserFromEmail = async (projectId: number, email: string): Promis
export const pagedUsers = async (params: SearchParams, projectId: number) => {
return await User.searchParams(
params,
['email', 'phone'],
['external_id', 'email', 'phone'],
b => b.where({ project_id: projectId }),
)
}

View file

@ -15,16 +15,16 @@ export default function UserTabs() {
{...state}
columns={[
{ key: 'full_name', title: 'Name' },
{ key: 'external_id', title: 'External ID' },
{ key: 'email' },
{ key: 'phone' },
{ key: 'timezone' },
{ key: 'locale' },
{ key: 'created_at' },
{ key: 'updated_at' },
]}
onSelectRow={({ id }) => route(`users/${id}`)}
enableSearch
searchPlaceholder="Search email or phone"
searchPlaceholder="Search by ID, email or phone"
/>
</PageContent>
}