updateJob = (state, task, type) => {
  switch (task.status) {
    case 'Init': {
      return {
        ...state,
        pending: [
          ...state.pending,
          {
            ...task,
            type,
            status: 'Pending',
            start: Date.now()
          }
        ]
      }
    }
    case 'Send': {
      const { pending, rest } = pullPending(state.pending, task)
      return {
        ...state,
        pending: [
          ...rest,
          {
            ...pending,
            ...task,
            status: 'Pending'
          }
        ]
      }
    }
    case 'Exit': {
      const { pending, rest } = pullPending(state.pending, task)

      if (task.result.ok) {
        return {
          ...state,
          pending: rest,
          finished: [
            ...state.finished,
            {
              ...pending,
              ...task,
              end: Date.now(),
              value: task.result.value,
              status: 'Done'
            }
          ]
        }
      } else {
        return {
          ...state,
          pending: rest,
          failed: [
            ...state.failed,
            {
              ...pending,
              ...task,
              end: Date.now(),
              error: task.result.error,
              status: 'Failed'
            }
          ]
        }
      }
    }
    default: {
      console.error('Task has an invalid state', task)
      return state
    }
  }
}
Updates state of the given job.
@param {Model} state
@param {JobState} task
@param {*} type
@returns {Model}