Sharing: Instantly trigger upload #225

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-04-06 10:26:26 +02:00
parent bf2b5ca108
commit 9b7a5d69d4
3 changed files with 30 additions and 20 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/query"
"github.com/photoprism/photoprism/internal/workers"
"github.com/photoprism/photoprism/pkg/txt"
)
@ -144,6 +145,8 @@ func ShareWithAccount(router *gin.RouterGroup, conf *config.Config) {
fileShare.FirstOrCreate(conf.Db())
}
workers.StartShare(conf)
c.JSON(http.StatusOK, files)
})
}

View file

@ -105,6 +105,7 @@ func (s *Share) Start() (err error) {
file.Errors++
file.Error = err.Error()
} else {
log.Infof("share: uploaded %s to %s", file.RemoteName, a.AccName)
file.Errors = 0
file.Error = ""
file.Status = entity.FileShareShared
@ -156,6 +157,7 @@ func (s *Share) Start() (err error) {
file.Errors++
file.Error = err.Error()
} else {
log.Infof("share: removed %s from %s", file.RemoteName, a.AccName)
file.Errors = 0
file.Error = ""
file.Status = entity.FileShareRemoved

View file

@ -12,7 +12,7 @@ var log = event.Log
var stop = make(chan bool, 1)
func Start(conf *config.Config) {
ticker := time.NewTicker(5 * time.Minute) // TODO
ticker := time.NewTicker(15 * time.Minute)
go func() {
for {
@ -24,30 +24,35 @@ func Start(conf *config.Config) {
mutex.Sync.Cancel()
return
case <-ticker.C:
if !mutex.Share.Busy() {
go func() {
// Start
s := NewShare(conf)
if err := s.Start(); err != nil {
log.Error(err)
}
}()
}
if !mutex.Sync.Busy() {
go func() {
// Start
s := NewSync(conf)
if err := s.Start(); err != nil {
log.Error(err)
}
}()
}
StartShare(conf)
StartSync(conf)
}
}
}()
}
func StartShare(conf *config.Config) {
if !mutex.Share.Busy() {
go func() {
s := NewShare(conf)
if err := s.Start(); err != nil {
log.Error(err)
}
}()
}
}
func StartSync(conf *config.Config) {
if !mutex.Sync.Busy() {
go func() {
s := NewSync(conf)
if err := s.Start(); err != nil {
log.Error(err)
}
}()
}
}
func Stop() {
stop <- true
}