Tuesday, 5 February 2019

How to architect a GraphQL app that needs to do background work?

I am working on a GraphQL backend (with Yoga) that needs to do some background work like fetching and parsing web pages and adding some of that data to the database. Some of the background work is tied to GraphQL mutations that can be called by the client, another chunk is tied to running on a set frequency (i.e. updating data that was last updated a week ago).I am currently triggering some of the background work with Bull by pushing a job onto a queue from inside the yoga mutation resolver. While this currently works, it doesn't feel idiomatic to be firing off a page crawl from inside what is essentially an unrelated function (the GraphQL resolver).Is there a better way to approach this? Possibly emitting an event when a mutation is called listening for the events elsewhere in the application?For functions that I need to run on a regular basis, what is the favorite way to schedule those?

Submitted February 05, 2019 at 04:05PM by VacantPlains

No comments:

Post a Comment