Refactor imports and clean up whitespace in API and runner client files. Update auth package references to use the new package structure. Improve mutex usage in the runner client for better concurrency handling.
This commit is contained in:
@@ -7,8 +7,6 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"fuego/internal/auth"
|
||||
"fuego/pkg/types"
|
||||
)
|
||||
|
||||
@@ -39,9 +37,9 @@ func (s *Server) handleGenerateRegistrationToken(w http.ResponseWriter, r *http.
|
||||
}
|
||||
|
||||
s.respondJSON(w, http.StatusCreated, map[string]interface{}{
|
||||
"token": token,
|
||||
"expires_in": expiresIn.String(),
|
||||
"expires_at": time.Now().Add(expiresIn),
|
||||
"token": token,
|
||||
"expires_in": expiresIn.String(),
|
||||
"expires_at": time.Now().Add(expiresIn),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -169,4 +167,3 @@ func (s *Server) handleListRunnersAdmin(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
s.respondJSON(w, http.StatusOK, runners)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,35 +10,36 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
authpkg "fuego/internal/auth"
|
||||
"fuego/internal/database"
|
||||
"fuego/internal/storage"
|
||||
"fuego/pkg/types"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/go-chi/cors"
|
||||
"github.com/gorilla/websocket"
|
||||
"fuego/internal/auth"
|
||||
"fuego/internal/database"
|
||||
"fuego/internal/storage"
|
||||
"fuego/pkg/types"
|
||||
)
|
||||
|
||||
// Server represents the API server
|
||||
type Server struct {
|
||||
db *database.DB
|
||||
auth *auth.Auth
|
||||
secrets *auth.Secrets
|
||||
auth *authpkg.Auth
|
||||
secrets *authpkg.Secrets
|
||||
storage *storage.Storage
|
||||
router *chi.Mux
|
||||
|
||||
// WebSocket connections
|
||||
wsUpgrader websocket.Upgrader
|
||||
runnerConns map[int64]*websocket.Conn
|
||||
runnerConnsMu sync.RWMutex
|
||||
frontendConns map[string]*websocket.Conn // key: "jobId:taskId"
|
||||
wsUpgrader websocket.Upgrader
|
||||
runnerConns map[int64]*websocket.Conn
|
||||
runnerConnsMu sync.RWMutex
|
||||
frontendConns map[string]*websocket.Conn // key: "jobId:taskId"
|
||||
frontendConnsMu sync.RWMutex
|
||||
}
|
||||
|
||||
// NewServer creates a new API server
|
||||
func NewServer(db *database.DB, auth *auth.Auth, storage *storage.Storage) (*Server, error) {
|
||||
secrets, err := auth.NewSecrets(db.DB)
|
||||
func NewServer(db *database.DB, auth *authpkg.Auth, storage *storage.Storage) (*Server, error) {
|
||||
secrets, err := authpkg.NewSecrets(db.DB)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize secrets: %w", err)
|
||||
}
|
||||
@@ -290,7 +291,7 @@ func (s *Server) handleGetMe(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Helper to get user ID from context
|
||||
func getUserID(r *http.Request) (int64, error) {
|
||||
userID, ok := auth.GetUserID(r.Context())
|
||||
userID, ok := authpkg.GetUserID(r.Context())
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("user ID not found in context")
|
||||
}
|
||||
@@ -510,4 +511,3 @@ func (s *Server) recoverTaskTimeouts() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"fuego/pkg/types"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
// Client represents a runner client
|
||||
@@ -35,7 +36,7 @@ type Client struct {
|
||||
runnerSecret string
|
||||
managerSecret string
|
||||
wsConn *websocket.Conn
|
||||
wsConnMu sync.Mutex
|
||||
wsConnMu sync.RWMutex
|
||||
stopChan chan struct{}
|
||||
}
|
||||
|
||||
@@ -268,8 +269,8 @@ func (c *Client) handleTaskAssignment(msg map[string]interface{}) {
|
||||
|
||||
// Convert to task map format
|
||||
taskMap := map[string]interface{}{
|
||||
"id": taskID,
|
||||
"job_id": jobID,
|
||||
"id": taskID,
|
||||
"job_id": jobID,
|
||||
"frame_start": frameStart,
|
||||
"frame_end": frameEnd,
|
||||
}
|
||||
@@ -813,4 +814,3 @@ func (c *Client) sendTaskComplete(taskID int64, outputPath string, success bool,
|
||||
}
|
||||
return fmt.Errorf("WebSocket not connected, cannot complete task")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user