Support a Priority Queue
stellarpower opened this issue · 2 comments
Allow assigning an optional priority to jobs, using a simple algorithm for selecting jobs:
- Find the highest priority that has outstanding jobs to run
- Run the job that has been waiting the longest in this priority
- repeat
Given that the utility appears to be filesystem-based and has a shell implementation, I'd imagine a simple way to do this would be to change the NQDIR format to create sortable directories with the priority number; jobs then go into this with their timestamp. Using sort -n
(and whatever equivalent for C) should allow sorting of negative directories, such that a default priority of zero indicates no preference. Negative numbers could indicate lower priority (probably more intuitive) or higher priority (matches nice
/kernel)
I will try and fork and PR if I have time, but am adding this feature request in case I don't. If I do, I'll probably only be able to implement one version - either shell or C, if you'd be happy to reflect in the other if you want to add the feature at all.
I think this is out of scope for plain nq
, but you are free to fork this project of course.
Thanks for the feedback. I haven't been able to look back at this until today, and was planning to implement as a fork, however, I've been looking for projects for ages I could write in Crystal and this would be one, so may try that instead. I'll add the link in case anyone else is interested once I'm done.