Task for continuously check for iTunes Library updates
This commit is contained in:
+6
-5
@@ -26,12 +26,13 @@ type Scanner interface {
|
|||||||
type tempIndex map[string]domain.ArtistInfo
|
type tempIndex map[string]domain.ArtistInfo
|
||||||
|
|
||||||
var (
|
var (
|
||||||
inProgress = make(chan int)
|
inProgress chan int
|
||||||
lastUpdated time.Time
|
lastCheck time.Time
|
||||||
itunesLibrary string
|
itunesLibrary string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
inProgress = make(chan int)
|
||||||
startImport()
|
startImport()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ func CheckForUpdates(force bool) {
|
|||||||
<-inProgress
|
<-inProgress
|
||||||
|
|
||||||
if force {
|
if force {
|
||||||
lastUpdated = time.Time{}
|
lastCheck = time.Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
startImport()
|
startImport()
|
||||||
@@ -55,11 +56,11 @@ func startImport() {
|
|||||||
beego.Error(err)
|
beego.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if lastUpdated.After(info.ModTime()) {
|
if lastCheck.After(info.ModTime()) {
|
||||||
inProgress <- 1
|
inProgress <- 1
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastUpdated = time.Now()
|
lastCheck = time.Now()
|
||||||
|
|
||||||
// TODO Move all to DI
|
// TODO Move all to DI
|
||||||
i := &Importer{mediaFolder: beego.AppConfig.String("musicFolder")}
|
i := &Importer{mediaFolder: beego.AppConfig.String("musicFolder")}
|
||||||
|
|||||||
+7
-1
@@ -1,6 +1,9 @@
|
|||||||
package tasks
|
package tasks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego"
|
||||||
"github.com/astaxie/beego/toolbox"
|
"github.com/astaxie/beego/toolbox"
|
||||||
"github.com/deluan/gosonic/scanner"
|
"github.com/deluan/gosonic/scanner"
|
||||||
)
|
)
|
||||||
@@ -14,6 +17,9 @@ func init() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
toolbox.AddTask(TaskItunesScan, scan)
|
toolbox.AddTask(TaskItunesScan, scan)
|
||||||
|
go func() {
|
||||||
|
time.Sleep(20 * time.Second)
|
||||||
|
beego.Debug("Starting", TaskItunesScan)
|
||||||
toolbox.StartTask()
|
toolbox.StartTask()
|
||||||
defer toolbox.DeleteTask(TaskItunesScan)
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user