data

package
v0.1.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var BackupLoopState = false

BackupLoopState is the boolean variable used to show the state of the backup loop.

View Source
var DB *sql.DB

DB is the instance of the SQLite3 database used to store the user's tasks.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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

func DeleteTask(ID string) error

DeleteTask is a function used to delete a specific task from the table 'Tasks', on the SQLite3 database.

func GetActiveTasks

func GetActiveTasks() (activeTasks *[]UserTask, err error)

GetActiveTasks is a function that returns the tasks with the state `active` from the tasks database.

func GetFailedTasks

func GetFailedTasks() (failedTasks *[]UserTask, err error)

GetFailedTasks is a function that returns the tasks with the state `failed` from the tasks database.

func GetInactiveTasks

func GetInactiveTasks() (inactiveTasks *[]UserTask, err error)

GetInactiveTasks is a function that returns the tasks with the state `inactive` from the tasks database.

func GetOnExecutionTasks

func GetOnExecutionTasks() (onExecutionTasks *[]UserTask, err error)

GetOnExecutionTasks is a method of the UserData struct that returns the tasks with the state `on-execution`.

func GetTasks

func GetTasks() (*[]UserTask, error)

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 InitDB

func InitDB(filepath string) (*sql.DB, error)

InitDB is the function used to initialize the SQLite3 database.

func NewTask

func NewTask(task *UserTask) error

NewTask is a function used to add a new task to the table 'Tasks', on the SQLite3 database.

func UpdateTask

func UpdateTask(ID string, updatedTask *UserTask) error

UpdateTask is a function used to update an existing task from the JSON data file.

func UpdateTaskState

func UpdateTaskState(ID string, newState TaskState) error

UpdateTaskState is a function used to change the state of a task.

Types

type Event

type Event struct {
	Type   EventType
	TaskID string
}

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.

const (
	// Modified represents a task that has variated some of its fields.
	Modified EventType = iota
	// Deleted represents a task that has been removed.
	Deleted
	// Added represents a new task.
	Added
	// Failed represents a task that failed during execution.
	Failed
)

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 UserArg

type UserArg struct {
	ID      string `json:"ID"`
	Content string `json:"content"`
}

UserArg is a struct for arg parsing

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

func GetTaskByID(ID string) (taskFound *UserTask, err error)

GetTaskByID is a function that returns a specific task, searching it by the ID on the tasks database.

func GetTaskByName

func GetTaskByName(name string) (taskFound *UserTask, err error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL