Documentation
¶
Index ¶
- Constants
- Variables
- func CreateTable() error
- func DeleteTask(ID string) error
- func GetActiveTasks() (activeTasks *[]UserTask, err error)
- func GetFailedTasks() (failedTasks *[]UserTask, err error)
- func GetInactiveTasks() (inactiveTasks *[]UserTask, err error)
- func GetOnExecutionTasks() (onExecutionTasks *[]UserTask, err error)
- func GetTasks() (*[]UserTask, error)
- func Init()
- func InitDB(filepath string) (*sql.DB, error)
- func NewTask(task *UserTask) error
- func UpdateTask(ID string, updatedTask *UserTask) error
- func UpdateTaskState(ID string, newState TaskState) error
- type Event
- type EventType
- type TaskState
- type UserAction
- type UserArg
- type UserTask
- type UserTrigger
Constants ¶
const ( // DataPath is the path of the user SQLite database. DataPath string = "./data/" // DataFilename is the name of the SQLite file. DataFilename string = "tasks.db" )
Variables ¶
var BackupLoopState = false
BackupLoopState is the boolean variable used to show the state of the backup loop.
var DB *sql.DB
DB is the instance of the SQLite3 database used to store the user's tasks.
var ErrBackupLoopAlreadyActive = errors.New(
"Error: the backup loop is already active, new loop aborted",
)
ErrBackupLoopAlreadyActive is the error used when the backup loop was already started and is called to start again.
var ErrBadTaskID = errors.New("Invalid task ID: the task ID provided not exists " +
"in the user database.")
ErrBadTaskID is an error used when a task with specific ID is not found. in the JSON data file.
var ErrBadTaskName = errors.New("Invalid task name: the task name provided not exists " +
"in the user database.")
ErrBadTaskName is an error used when a task with specific name is not found. in the JSON data file.
var ErrNoFilenameAssigned = errors.New("No Filename: the filename of the data file was" +
" not assigned")
ErrNoFilenameAssigned is an error used when the name of the json data file was not setted.
var EventBus chan Event
EventBus is the channel used to transport the events related to the tasks.
Functions ¶
func CreateTable ¶
func CreateTable() error
CreateTable is the function that creates the table 'Tasks' into the SQLite3 database.
func DeleteTask ¶
DeleteTask is a function used to delete a specific task from the table 'Tasks', on the SQLite3 database.
func GetActiveTasks ¶
GetActiveTasks is a function that returns the tasks with the state `active` from the tasks database.
func GetFailedTasks ¶
GetFailedTasks is a function that returns the tasks with the state `failed` from the tasks database.
func GetInactiveTasks ¶
GetInactiveTasks is a function that returns the tasks with the state `inactive` from the tasks database.
func GetOnExecutionTasks ¶
GetOnExecutionTasks is a method of the UserData struct that returns the tasks with the state `on-execution`.
func GetTasks ¶
GetTasks is a func that returns all the user tasks from the table `Tasks`, from the SQLite3 database.
func Init ¶
func Init()
Init initializes the directory where the tasks will be stored (if not exists).
func NewTask ¶
NewTask is a function used to add a new task to the table 'Tasks', on the SQLite3 database.
func UpdateTask ¶
UpdateTask is a function used to update an existing task from the JSON data file.
func UpdateTaskState ¶
UpdateTaskState is a function used to change the state of a task.
Types ¶
type Event ¶
Event is the struct used to know which action must be executed by the engine with the given task.
type EventType ¶
type EventType uint8
EventType represents the different situations in which a task can be involved when the user data file has been modified.
type TaskState ¶
type TaskState string
TaskState is the type used to represent the different states of the tasks.
const ( // StateTaskFailed is a variable that can be used in the `State` // field of each task. This state represents a failed task. StateTaskFailed TaskState = "failed" // StateTaskOnExecution is a variable that can be used in the `State` // field of each task. This state represents a task currently on execution. StateTaskOnExecution TaskState = "on-execution" // StateTaskInactive is a variable that can be used in the `State` // field of each task. This state represents a deactivated/inactive task. StateTaskInactive TaskState = "inactive" // StateTaskActive is a variable that can be used in the `State` // field of each task. This state represents an active task. StateTaskActive TaskState = "active" )
type UserAction ¶
type UserAction struct {
ID string `json:"ID"`
Args []UserArg `json:"args"`
Timestamp string `json:"timestamp"`
Chained bool `json:"chained"`
ArgumentToReplaceByCR string `json:"argumentToReplaceByCR"`
Order uint8 `json:"order"`
}
UserAction is a struct for parsing every action
type UserTask ¶
type UserTask struct {
Name string `json:"name"`
State TaskState `json:"state"`
Trigger UserTrigger `json:"trigger"`
Actions []UserAction `json:"actions"`
Created time.Time `json:"created"`
LastTimeModified time.Time `json:"lastTimeModified"`
ID string `json:"ID"`
}
UserTask is a struct for parse each task.
func GetTaskByID ¶
GetTaskByID is a function that returns a specific task, searching it by the ID on the tasks database.
func GetTaskByName ¶
GetTaskByName is a function that returns a specific task, searching it by the name on the tasks database.
type UserTrigger ¶
type UserTrigger struct {
ID string `json:"ID"`
Args []UserArg `json:"args"`
Timestamp string `json:"timestamp"`
}
UserTrigger is a struct for parsing every trigger