mjackson/firework — pull request #4 by dusty (2014-09-09 13:35:01+00:00)
Title: Enhancement: track startedJobs state with priority

Let me know if you are interested in this idea and if so, if you see any faults in my implementation.

My goal was to track the state of jobs using priority. This makes it easier to build a web/script UI on top of firework that can show what jobs are running, failed, or completed, without having to loop through all the startedJobs. I also wanted to be able to add back the original priority when we retry a failed job.

This was implemented by adding a priority to the job based on its state. When the job is first started, we save the current priority from pendingJobs as the _priority attribute to re-use later.

Then we set the priority to 'running'. This is helpful if a SIGKILL stopped the process mid-work. So when we restart we can find the jobs that didn't finish.

When a job is completed successfully, its updated with a priority of 'completed'. This is useful if you just want to clear the completed jobs.

When a job fails, it is marked with a priority of 'failed'. By setting it as a priority, we can just use an equalTo() to track all the failed jobs, rather than a loop through all startedJobs.

I'm using setWithPriority on this, but we could also do an update followed by setPriority, if you think that makes more sense.

Do you see anything faulty in this logic?