lib/osc_machete_rails/statusable.rb
def update_status!(force: false)
      # this will make it easier to differentiate from current_status
      cached_status = status

      # by default only update if its an active job
      if  (cached_status.not_submitted? && pbsid) || cached_status.active? || force
        # get the current status from the system
        current_status = job.status

        # if job is done, lets re-validate
        if current_status.completed?
          current_status = results_valid? ? OSC::Machete::Status.passed : OSC::Machete::Status.failed
        end

        if (current_status != cached_status) || force
          self.status = current_status
          self.save
        end
      end

    rescue PBS::Error => e
      # we log the error but we just don't update the status
      Rails.logger.error("During update_status! call on job with pbsid #{pbsid} and id #{id}" \
                          " a PBS::Error was thrown: #{e.message}")
    end
def update_status!(force: false)
      # this will make it easier to differentiate from current_status
      cached_status = status

      # by default only update if its an active job
      if  (cached_status.not_submitted? && pbsid) || cached_status.active? || force
        # get the current status from the system
        current_status = job.status

        # if job is done, lets re-validate
        if current_status.completed?
          current_status = results_valid? ? OSC::Machete::Status.passed : OSC::Machete::Status.failed
        end

        if (current_status != cached_status) || force
          self.status = current_status
          self.save
        end
      end

    rescue PBS::Error => e
      # we log the error but we just don't update the status
      Rails.logger.error("During update_status! call on job with pbsid #{pbsid} and id #{id}" \
                          " a PBS::Error was thrown: #{e.message}")
    end
FIXME: should have a unit test for this!
 job.update_status! will update and save object
 if submitted? and ! completed? and status changed from previous state
 force will cause status to update regardless of completion status,
 redoing the validations. This way, if you are fixing validation methods
 you can use the Rails console to update the status of a Workflow by doing this:

     Container.last.jobs.each {|j| j.update_status!(force: true) }

 Or for a single statusable such as job:

     job.update_status!(force: true)

 FIXME: should log whether a validation method was called or
 throw a warning that no validation method was found (the one that would have been called)

 @param [Boolean, nil] force Force the update. (Default: false)