Shopify Remix App - Webhooks/CRON Jobs

Shopify Remix App - Webhooks/CRON Jobs

AyoDyln
Shopify Partner
2 0 2

Hello 😁

I'm working on my first Shopify Application using the Remix framework. My application has some needs that are pushing it into SaaS territory. I need to have logic that would be triggered in desired intervals of time, so a CRON Job is needed on some level.

For context, I'm pretty new still to Shopify App development and trying to gain an understanding of the architecture still. I know Web-hooks are subscription based, however are only triggered IF a pre-designated Shopify Shop event is occurring (e.g, "product update"). For the CRON job issue, I've discovered that Remix App doesn't offer any CRON job features out of the box and all my other research is telling me that I would need to create or have an external CRON Job service, which is okay.

I just need assistance in figuring out how to have a CRON Job send a request to my Shopify App (I'm unsure if this is sent to just my App on a hosting provider or to every instance of the app on Shopify stores). 

What are some solutions I could do to enable this behavior? Essentially, I need to have events triggered at specific times and update a Shops product info. In my head, I feel like having a CRON job send a request and have a Web-hook listen for that custom event and do something with it.

Any information would be greatly appreciated, I'm excited to learn more. 

Thank you 😊


Replies 2 (2)

UncleBabyKern
Shopify Partner
5 0 3

I'm looking into the same thing and thought I'd share about https://trigger.dev/ which I've just begun reading about. If you're not using TypeScript I'll just mention that TS can be adopted incrementally so you wouldn't have to commit to it everywhere in your app. 

 

Have you learned anything else on your own since posting, @AyoDyln?

I'm still unsure if it would be wiser to maintain an isolated app to run cron jobs, and I'm tempted to write it into my shopify-remix app. Trigger seems to make a case for fearlessly writing it into 1 app.

AyoDyln
Shopify Partner
2 0 2

@UncleBabyKern, I'm unsure if I for sure have the correct answer yet. Since work is having me jump between projects. But, from my research I've done so far, I found this information. Typescript isn't an issue. 

Shopify Apps are embedded onto the Admin page, so essentially you're running a web app. Meaning, our Shopify Apps are developed and hosted (by a Shopify recommended provider) and then being accessed with an Iframe and OAuth. So, this means the following:

  • Our apps are hosted on a server
  • Remix apps have route configuration for client and server side
  • Shopify Webhooks/Events are only triggered by Shopify, integrating them into an automated architecture with cron jobs that are dependent of data in your database doesn't really seem to be a good fit. From at least what I found, I can't find a way to make a custom web hook that sends an event to the Shopify server from a CRON job for example. 
  • Since our Apps are hosted on a Server and has a public URL during development/Production, there are routes we can configure to be available outside of a Shopify App iframe environment
  • Remix API Routing that can be configured with your desired amount of security involved (e.g., cors). 
    • Meaning, we can have CRON jobs running and every interval, trigger and send a HTTPS req to your Apps API route and then that route would conduct any logical operations that is needed. 
    • There are free CRON job solutions out there to used to start out on for development and maybe even a small group of users.
    • Eventually, as the application scales, better CRON job solutions and optimal multitenancy database architecture is required. 

 

I still have yet to employ all this in my project, but I'm pretty confident in this route because I've tried everything I could think of and researched endlessly for info. My recommendation is looking into what I mentioned above but also avoid over complication as much as possible. Whiteboard everything out, if you haven't yet. For myself, tracking all this information, Shopify's App architecture, and all the dependencies get overwhelming. 

I hope this was helpful 😊