Refactor cancel script so that the bulk of it is in a function.
Refactor cancel script so that the bulk of it is in a function.

This is in prep for it supporting bulk cancellation, which will
iteratively (and recursively) call this new function.

backupify/qless-core,seomoz/qless-core,seomoz/qless-core