
Ask HN: General solution for pre-emptive background work scheduling - prmph
Here is scenario I hope the software architecture wonks on HN can help me with:<p>I want to execute a set of jobs with one background worker (or several). Whenever a job is done, a message is fired, and a listener on the main thread receives the message and stores some data in a cache.<p>So far this seems simple, but now I want pre-emptive scheduling from the main thread so I can, on demand, send a message to prioritize a specific job, so that it is done as soon as possible.<p>What is a general pattern for a clean solution to this problem?
======
cimmanom
Multiple queues - a general queue and a priority queue. You can either have
separate workers consuming the two queues, or have each worker check the
priority queue first and accept messages from the general queue only if the
priority queue is empty.

