Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(egh): Course Creation Sync Flow #350

Merged
merged 6 commits into from
Dec 17, 2024

Conversation

zacjones93
Copy link
Contributor

Implements the course creation workflow that syncs courses between builder, egghead-rails, and sanity:

  • Adds egghead/course-created event and handler
  • Creates new course in egghead-rails when a course post is created
  • Updates Sanity course creation to wait for Egghead course ID
  • Adds TypeScript schemas for egghead-rails database courses and instructors

gif

Co-authored-by: Creeland [email protected]

zacjones93 and others added 5 commits December 16, 2024 16:10
- Introduced a new event for course creation: `EGGHEAD_COURSE_CREATED_EVENT`.
- Added type definition for `EggheadCourseCreated` and its associated schema using Zod for validation.
- Updated the event types in `inngest.server.ts` to include the new course created event.

Co-authored-by: Creeland <[email protected]>
…dDbCourseSchema

- Changed the `id` field in `EggheadDbCourseSchema` from optional to required.
- Introduced a new `InstructorDbSchema` with comprehensive fields for instructor details, including `user_id`, `email`, and various optional attributes.
- Updated the `loadEggheadInstructorForUser` function to validate the instructor data using the new schema, ensuring robust error handling.

Co-authored-by: Creeland <[email protected]>
- Added the `createCourseInEgghead` function to handle course creation in Egghead.
- Integrated error handling for instructor retrieval and course creation.
- Emitted `EGGHEAD_COURSE_CREATED_EVENT` upon successful course creation.
- Updated the database to sync the created course ID with the corresponding post.

This enhancement improves the workflow for creating courses and ensures proper event handling and data synchronization.

Co-authored-by: Creeland <[email protected]>
- 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]>
@zacjones93 zacjones93 added the enhancement New feature or request label Dec 17, 2024
@zacjones93 zacjones93 requested a review from joelhooks December 17, 2024 18:06
Copy link

linear bot commented Dec 17, 2024

Copy link

vercel bot commented Dec 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ai-hero ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 8:45pm
astro-party ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 8:45pm
course-builder-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 8:45pm
course-builder-egghead ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 8:45pm
course-builder-poc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 8:45pm
course-builder-video-blog ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 8:45pm
epic-react-builder ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 8:45pm
epic-web-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 8:45pm
go-local-first ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 8:45pm
pro-aws ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 8:45pm
pro-nextjs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 8:45pm
value-based-design ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 8:45pm

Copy link
Collaborator

@joelhooks joelhooks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i approved but there are a lot of suggestions for a follow up

throw new NonRetriableError('Post not found')
}

if (post.fields?.postType !== 'course') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be part of the trigger instead of here which imo makes more sense than throwing errors when any other kind of post is created

const instructor = await loadEggheadInstructorForUser(post.createdById)

if (!instructor) {
return null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could throw the error instead of returning null and probably remove the need for the guard below

return course
})

step.sendEvent(EGGHEAD_COURSE_CREATED_EVENT, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind of weird to go through all of the above and then send this different event 🤔

})
}

const course = await step.run('create-course', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insider. among this eggheadCourse instead of just course because so many courses

@@ -39,22 +40,38 @@ export const createCourseInSanity = inngest.createFunction(
return contributor
})

const courseCreatedEvent = await step.waitForEvent(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not super stoked about the way these are connected together and think we might consider tightening it up or making the flow more obvious

this is the danger of event driven

entropy

@@ -40,6 +40,36 @@ export const getCachedEggheadInstructorForUser = unstable_cache(
{ revalidate: 3600, tags: ['users'] },
)

export const InstructorDbSchema = z.object({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the db here egghead? let's label it if so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants