Skip to content

Commit

Permalink
feat(egh): wait for course created event in sanity course sync
Browse files Browse the repository at this point in the history
- Imported `EGGHEAD_COURSE_CREATED_EVENT` to wait for course creation events from Egghead.
- Implemented error handling to throw a `NonRetriableError` if the course is not created.
- Mapped the `railsCourseId` to the newly created course ID and updated the `sharedId` to use the course's slug.
- Improved the overall workflow for course creation in Sanity by ensuring proper event synchronization.

Co-authored-by: Creeland <[email protected]>
  • Loading branch information
2 people authored and kodiakhq[bot] committed Dec 17, 2024
1 parent 40cafd3 commit f1473f5
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EGGHEAD_COURSE_CREATED_EVENT } from '@/inngest/events/egghead/course-created'
import { POST_CREATED_EVENT } from '@/inngest/events/post-created'
import { inngest } from '@/inngest/inngest.server'
import { SanityCourseSchema } from '@/lib/sanity-content'
Expand Down Expand Up @@ -39,22 +40,38 @@ export const createCourseInSanity = inngest.createFunction(
return contributor
})

const courseCreatedEvent = await step.waitForEvent(
`wait for course created in egghead-rails`,
{
event: EGGHEAD_COURSE_CREATED_EVENT,
timeout: '3 mins',
},
)

if (!courseCreatedEvent) {
throw new NonRetriableError('Course not created in egghead')
}

const courseId = courseCreatedEvent.data.id

const sanityCourse = await step.run('create-course', async () => {
const { fields } = post

const courseGuid = fields?.slug.split('~').pop()

const coursePayload = SanityCourseSchema.safeParse({
title: fields?.title,
slug: {
current: fields?.slug,
_type: 'slug',
},
description: fields?.body,
railsCourseId: fields?.railsCourseId,
collaborators: [contributor],
searchIndexingState: 'hidden',
accessLevel: 'pro',
productionProcessState: 'new',
sharedId: post.id,
sharedId: courseGuid,
railsCourseId: courseId,
})

if (!coursePayload.success) {
Expand Down

0 comments on commit f1473f5

Please sign in to comment.