farmbot_os/lib/farmbot/system.ex

53 lines
1.3 KiB
Elixir
Raw Normal View History

2017-01-09 15:58:27 -07:00
defmodule Farmbot.System do
@moduledoc """
2017-08-10 00:38:42 -06:00
Common functionality that should be implemented by a system
2017-01-09 15:58:27 -07:00
"""
error_msg = """
Please configure your `:system_tasks` behaviour!
"""
2017-08-10 11:02:42 -06:00
@system_tasks Application.get_env(:farmbot, :behaviour)[:system_tasks] || Mix.raise error_msg
@typedoc "Reason for a task to execute. Should be human readable."
@type reason :: binary
@typedoc "Any ole data that caused a factory reset. Will try to format it as a human readable binary."
2017-08-10 12:51:57 -06:00
@type unparsed_reason :: term
@doc """
Should remove all persistant data. this includes:
* network config
* credentials
"""
@callback factory_reset(reason) :: no_return
@doc "Restarts the machine."
@callback reboot(reason) :: no_return
@doc "Shuts down the machine."
@callback shutdown(reason) :: no_return
#TODO(Connor) Format `unparsed_reason` into a human readable binary.
2017-08-10 11:02:42 -06:00
use Farmbot.DebugLog
@doc "Remove all configuration data, and reboot."
@spec factory_reset(unparsed_reason) :: no_return
2017-08-10 11:02:42 -06:00
def factory_reset(reason) do
2017-09-09 18:51:13 -06:00
@system_tasks.factory_reset(reason)
2017-08-10 11:02:42 -06:00
end
@doc "Reboot."
@spec reboot(unparsed_reason) :: no_return
2017-08-10 11:02:42 -06:00
def reboot(reason) do
@system_tasks.reboot(reason)
end
@doc "Shutdown."
@spec shutdown(unparsed_reason) :: no_return
2017-08-10 11:02:42 -06:00
def shutdown(reason) do
@system_tasks.shutdown(reason)
2017-09-18 18:23:10 -06:00
end
end