This PR changes the completed and failed sets to be zsets. This allows us to efficiently get a subset of the completed or failed jobs, which is very useful for pagination on UIs, etc. Along with this PR there are also some refactoring, for instance I started to move the LUA scripts to separate files, which is much more cleaner and convenient than what we have today.