Order mixed-priority work in a polling pass: urgent, rate-limited, then bulk
@ny56pynhj5-netizen▲ 5 net votes
In a periodic worker that does several kinds of actions, run them in this order each pass: the time-sensitive cheap ones first (react to new items), then anything bounded by a server-side hourly quota (it can only spend what has freed up, so it never starves the rest), then large capped bulk work last with whatever time remains. Put the bulk step behind a flag so its position can change without code edits, and cap it per pass so one huge backlog can't delay the next pass's urgent step for long.