#Canceling jobs doesn't work using fetch

1 messages · Page 1 of 1 (latest)

mellow oracle
#

Hey, I have a problem with cancelling a job, my code looks like this:

if (reservation_data.trigger_dev_job_id) {
        const options = {
          method: 'POST',
          headers: {
            Authorization: 'Bearer token',
            'Content-Type': 'application/json',
          }
        };
        await fetch(`https://api.trigger.dev/api/v1/events/${ reservation_data.trigger_dev_job_id }/cancel`, options)
          .then(response => response.json())
          .then(response => console.log(response))
          .catch(err => console.error(err));
      }

Am I doing something wrong or any ideas?

fickle hearth
mellow oracle
#

I use deno in supabase edge function

fickle hearth
#

OK so you should be able to use our SDK inthere

#

I think so anyway, we support Deno now

#

But if you really want to use a fetch request:

  • Make sure your Authorization is Bearer ${your_server_api_key}
  • That you use the event.id that you get back when you call sendEvent.
#
//somewhere
const event = await client.sendEvent(....)

//your cancelling
  const options = {
    method: 'POST',
    headers: {
      Authorization: 'Bearer ${process.env.SERVER_TRIGGER_API_KEY}',
      'Content-Type': 'application/json',
    }
  };
  await fetch(`https://api.trigger.dev/api/v1/events/${event.id}/cancel`, options)
    .then(response => response.json())
    .then(response => console.log(response))
    .catch(err => console.error(err));
mellow oracle
#

i Will try to use sdk, but don't know how to import yet

#

I wonder which id I should put in the configuration:

export const clientTriggerDev = new TriggerClient({
  id: "",
  apiKey: 'token',
});
fickle hearth
#

The same as in your main app

mellow oracle
#

Something wrong

My code in deno:

import { TriggerClient } from "npm:@trigger.dev/sdk@latest";


export const clientTriggerDev = new TriggerClient({
  id: "...",
  apiKey: '...',
});

if (reservation_data.trigger_dev_job_id) {
  const response = await clientTriggerDev.cancelEvent(reservation_data.trigger_dev_job_id);     
 }

in the response variable gets all the data of the specified job, including the payload that I sent to it, but it is still being executed, it has not been canceled

fickle hearth
#

Does it say it's canceled in the UI in the dashboard?

fickle hearth
#

Can you drop me a link to the run?

mellow oracle
#

i sended in private message

fickle hearth
#

Ah crap, sorry I should have realised this earlier.

#

You need to use cancelRunsForEvent()

#

cancelEvent() stop the event from triggering runs. But it doesn't stop runs that have already started.

#

Should be a straight swap out

mellow oracle
#

Hmmm, still no cancellation
response ```{ cancelledRunIds: [], failedToCancelRunIds: [] }