worker

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

internal/worker/theme_manager.go

internal/worker/pool.go

internal/worker/slidev.go

internal/worker/worker.go

internal/worker/workspace.go - Updated with permission handling

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExportOptions

type ExportOptions struct {
	Format     string // pdf, png, md
	Output     string // Fichier de sortie
	WithClicks bool   // Inclure les animations de click
	Range      string // Pages à exporter (ex: "1-10")
}

ExportOptions contient les options d'export

type JobProcessor

type JobProcessor struct {
	// contains filtered or unexported fields
}

JobProcessor traite les jobs de génération

func NewJobProcessor

func NewJobProcessor(
	jobService jobs.JobService,
	storageService *storage.StorageService,
	config *PoolConfig,
) *JobProcessor

NewJobProcessor crée un nouveau processeur de jobs

func (*JobProcessor) ProcessJob

func (p *JobProcessor) ProcessJob(ctx context.Context, job *models.GenerationJob) *JobResult

ProcessJob traite un job de génération complet avec debug amélioré

type JobResult

type JobResult struct {
	Success   bool
	Error     error
	Duration  time.Duration
	Progress  int
	LogOutput []string
}

JobResult contient le résultat du traitement d'un job

type NpmPackageManager added in v0.0.4

type NpmPackageManager struct {
	// contains filtered or unexported fields
}

NpmPackageManager gère l'installation des paquets Npm

func NewNpmPackageManager added in v0.0.4

func NewNpmPackageManager(workspaceBase string) *NpmPackageManager

NewNpmPackageManager crée un nouveau gestionnaire de thèmes

func (*NpmPackageManager) AutoInstallNpmPackages added in v0.0.4

func (tm *NpmPackageManager) AutoInstallNpmPackages(ctx context.Context, workspace *Workspace) ([]*models.NpmPackageInstallResult, error)

AutoInstallNpmPackages installe automatiquement les thèmes manquants - VERSION ROBUSTE

func (*NpmPackageManager) InstallNpmPackage added in v0.0.4

func (tm *NpmPackageManager) InstallNpmPackage(ctx context.Context, workspace *Workspace, npmPackage string) (*models.NpmPackageInstallResult, error)

InstallNpmPackage installe un paquet NPM

func (*NpmPackageManager) NpmInstall added in v0.0.4

func (tm *NpmPackageManager) NpmInstall(ctx context.Context, workspace *Workspace) error

type PoolConfig

type PoolConfig struct {
	WorkerCount      int           // Nombre de workers simultanés
	PollInterval     time.Duration // Intervalle de polling des jobs
	JobTimeout       time.Duration // Timeout par job
	WorkspaceBase    string        // Répertoire de base pour les workspaces
	SlidevCommand    string        // Commande Slidev (par défaut "npx @slidev/cli")
	CleanupWorkspace bool          // Nettoyer les workspaces après traitement
}

PoolConfig contient la configuration du pool de workers

func DefaultPoolConfig

func DefaultPoolConfig() *PoolConfig

DefaultPoolConfig retourne une configuration par défaut avec chemin sécurisé

type PoolStats

type PoolStats struct {
	WorkerCount   int           `json:"worker_count"`
	QueueSize     int           `json:"queue_size"`
	QueueCapacity int           `json:"queue_capacity"`
	Running       bool          `json:"running"`
	Workers       []WorkerStats `json:"workers"`
}

PoolStats contient les statistiques du pool

type SlidevBuildOptions

type SlidevBuildOptions struct {
	Output  string            // Répertoire de sortie (par défaut: dist)
	Base    string            // Base URL
	Options map[string]string // Options additionnelles
	Export  *ExportOptions    // Options d'export (PDF, etc.)
}

SlidevBuildOptions contient les options pour la build Slidev

type SlidevResult

type SlidevResult struct {
	Success    bool
	ExitCode   int
	Logs       []string
	Duration   time.Duration
	OutputPath string
}

SlidevResult contient le résultat de l'exécution Slidev

type SlidevRunner

type SlidevRunner struct {
	// contains filtered or unexported fields
}

SlidevRunner exécute les commandes Slidev

func NewSlidevRunner

func NewSlidevRunner(config *PoolConfig) *SlidevRunner

NewSlidevRunner crée un nouveau runner Slidev

func (*SlidevRunner) Build

func (sr *SlidevRunner) Build(ctx context.Context, workspace *Workspace, job *models.GenerationJob) (*SlidevResult, error)

Build exécute `slidev build` dans le workspace avec validation améliorée

func (*SlidevRunner) BuildWithOptions

func (sr *SlidevRunner) BuildWithOptions(ctx context.Context, workspace *Workspace, job *models.GenerationJob, options *SlidevBuildOptions) (*SlidevResult, error)

BuildWithOptions exécute Slidev build avec des options spécifiques

func (*SlidevRunner) CheckDependencies

func (sr *SlidevRunner) CheckDependencies(ctx context.Context) error

CheckDependencies vérifie que toutes les dépendances nécessaires sont disponibles

func (*SlidevRunner) ExportToPDF

func (sr *SlidevRunner) ExportToPDF(ctx context.Context, workspace *Workspace, job *models.GenerationJob, outputFile string) error

ExportToPDF exporte la présentation en PDF

func (*SlidevRunner) GetBuildInfo

func (sr *SlidevRunner) GetBuildInfo() map[string]interface{}

GetBuildInfo retourne des informations sur la build

func (*SlidevRunner) GetSlidevVersion

func (sr *SlidevRunner) GetSlidevVersion(ctx context.Context) (string, error)

GetSlidevVersion retourne la version de Slidev installée

func (*SlidevRunner) InstallDependencies

func (sr *SlidevRunner) InstallDependencies(ctx context.Context, workspace *Workspace) error

InstallDependencies installe les dépendances si un package.json est présent

func (*SlidevRunner) InstallNpmPackages added in v0.0.4

func (sr *SlidevRunner) InstallNpmPackages(ctx context.Context, workspace *Workspace, job *models.GenerationJob) error

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker représente un worker individuel qui traite les jobs

func NewWorker

func NewWorker(
	id int,
	jobService jobs.JobService,
	storageService *storage.StorageService,
	config *PoolConfig,
) *Worker

NewWorker crée un nouveau worker

func (*Worker) GetStats

func (w *Worker) GetStats() WorkerStatsInternal

GetStats retourne les statistiques du worker - VERSION CORRIGÉE

func (*Worker) Start

func (w *Worker) Start(ctx context.Context, jobQueue <-chan *models.GenerationJob)

Start démarre le worker et écoute la queue des jobs

type WorkerPool

type WorkerPool struct {
	// contains filtered or unexported fields
}

WorkerPool gère un pool de workers pour traiter les jobs de génération

func NewWorkerPool

func NewWorkerPool(
	jobService jobs.JobService,
	storageService *storage.StorageService,
	config *PoolConfig,
) *WorkerPool

NewWorkerPool crée un nouveau pool de workers

func (*WorkerPool) GetConfig

func (p *WorkerPool) GetConfig() *PoolConfig

func (*WorkerPool) GetStats

func (p *WorkerPool) GetStats() PoolStats

GetStats retourne les statistiques du pool

func (*WorkerPool) Start

func (p *WorkerPool) Start(ctx context.Context) error

Start démarre le pool de workers

func (*WorkerPool) Stop

func (p *WorkerPool) Stop() error

Stop arrête le pool de workers

type WorkerStats

type WorkerStats struct {
	ID           int    `json:"id"`
	Status       string `json:"status"` // idle, busy, stopped
	CurrentJobID string `json:"current_job_id,omitempty"`
	JobsTotal    int64  `json:"jobs_total"`
	JobsSuccess  int64  `json:"jobs_success"`
	JobsFailed   int64  `json:"jobs_failed"`
}

WorkerStats contient les statistiques d'un worker

type WorkerStatsInternal

type WorkerStatsInternal struct {
	Status       string
	CurrentJobID string
	JobsTotal    int64
	JobsSuccess  int64
	JobsFailed   int64
}

WorkerStatsInternal structure interne pour les stats du worker

type Workspace

type Workspace struct {
	// contains filtered or unexported fields
}

Workspace représente un espace de travail isolé pour un job

func NewWorkspace

func NewWorkspace(basePath string, jobID uuid.UUID) (*Workspace, error)

NewWorkspace crée un nouveau workspace pour un job avec gestion des permissions

func (*Workspace) Cleanup

func (w *Workspace) Cleanup() error

Cleanup supprime le workspace et tous ses fichiers avec vérifications de sécurité

func (*Workspace) CopyFile

func (w *Workspace) CopyFile(src, dst string) error

CopyFile copie un fichier à l'intérieur du workspace

func (*Workspace) CreateDirectory

func (w *Workspace) CreateDirectory(dirname string) error

CreateDirectory crée un répertoire dans le workspace

func (*Workspace) DirExists

func (w *Workspace) DirExists(dirname string) bool

DirExists vérifie si un répertoire existe dans le workspace

func (*Workspace) FileExists

func (w *Workspace) FileExists(filename string) bool

FileExists vérifie si un fichier existe dans le workspace

func (*Workspace) GetAbsDistPath

func (w *Workspace) GetAbsDistPath() string

GetAbsDistPath retourne le chemin absolu du répertoire de sortie

func (*Workspace) GetDistPath

func (w *Workspace) GetDistPath() string

GetDistPath retourne le chemin du répertoire de sortie

func (*Workspace) GetFileSize

func (w *Workspace) GetFileSize(filename string) (int64, error)

GetFileSize retourne la taille d'un fichier

func (*Workspace) GetPath

func (w *Workspace) GetPath() string

func (*Workspace) GetWorkspaceInfo

func (w *Workspace) GetWorkspaceInfo() WorkspaceInfo

GetWorkspaceInfo retourne des informations sur le workspace

func (*Workspace) ListAllFiles

func (w *Workspace) ListAllFiles(dirname string) ([]string, error)

ListAllFiles liste récursivement tous les fichiers dans un répertoire

func (*Workspace) ListFiles

func (w *Workspace) ListFiles(dirname string) ([]string, error)

ListFiles liste les fichiers dans un répertoire du workspace

func (*Workspace) ReadFile

func (w *Workspace) ReadFile(filename string) (io.Reader, error)

ReadFile lit un fichier depuis le workspace

func (*Workspace) WriteFile

func (w *Workspace) WriteFile(filename string, reader io.Reader) error

WriteFile écrit un fichier dans le workspace avec gestion d'erreurs améliorée

type WorkspaceInfo

type WorkspaceInfo struct {
	JobID         string   `json:"job_id"`
	Path          string   `json:"path"`
	DistPath      string   `json:"dist_path"`
	Exists        bool     `json:"exists"`
	SizeBytes     int64    `json:"size_bytes"`
	FileCount     int      `json:"file_count"`
	Files         []string `json:"files,omitempty"`
	DistExists    bool     `json:"dist_exists"`
	DistFileCount int      `json:"dist_file_count"`
	DistFiles     []string `json:"dist_files,omitempty"`
}

WorkspaceInfo contient des informations sur un workspace

type WorkspaceManager

type WorkspaceManager struct {
	// contains filtered or unexported fields
}

WorkspaceManager gère les workspaces globalement

func NewWorkspaceManager

func NewWorkspaceManager(basePath string) (*WorkspaceManager, error)

NewWorkspaceManager crée un nouveau gestionnaire de workspaces

func (*WorkspaceManager) CleanupOldWorkspaces

func (wm *WorkspaceManager) CleanupOldWorkspaces(maxAge int64) (int, error)

CleanupOldWorkspaces supprime les workspaces plus anciens qu'une durée donnée

func (*WorkspaceManager) GetWorkspaceStats

func (wm *WorkspaceManager) GetWorkspaceStats() (WorkspaceStats, error)

GetWorkspaceStats retourne des statistiques globales sur les workspaces

func (*WorkspaceManager) ListWorkspaces

func (wm *WorkspaceManager) ListWorkspaces() ([]WorkspaceInfo, error)

ListWorkspaces liste tous les workspaces existants

type WorkspaceStats

type WorkspaceStats struct {
	TotalWorkspaces    int   `json:"total_workspaces"`
	WorkspacesWithDist int   `json:"workspaces_with_dist"`
	TotalSizeBytes     int64 `json:"total_size_bytes"`
	TotalFileCount     int   `json:"total_file_count"`
}

WorkspaceStats contient des statistiques sur les workspaces

Jump to

Keyboard shortcuts

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