#Best Practices for Implementing Job Retrieval in a Serverless Architecture with Vercel and Python

1 messages · Page 1 of 1 (latest)

lean spruce
#

That's all that sendEvent in the SDK is doing

lean spruce
#

@desert fiber perhaps you could look at this, I'm on my phone and won't be back for a few hours

desert fiber
#

Unfortunately not around my laptop at the moment either

lean spruce
#

Are you setting a source when sending the event?

#

I think the issue might be that if you set the source you need to set the eventTrigger() to also use the same source. It defaults to "trigger.dev" if you leave it blank on both, which is probably what I'd recommend unless you want to send events from multiple places and filter them out using the source.

#

I think the problem with this event is that the source is blank, and I'm guessing you haven't set the source on eventTrigger to match that?

#

We should make this clearer in the docs

lean spruce
#

Yeah that event has a URL. The critical thing is that the Job has to have a matching source on it, otherwise the events will be filtered out and won't trigger any runs.

client.defineJob({
  id: "job-2",
  name: "Second job",
  version: "0.0.1",
  trigger: eventTrigger({
    name: "image.background.removal",
    //the source has to match the event you send, or you omit it in both (and it default to trigger.dev)
    source: "https://ds-b.......",
    schema: z.object({
      userId: z.string(),
      storeId: z.string(),
      //etc
    }),
  }),
  run: async (payload, io, ctx) => {
    //do stuff
  },
});
#

When we receive an event we check to see which Jobs match the event. We only trigger jobs where the name, source and filter all match the incoming event.

#

Yeah the source in the event you send has to match the eventTrigger

#

Most people just leave it off

#

The event has a source of https://ds-b... and is for the PROD environment.

The Job, from the last index which was a few mins ago, has this filter rule:

"trigger": {
  "rule": {
    "event": "image.background.removal",
    "source": "trigger.dev",
    "payload": {}
  },
  "type": "static",
  "title": "image.background.removal"
}
#

If you remove the source from the event you send does it work?

#

Yeah that looks correct. You deployed that to prod?

#

Yeah this event looks good. I really think the issue is the source. It seems like this might be a bug on our end with not passing the source from your eventTrigger through.

Is it possible for you to try sending the same event as above but with the source left off? (so it defaults to trigger.dev)

#

This is for the above event. It finds the Job but then the event doesn't match the filter.

#

Ok cool, sorry about this. It seems like it must be a bug in the source getting set in the db. I've looked at the code and it seems like it's passed through but there's quite a lot of steps.