Skip to content

Commit

Permalink
Remove unused exported functions
Browse files Browse the repository at this point in the history
  • Loading branch information
r4ulcl committed Dec 29, 2024
1 parent 498dac5 commit d1cae30
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 50 deletions.
38 changes: 19 additions & 19 deletions manager/database/DBtask.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func GetTasks(r *http.Request, db *sql.DB, verbose, debug bool) ([]globalstructs
}

// Fetch tasks using the constructed SQL query
return GetTasksSQL(sql, args, db, verbose, debug)
return getTasksSQL(sql, args, db, verbose, debug)
}

func getPage(queryParams url.Values) int {
Expand All @@ -211,18 +211,18 @@ func getLimit(queryParams url.Values) int {
// GetTasksPending Get Tasks with status = Pending
func GetTasksPending(limit int, db *sql.DB, verbose, debug bool) ([]globalstructs.Task, error) {
sql := "SELECT ID, notes, commands, files, name, createdAt, updatedAt, executedAt, status, WorkerName, username, priority, timeout, callbackURL, callbackToken FROM task WHERE status = 'pending' ORDER BY priority DESC, createdAt ASC LIMIT ?"
return GetTasksSQL(sql, []interface{}{limit}, db, verbose, debug)
return getTasksSQL(sql, []interface{}{limit}, db, verbose, debug)
}

// GetTasksSQL executes a parameterized SQL query to fetch tasks.
func GetTasksSQL(sqlQuery string, args []interface{}, db *sql.DB, verbose, debug bool) ([]globalstructs.Task, error) {
// getTasksSQL executes a parameterized SQL query to fetch tasks.
func getTasksSQL(sqlQuery string, args []interface{}, db *sql.DB, verbose, debug bool) ([]globalstructs.Task, error) {
var tasks []globalstructs.Task

// Execute the parameterized query
rows, err := db.Query(sqlQuery, args...)
if err != nil {
if debug {
log.Println("DB Error DBTask GetTasksSQL:", sqlQuery, err)
log.Println("DB Error DBTask getTasksSQL:", sqlQuery, err)
}
return tasks, err
}
Expand All @@ -242,7 +242,7 @@ func GetTasksSQL(sqlQuery string, args []interface{}, db *sql.DB, verbose, debug
)
if err != nil {
if debug {
log.Println("DB Error DBTask GetTasksSQL: Row Scan", err)
log.Println("DB Error DBTask getTasksSQL: Row Scan", err)
}
return tasks, err
}
Expand All @@ -262,7 +262,7 @@ func GetTasksSQL(sqlQuery string, args []interface{}, db *sql.DB, verbose, debug
// Check for errors during row iteration
if err := rows.Err(); err != nil {
if debug {
log.Println("DB Error DBTask GetTasksSQL: Rows Iteration", err)
log.Println("DB Error DBTask getTasksSQL: Rows Iteration", err)
}
return tasks, err
}
Expand Down Expand Up @@ -330,15 +330,15 @@ func GetTask(db *sql.DB, id string, verbose, debug bool) (globalstructs.Task, er
return task, nil
}

// GetTaskExecutedAt Get Task ExecutedAt by id
func GetTaskExecutedAt(db *sql.DB, id string, verbose, debug bool) (string, error) {
// getTaskExecutedAt Get Task ExecutedAt by id
func getTaskExecutedAt(db *sql.DB, id string, verbose, debug bool) (string, error) {
// Retrieve the workerName from the task table
var executedAt string
err := db.QueryRow("SELECT executedAt FROM task WHERE ID = ?",
id).Scan(&executedAt)
if err != nil {
if debug {
log.Println("DB Error DBTask GetTaskExecutedAt: ", err)
log.Println("DB Error DBTask getTaskExecutedAt: ", err)
}
return executedAt, err
}
Expand All @@ -347,45 +347,45 @@ func GetTaskExecutedAt(db *sql.DB, id string, verbose, debug bool) (string, erro
}

/*
// GetTaskWorker gets task workerName from an ID
// getTaskWorker gets task workerName from an ID
// This is the worker executing the task
func GetTaskWorker(db *sql.DB, id string, verbose, debug bool) (string, error) {
func getTaskWorker(db *sql.DB, id string, verbose, debug bool) (string, error) {
// Retrieve the workerName from the task table
var workerName string
err := db.QueryRow("SELECT WorkerName FROM task WHERE ID = ?",
id).Scan(&workerName)
if err != nil {
if debug {
log.Println("DB Error DBTask GetTaskWorker: ", err)
log.Println("DB Error DBTask getTaskWorker: ", err)
}
return workerName, err
}
return workerName, nil
}
// SetTasksWorkerFailed set to failed all task running worker workerName
func SetTasksWorkerFailed(db *sql.DB, workerName string, verbose, debug bool, wg *sync.WaitGroup) error {
// setTasksWorkerFailed set to failed all task running worker workerName
func setTasksWorkerFailed(db *sql.DB, workerName string, verbose, debug bool, wg *sync.WaitGroup) error {
defer wg.Done()
wg.Add(1)
_, err := db.Exec("UPDATE task SET status = 'failed' WHERE workerName = ? AND status = 'running' ", workerName)
if err != nil {
if debug {
log.Println("DB Error DBTask SetTasksWorkerFailed: ", err)
log.Println("DB Error DBTask setTasksWorkerFailed: ", err)
}
return err
}
return nil
}
// SetTasksWorkerInvalid set to invalid all task running worker workerName
func SetTasksWorkerInvalid(db *sql.DB, workerName string, verbose, debug bool, wg *sync.WaitGroup) error {
// setTasksWorkerInvalid set to invalid all task running worker workerName
func setTasksWorkerInvalid(db *sql.DB, workerName string, verbose, debug bool, wg *sync.WaitGroup) error {
defer wg.Done()
wg.Add(1)
_, err := db.Exec("UPDATE task SET status = 'invalid' WHERE workerName = ? AND status = 'running' ", workerName)
if err != nil {
if debug {
log.Println("DB Error DBTask SetTasksWorkerInvalid: ", err)
log.Println("DB Error DBTask setTasksWorkerInvalid: ", err)
}
return err
}
Expand Down
33 changes: 7 additions & 26 deletions manager/database/DBworkers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func RmWorkerName(db *sql.DB, name string, verbose, debug bool, wg *sync.WaitGro
// GetWorkers retrieves all workers from the database.
func GetWorkers(db *sql.DB, verbose, debug bool) ([]globalstructs.Worker, error) {
sql := "SELECT name, defaultThreads, iddleThreads, up, downCount FROM worker;"
return GetWorkerSQL(sql, db, verbose, debug)
return getWorkerSQL(sql, db, verbose, debug)
}

// GetWorker retrieves a worker from the database by its name.
Expand Down Expand Up @@ -145,17 +145,17 @@ func SetIddleThreadsTo(IddleThreads int, db *sql.DB, worker string, verbose, deb
// GetWorkerIddle retrieves all workers that are iddle.
func GetWorkerIddle(db *sql.DB, verbose, debug bool) ([]globalstructs.Worker, error) {
sql := "SELECT name, defaultThreads, iddleThreads, up, downCount FROM worker WHERE up = true AND IddleThreads > 0 ORDER BY RAND();"
return GetWorkerSQL(sql, db, verbose, debug)
return getWorkerSQL(sql, db, verbose, debug)
}

// GetWorkerUP retrieves all workers that are up.
func GetWorkerUP(db *sql.DB, verbose, debug bool) ([]globalstructs.Worker, error) {
// getWorkerUP retrieves all workers that are up.
func getWorkerUP(db *sql.DB, verbose, debug bool) ([]globalstructs.Worker, error) {
sql := "SELECT name, defaultThreads, iddleThreads, up, downCount FROM worker WHERE up = true;"
return GetWorkerSQL(sql, db, verbose, debug)
return getWorkerSQL(sql, db, verbose, debug)
}

// GetWorkerSQL retrieves workers information based on a SQL statement.
func GetWorkerSQL(sql string, db *sql.DB, verbose, debug bool) ([]globalstructs.Worker, error) {
// getWorkerSQL retrieves workers information based on a SQL statement.
func getWorkerSQL(sql string, db *sql.DB, verbose, debug bool) ([]globalstructs.Worker, error) {
// Slice to store all workers
var workers []globalstructs.Worker

Expand Down Expand Up @@ -294,25 +294,6 @@ func GetDownCount(db *sql.DB, verbose, debug bool) (int, error) {
return count, nil
}

/*
// AddWorkerIddleThreads1 sets the status of a worker to the specified working value using the worker's name.
func AddWorkerIddleThreads2222(db *sql.DB, worker string, verbose, debug bool, wg *sync.WaitGroup) error {
defer wg.Done()
wg.Add(1)
if debug {
log.Println("DB AddWorkerIddleThreads1 worker name:", worker)
}
_, err := db.Exec("UPDATE worker SET IddleThreads = IddleThreads + 1 WHERE name = ?;",
worker)
if err != nil {
if debug {
log.Println("DB Error DBworkers: ", err)
}
return err
}
return nil
}*/

// SubtractWorkerIddleThreads1 Subtract WorkerIddleThreads 1 if >0
func SubtractWorkerIddleThreads1(db *sql.DB, worker string, verbose, debug bool, wg *sync.WaitGroup) error {
defer wg.Done()
Expand Down
10 changes: 5 additions & 5 deletions worker/managerrequest/managerRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func SendMessage(conn *websocket.Conn, message []byte, verbose, debug bool, writ
return nil
}

// SendWebSocketMessage is a helper function to send a WebSocket message to the manager
func SendWebSocketMessage(config *utils.WorkerConfig, messageType string, payload interface{}, verbose, debug bool, writeLock *sync.Mutex) error {
// sendWebSocketMessage is a helper function to send a WebSocket message to the manager
func sendWebSocketMessage(config *utils.WorkerConfig, messageType string, payload interface{}, verbose, debug bool, writeLock *sync.Mutex) error {
// Marshal the payload into JSON
payloadData, err := json.Marshal(payload)
if err != nil {
Expand Down Expand Up @@ -113,7 +113,7 @@ func AddWorker(config *utils.WorkerConfig, verbose, debug bool, writeLock *sync.
DownCount: 0,
}

return SendWebSocketMessage(config, "addWorker", worker, verbose, debug, writeLock)
return sendWebSocketMessage(config, "addWorker", worker, verbose, debug, writeLock)
}

// DeleteWorker sends a POST request to delete a worker from the manager
Expand All @@ -125,10 +125,10 @@ func DeleteWorker(config *utils.WorkerConfig, verbose, debug bool, writeLock *sy
DownCount: 0,
}

return SendWebSocketMessage(config, "deleteWorker", worker, verbose, debug, writeLock)
return sendWebSocketMessage(config, "deleteWorker", worker, verbose, debug, writeLock)
}

// CallbackTaskMessage sends a POST request to the manager with a task message
func CallbackTaskMessage(config *utils.WorkerConfig, task *globalstructs.Task, verbose, debug bool, writeLock *sync.Mutex) error {
return SendWebSocketMessage(config, "callbackTask", task, verbose, debug, writeLock)
return sendWebSocketMessage(config, "callbackTask", task, verbose, debug, writeLock)
}

0 comments on commit d1cae30

Please sign in to comment.