   * Regimen
     * ignore `end_time`.
     * ignore calendar.
-    * if schedule_time is more than 60 seconds passed due, assume it already scheduled, and don't schedule it again.
+    * if schedule_time is more than 60 seconds passed due, assume it already
+      scheduled, and don't schedule it again.
   * Sequence
     * if `schedule_time` is late, check the calendar.
-      * for each item in the calendar, check if it's event is more than 60 seconds in the past. if not, execute it.
+      * for each item in the calendar, check if it's event is more than
+        60 seconds in the past. if not, execute it.
     * if there is only one event in the calendar, ignore the `end_time`
   """
 

    finished? = Timex.after?(now, end_time)

    case mod do
      Regimen -> maybe_schedule_regimen(scheduled?, schedule_time, last_time, executable, now)
      Sequence -> maybe_schedule_sequence(scheduled?, finished?, f, last_time, executable, now)
    end
  end

  defp maybe_schedule_regimen(scheduled?, schedule_time, last_time, executable, now)

  defp maybe_schedule_regimen(true = _scheduled?, schedule_time, nil, regimen, _now) do
    maybe_farm_event_log("regimen #{regimen.name} (#{regimen.id}) scheduling.")
    process_via = Farmbot.Regimen.NameProvider.via(regimen)
    pid = GenServer.whereis(process_via)
    if pid, do: {nil, schedule_time}, else: {regimen, schedule_time}
  end

  defp maybe_schedule_regimen(true = _scheduled?, _schedule_time, last_time, event, _now) do
    maybe_farm_event_log("regimen #{event.name} (#{event.id}) should already be scheduled.")
    {nil, last_time}
  end

  defp maybe_schedule_regimen(false = _scheduled?, schedule_time, last_time, event, _) do
    maybe_farm_event_log(
      "regimen #{event.name} (#{event.id}) is not scheduled yet. (#{inspect(schedule_time)}) (#{
        inspect(Timex.now())
      })"
    )

    {nil, last_time}
  end

  defp lookup!(module, %FarmEvent{executable_id: exe_id, id: id}) when is_atom(module) do
    case module do
      Sequence ->
        Asset.get_sequence_by_id!(exe_id)

    # update state.
    new_state = %{
      state
      | last_time_index:
          Map.put(state.last_time_index, farm_event.id, last_time)
    }

    case new_late_executable do
