What are ways to trigger a worker process in Heroku? In particular, a process that is needed infrequently but quickly when needed, eg bluemoon.js
.
Polling every second to read a task queue (which can be stored in a database) is the approach I can think of.
Trigger makes more sense to me for this case. Is there a way to directly trigger a worker process when needed? Or is there no real downside to frequent polling?
What you really want is a message queueing service like Amazon SQS , RabbitMQ , or something similar.
What message queueing services do is this:
The reason the above pattern works so well is that these services are optimized for speed and cost -- they're VERY inexpensive to run (I'm a huge fan of Amazon SQS myself), have almost no overhead, and are incredibly fast.
The reason you DON'T want to poll a database (which is what most people think of when they imagine stuff like this) is because it's going to waste resources and cause problems later on:
In general, for problems like this, a messaging service is the perfect solution!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.