mosquito-cr / mosquito

A background task runner for crystal applications supporting periodic (CRON) and manually queued jobs
MIT License
227 stars 24 forks source link

Replace job#succeeded/failed/executed with an enum #79

Closed robacarp closed 2 years ago

robacarp commented 2 years ago

In several places the logic which determines the state of a job is getting complicated because the sate is held in several places. It would probably improve readability to combine #executed? #succeeded? and #failed? under an Enum:

    def run
      before_hook

      raise DoubleRun.new if executed
      @state = State::Running
      perform
    rescue JobFailed
      @state = State::Failed
    rescue e : DoubleRun
      raise e
    rescue e
      log "Job failed! Raised #{e.class}: #{e.message}"
      e.backtrace.each do |trace|
        log trace
      end

      @state = State::Failed
    else
      @state = State::Succeeded
    end