Skip to content

Commit

Permalink
Schedule unfeaturing listing in 7 days with Trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
DinerIsmail committed Oct 27, 2024
1 parent aa7a9eb commit 92c3534
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
12 changes: 0 additions & 12 deletions app/api/hello-world/route.ts

This file was deleted.

5 changes: 5 additions & 0 deletions app/api/listing/[id]/feature/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import prisma from '@prisma-rw'
import { unfeatureListingTask } from '@trigger/unfeature-listing'
import { tasks } from '@trigger.dev/sdk/v3'

Check warning on line 3 in app/api/listing/[id]/feature/route.ts

View workflow job for this annotation

GitHub Actions / test

'tasks' is defined but never used

export async function PATCH(_request, { params }) {
try {
Expand All @@ -13,6 +15,9 @@ export async function PATCH(_request, { params }) {
},
})

const handle = await unfeatureListingTask.trigger({ listingId })
console.log('[RW]Task is running with handle', handle.id)

return Response.json({
listing,
})
Expand Down
2 changes: 1 addition & 1 deletion hooks/listings/useFeatureListing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const featureListingRequest = async (id) => {
return listing
}

const unfeatureListingRequest = async (id) => {
export const unfeatureListingRequest = async (id) => {
const response = await fetch(`api/listing/${id}/unfeature`, {
method: 'PATCH',
})
Expand Down
15 changes: 0 additions & 15 deletions trigger/example.ts

This file was deleted.

22 changes: 22 additions & 0 deletions trigger/unfeature-listing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { logger, task, wait } from '@trigger.dev/sdk/v3'
import { REMOTE_URL } from '@helpers/config'

export const unfeatureListingTask = task({
id: 'unfeature-listing',
run: async (payload: any, { ctx }) => {
logger.log('Scheduling job to unfeature listing in 7 days', {
payload,
ctx,
})
const { listingId } = payload

await wait.for({ minutes: 1 })
await fetch(`${REMOTE_URL}/api/listing/${listingId}/unfeature`, {
method: 'PATCH',
})

return {
message: 'Hello, world!',
}
},
})

0 comments on commit 92c3534

Please sign in to comment.