Skip to content

Commit 7066078

Browse files
authored
Merge pull request #122 from contre95/fix/job_reference
chore(jobs): Move jobs entities to domains
2 parents aa4dbdc + 08bef93 commit 7066078

File tree

14 files changed

+132
-133
lines changed

14 files changed

+132
-133
lines changed

src/features/analyze/acoustid_job.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"log/slog"
77

8-
"github.com/contre95/soulsolid/src/features/jobs"
8+
"github.com/contre95/soulsolid/src/music"
99
)
1010

1111
// AcoustIDJobTask handles AcoustID analysis job execution
@@ -26,7 +26,7 @@ func (t *AcoustIDJobTask) MetadataKeys() []string {
2626
}
2727

2828
// Execute performs the AcoustID analysis operation
29-
func (t *AcoustIDJobTask) Execute(ctx context.Context, job *jobs.Job, progressUpdater func(int, string)) (map[string]any, error) {
29+
func (t *AcoustIDJobTask) Execute(ctx context.Context, job *music.Job, progressUpdater func(int, string)) (map[string]any, error) {
3030
// Get total track count for progress reporting
3131
totalTracks, err := t.service.library.GetTracksCount(ctx)
3232
if err != nil {
@@ -134,7 +134,7 @@ func (t *AcoustIDJobTask) Execute(ctx context.Context, job *jobs.Job, progressUp
134134
}
135135

136136
// Cleanup performs cleanup after job completion
137-
func (t *AcoustIDJobTask) Cleanup(job *jobs.Job) error {
137+
func (t *AcoustIDJobTask) Cleanup(job *music.Job) error {
138138
slog.Debug("Cleaning up AcoustID analysis job", "jobID", job.ID)
139139
return nil
140140
}

src/features/analyze/lyrics_job.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"log/slog"
77

8-
"github.com/contre95/soulsolid/src/features/jobs"
8+
"github.com/contre95/soulsolid/src/music"
99
)
1010

1111
// LyricsJobTask handles lyrics analysis job execution
@@ -26,7 +26,7 @@ func (t *LyricsJobTask) MetadataKeys() []string {
2626
}
2727

2828
// Execute performs the lyrics analysis operation
29-
func (t *LyricsJobTask) Execute(ctx context.Context, job *jobs.Job, progressUpdater func(int, string)) (map[string]any, error) {
29+
func (t *LyricsJobTask) Execute(ctx context.Context, job *music.Job, progressUpdater func(int, string)) (map[string]any, error) {
3030
job.Logger.Info("EXECUTE STARTED: Lyrics job task is running", "color", "pink")
3131

3232
// Check if any lyrics providers are enabled
@@ -146,7 +146,7 @@ func (t *LyricsJobTask) Execute(ctx context.Context, job *jobs.Job, progressUpda
146146
}
147147

148148
// Cleanup performs cleanup after job completion
149-
func (t *LyricsJobTask) Cleanup(job *jobs.Job) error {
149+
func (t *LyricsJobTask) Cleanup(job *music.Job) error {
150150
slog.Debug("Cleaning up lyrics analysis job", "jobID", job.ID)
151151
return nil
152152
}

src/features/analyze/reorganize_job.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"os"
88
"path/filepath"
99

10-
"github.com/contre95/soulsolid/src/features/jobs"
10+
"github.com/contre95/soulsolid/src/music"
1111
)
1212

1313
// ReorganizeJobTask handles file reorganization job execution
@@ -28,7 +28,7 @@ func (t *ReorganizeJobTask) MetadataKeys() []string {
2828
}
2929

3030
// Execute performs the file reorganization operation
31-
func (t *ReorganizeJobTask) Execute(ctx context.Context, job *jobs.Job, progressUpdater func(int, string)) (map[string]any, error) {
31+
func (t *ReorganizeJobTask) Execute(ctx context.Context, job *music.Job, progressUpdater func(int, string)) (map[string]any, error) {
3232
// Get total track count for progress reporting
3333
totalTracks, err := t.service.library.GetTracksCount(ctx)
3434
if err != nil {
@@ -144,7 +144,7 @@ func (t *ReorganizeJobTask) Execute(ctx context.Context, job *jobs.Job, progress
144144
}
145145

146146
// Cleanup performs cleanup after job completion
147-
func (t *ReorganizeJobTask) Cleanup(job *jobs.Job) error {
147+
func (t *ReorganizeJobTask) Cleanup(job *music.Job) error {
148148
slog.Debug("Cleaning up reorganization job", "jobID", job.ID)
149149
return nil
150150
}

src/features/downloading/download_job.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"regexp"
1010
"strings"
1111

12-
"github.com/contre95/soulsolid/src/features/jobs"
1312
"github.com/contre95/soulsolid/src/music"
1413
)
1514

@@ -40,7 +39,7 @@ func (e *DownloadJobTask) MetadataKeys() []string {
4039
}
4140

4241
// Execute performs the download operation
43-
func (e *DownloadJobTask) Execute(ctx context.Context, job *jobs.Job, progressUpdater func(int, string)) (map[string]any, error) {
42+
func (e *DownloadJobTask) Execute(ctx context.Context, job *music.Job, progressUpdater func(int, string)) (map[string]any, error) {
4443
jobType, ok := job.Metadata["type"].(string)
4544
if !ok {
4645
return nil, fmt.Errorf("invalid job type")
@@ -67,7 +66,7 @@ func (e *DownloadJobTask) Execute(ctx context.Context, job *jobs.Job, progressUp
6766
}
6867

6968
// executeTrackDownload handles track download jobs
70-
func (e *DownloadJobTask) executeTrackDownload(ctx context.Context, job *jobs.Job, progressUpdater func(int, string), downloadPath string) (map[string]any, error) {
69+
func (e *DownloadJobTask) executeTrackDownload(ctx context.Context, job *music.Job, progressUpdater func(int, string), downloadPath string) (map[string]any, error) {
7170
trackID, ok := job.Metadata["trackID"].(string)
7271
if !ok {
7372
return nil, fmt.Errorf("trackID not found in job metadata")
@@ -152,7 +151,7 @@ func (e *DownloadJobTask) executeTrackDownload(ctx context.Context, job *jobs.Jo
152151
}
153152

154153
// executeAlbumDownload handles album download jobs
155-
func (e *DownloadJobTask) executeAlbumDownload(ctx context.Context, job *jobs.Job, progressUpdater func(int, string), downloadPath string) (map[string]any, error) {
154+
func (e *DownloadJobTask) executeAlbumDownload(ctx context.Context, job *music.Job, progressUpdater func(int, string), downloadPath string) (map[string]any, error) {
156155
albumID, ok := job.Metadata["albumID"].(string)
157156
if !ok {
158157
return nil, fmt.Errorf("albumID not found in job metadata")
@@ -264,7 +263,7 @@ func (e *DownloadJobTask) executeAlbumDownload(ctx context.Context, job *jobs.Jo
264263
}
265264

266265
// executeArtistDownload handles artist download jobs
267-
func (e *DownloadJobTask) executeArtistDownload(ctx context.Context, job *jobs.Job, progressUpdater func(int, string), downloadPath string) (map[string]any, error) {
266+
func (e *DownloadJobTask) executeArtistDownload(ctx context.Context, job *music.Job, progressUpdater func(int, string), downloadPath string) (map[string]any, error) {
268267
artistID, ok := job.Metadata["artistID"].(string)
269268
if !ok {
270269
return nil, fmt.Errorf("artistID not found in job metadata")
@@ -384,7 +383,7 @@ func (e *DownloadJobTask) executeArtistDownload(ctx context.Context, job *jobs.J
384383
}
385384

386385
// executeTracksDownload handles multiple track download jobs
387-
func (e *DownloadJobTask) executeTracksDownload(ctx context.Context, job *jobs.Job, progressUpdater func(int, string), downloadPath string) (map[string]any, error) {
386+
func (e *DownloadJobTask) executeTracksDownload(ctx context.Context, job *music.Job, progressUpdater func(int, string), downloadPath string) (map[string]any, error) {
388387
var trackIDs []string
389388

390389
// Try to get trackIDs as []string first
@@ -488,7 +487,7 @@ func (e *DownloadJobTask) executeTracksDownload(ctx context.Context, job *jobs.J
488487
}
489488

490489
// executePlaylistDownload handles playlist download jobs
491-
func (e *DownloadJobTask) executePlaylistDownload(ctx context.Context, job *jobs.Job, progressUpdater func(int, string), downloadPath string) (map[string]any, error) {
490+
func (e *DownloadJobTask) executePlaylistDownload(ctx context.Context, job *music.Job, progressUpdater func(int, string), downloadPath string) (map[string]any, error) {
492491
playlistName, ok := job.Metadata["playlistName"].(string)
493492
if !ok {
494493
return nil, fmt.Errorf("playlistName not found in job metadata")
@@ -588,7 +587,7 @@ func (e *DownloadJobTask) executePlaylistDownload(ctx context.Context, job *jobs
588587
}
589588

590589
// Cleanup performs cleanup after job completion
591-
func (e *DownloadJobTask) Cleanup(job *jobs.Job) error {
590+
func (e *DownloadJobTask) Cleanup(job *music.Job) error {
592591
// TODO: Clean up temporary files, etc.
593592
slog.Debug("Cleaning up download job", "jobID", job.ID)
594593
return nil

src/features/downloading/service.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ import (
66
"strings"
77

88
"github.com/contre95/soulsolid/src/features/config"
9-
"github.com/contre95/soulsolid/src/features/jobs"
109
"github.com/contre95/soulsolid/src/music"
1110
)
1211

1312
// Service handles downloading operations
1413
type Service struct {
1514
configManager *config.Manager
16-
jobService jobs.JobService // TODO: Move this to domain job service
15+
jobService music.JobService // TODO: Move this to domain job service
1716
pluginManager *PluginManager
1817
tagWriter TagWriter
1918
}
2019

2120
// NewService creates a new downloading service
22-
func NewService(cfgManager *config.Manager, jobService jobs.JobService, pluginManager *PluginManager, tagWriter TagWriter) *Service {
21+
func NewService(cfgManager *config.Manager, jobService music.JobService, pluginManager *PluginManager, tagWriter TagWriter) *Service {
2322
return &Service{
2423
configManager: cfgManager,
2524
jobService: jobService,

src/features/importing/directory_job.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"time"
1212

1313
"github.com/contre95/soulsolid/src/features/config"
14-
"github.com/contre95/soulsolid/src/features/jobs"
1514
"github.com/contre95/soulsolid/src/music"
1615
)
1716

@@ -41,7 +40,7 @@ func (e *DirectoryImportTask) MetadataKeys() []string {
4140
}
4241

4342
// Execute runs the directory import logic.
44-
func (e *DirectoryImportTask) Execute(ctx context.Context, job *jobs.Job, progressUpdater func(int, string)) (map[string]any, error) {
43+
func (e *DirectoryImportTask) Execute(ctx context.Context, job *music.Job, progressUpdater func(int, string)) (map[string]any, error) {
4544
path := job.Metadata["path"].(string)
4645

4746
stats, err := e.runDirectoryImport(ctx, path, progressUpdater, job.Logger, job)
@@ -75,7 +74,7 @@ func (e *DirectoryImportTask) Execute(ctx context.Context, job *jobs.Job, progre
7574
}
7675

7776
// Cleanup does nothing for directory imports.
78-
func (e *DirectoryImportTask) Cleanup(job *jobs.Job) error {
77+
func (e *DirectoryImportTask) Cleanup(job *music.Job) error {
7978
return nil
8079
}
8180

@@ -206,7 +205,7 @@ func (e *DirectoryImportTask) findExistingTrack(ctx context.Context, trackToImpo
206205
return existingTrack, nil
207206
}
208207

209-
func (e *DirectoryImportTask) runDirectoryImport(ctx context.Context, pathToImport string, progressUpdater func(int, string), logger *slog.Logger, job *jobs.Job) (ImportStats, error) {
208+
func (e *DirectoryImportTask) runDirectoryImport(ctx context.Context, pathToImport string, progressUpdater func(int, string), logger *slog.Logger, job *music.Job) (ImportStats, error) {
210209
logger.Info("Service.runDirectoryImport: starting import", "path", pathToImport)
211210
var stats ImportStats
212211
moveFiles := e.service.config.Get().Import.Move

src/features/importing/service.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
"github.com/contre95/soulsolid/src/features/config"
13-
"github.com/contre95/soulsolid/src/features/jobs"
1413
"github.com/contre95/soulsolid/src/music"
1514
)
1615

@@ -36,13 +35,13 @@ type Service struct {
3635
metadataReader TagReader
3736
fingerprintReader FingerprintProvider
3837
config *config.Manager
39-
jobService jobs.JobService // TODO: Move this to domain job service
38+
jobService music.JobService // TODO: Move this to domain job service
4039
queue Queue
4140
watcher Watcher
4241
}
4342

4443
// NewService creates a new organizing service.
45-
func NewService(lib music.Library, tagReader TagReader, fingerprintReader FingerprintProvider, fileManager music.FileManager, cfg *config.Manager, jobService jobs.JobService, queue Queue, watcher Watcher) *Service {
44+
func NewService(lib music.Library, tagReader TagReader, fingerprintReader FingerprintProvider, fileManager music.FileManager, cfg *config.Manager, jobService music.JobService, queue Queue, watcher Watcher) *Service {
4645
s := &Service{
4746
config: cfg,
4847
library: lib,

src/features/jobs/handlers.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88
"time"
99

10+
"github.com/contre95/soulsolid/src/music"
1011
"github.com/gofiber/fiber/v2"
1112
)
1213

@@ -16,7 +17,7 @@ type Handler struct {
1617

1718
// JobResponse is a wrapper for the Job struct to include API links
1819
type JobResponse struct {
19-
*Job
20+
*music.Job
2021
Links map[string]string `json:"_links"`
2122
}
2223

@@ -127,7 +128,7 @@ func (h *Handler) HandleJobProgress(c *fiber.Ctx) error {
127128
return c.Status(404).SendString("Job not found.")
128129
}
129130

130-
if job.Status == JobStatusCompleted || job.Status == JobStatusFailed || job.Status == JobStatusCancelled {
131+
if job.Status == music.JobStatusCompleted || job.Status == music.JobStatusFailed || job.Status == music.JobStatusCancelled {
131132
c.Set("HX-Trigger", "done")
132133
}
133134

@@ -213,9 +214,9 @@ func (h *Handler) HandleActiveJob(c *fiber.Ctx) error {
213214
jobs := h.service.GetJobs()
214215

215216
// Filter out completed/failed/cancelled jobs to show only active ones
216-
activeJobs := make([]*Job, 0)
217+
activeJobs := make([]*music.Job, 0)
217218
for _, job := range jobs {
218-
if job.Status == JobStatusRunning || job.Status == JobStatusPending {
219+
if job.Status == music.JobStatusRunning || job.Status == music.JobStatusPending {
219220
activeJobs = append(activeJobs, job)
220221
}
221222
}
@@ -236,7 +237,7 @@ func (h *Handler) HandleFilteredJobsList(c *fiber.Ctx) error {
236237
// Filter jobs by type if specified
237238
jobTypeFilter := c.Query("prefix")
238239
if jobTypeFilter != "" {
239-
filteredJobs := make([]*Job, 0)
240+
filteredJobs := make([]*music.Job, 0)
240241
for _, job := range jobs {
241242
if strings.HasPrefix(job.Type, jobTypeFilter) {
242243
filteredJobs = append(filteredJobs, job)
@@ -274,7 +275,7 @@ func (h *Handler) HandleJobsCount(c *fiber.Ctx) error {
274275
count := 0
275276

276277
for _, job := range jobs {
277-
if filter == "active" && (job.Status == JobStatusRunning || job.Status == JobStatusPending) {
278+
if filter == "active" && (job.Status == music.JobStatusRunning || job.Status == music.JobStatusPending) {
278279
count++
279280
} else if filter == "all" {
280281
count++

0 commit comments

Comments
 (0)