Skip to content

feat: added the ability to cancel scheduled Events based on the event ID#332

Merged
ericallam merged 4 commits intotriggerdotdev:mainfrom
Chigala:feat/cancelEvent-function
Aug 21, 2023
Merged

feat: added the ability to cancel scheduled Events based on the event ID#332
ericallam merged 4 commits intotriggerdotdev:mainfrom
Chigala:feat/cancelEvent-function

Conversation

@Chigala
Copy link
Copy Markdown
Contributor

@Chigala Chigala commented Aug 14, 2023

Description

Added a function to cancel scheduled Events based on their ID.

Changes

  • added an API endpoint api.v1.events.$eventId.cancel.ts to update the cancelledAt column in the EventRecord table to the time the event was cancelled.
  • add a dequeue public function in the Zodworker class that handles removal of already scheduled jobs by calling the graphile_worker.remove_job SQL to remove the job.
  • Added a sendEvent function in the API Client class.

fixes #230
/claim #230

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Aug 14, 2023

⚠️ No Changeset found

Latest commit: 18a0282

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@algora-pbc algora-pbc bot mentioned this pull request Aug 14, 2023
@ericallam ericallam self-requested a review August 14, 2023 15:25
@ericallam
Copy link
Copy Markdown
Member

Thanks for this @Chigala, will be reviewing tomorrow 👍

@RamK777-stack
Copy link
Copy Markdown
Contributor

@Chigala I am curious to know, how you have tested sendEvent with some future date in the deliverAt key. because the job immediately runs for me. added my doubt in #230 (comment). please guide me on this.

@Chigala
Copy link
Copy Markdown
Contributor Author

Chigala commented Aug 14, 2023

Hello @RamK777-stack I believe @ericallam has already answered you. You weren't calling the sendEvent function correctly. That's why the job was running immediately.

Copy link
Copy Markdown
Member

@ericallam ericallam left a comment

Choose a reason for hiding this comment

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

Looks pretty close! Can you also add a cancelEvent method to the IO class, similar to sendEvent:

async sendEvent(key: string | any[], event: SendEvent, options?: SendEventOptions) {

return json({ error: "Event not found" }, { status: 404 });
}

//update the cancelledAt column in the eventRecord table
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Chigala
Copy link
Copy Markdown
Contributor Author

Chigala commented Aug 16, 2023

Looks pretty close! Can you also add a cancelEvent method to the IO class, similar to sendEvent:

async sendEvent(key: string | any[], event: SendEvent, options?: SendEventOptions) {

Yeah, I realised I had to add that too when I saw your code snippet on Discord. I'll implement it.

@matt-aitken matt-aitken requested a review from ericallam August 18, 2023 12:00
Copy link
Copy Markdown
Member

@ericallam ericallam left a comment

Choose a reason for hiding this comment

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

A few more requested changes. One other thing is this should be updated to check to make sure the event cancelledAt is not set. If it is set, it should just return:

https://github.com/triggerdotdev/trigger.dev/blob/improvements/job-run-performance/apps/webapp/app/services/events/deliverEvent.server.ts

@ericallam ericallam merged commit b9dc7ce into triggerdotdev:main Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cancel scheduled events

3 participants