mirror of https://github.com/Xhofe/alist
fix: send on closed channel
parent
08a001fbd1
commit
9e5ef974a7
|
@ -94,19 +94,14 @@ func EnableStorage(ctx context.Context, id uint) error {
|
||||||
if !storage.Disabled {
|
if !storage.Disabled {
|
||||||
return errors.Errorf("this storage have enabled")
|
return errors.Errorf("this storage have enabled")
|
||||||
}
|
}
|
||||||
err = LoadStorage(ctx, *storage)
|
|
||||||
if err != nil {
|
|
||||||
return errors.WithMessage(err, "failed load storage")
|
|
||||||
}
|
|
||||||
// re-get storage from db, because it maybe hava updated
|
|
||||||
storage, err = db.GetStorageById(id)
|
|
||||||
if err != nil {
|
|
||||||
return errors.WithMessage(err, "failed re-get storage again")
|
|
||||||
}
|
|
||||||
storage.Disabled = false
|
storage.Disabled = false
|
||||||
err = db.UpdateStorage(storage)
|
err = db.UpdateStorage(storage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "failed update storage in db, but have load in memory. you can try restart")
|
return errors.WithMessage(err, "failed update storage in db")
|
||||||
|
}
|
||||||
|
err = LoadStorage(ctx, *storage)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "failed load storage")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -128,12 +123,12 @@ func DisableStorage(ctx context.Context, id uint) error {
|
||||||
return errors.Wrapf(err, "failed drop storage")
|
return errors.Wrapf(err, "failed drop storage")
|
||||||
}
|
}
|
||||||
// delete the storage in the memory
|
// delete the storage in the memory
|
||||||
storagesMap.Delete(storage.MountPath)
|
|
||||||
storage.Disabled = true
|
storage.Disabled = true
|
||||||
err = db.UpdateStorage(storage)
|
err = db.UpdateStorage(storage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "failed update storage in db, but have drop in memory. you can try restart")
|
return errors.WithMessage(err, "failed update storage in db")
|
||||||
}
|
}
|
||||||
|
storagesMap.Delete(storage.MountPath)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,10 @@ func (c *Cron) Do(f func()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cron) Stop() {
|
func (c *Cron) Stop() {
|
||||||
|
select {
|
||||||
|
case _, _ = <-c.ch:
|
||||||
|
default:
|
||||||
c.ch <- struct{}{}
|
c.ch <- struct{}{}
|
||||||
close(c.ch)
|
close(c.ch)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ func TestCron(t *testing.T) {
|
||||||
c.Do(func() {
|
c.Do(func() {
|
||||||
t.Logf("cron log")
|
t.Logf("cron log")
|
||||||
})
|
})
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 3)
|
||||||
|
c.Stop()
|
||||||
c.Stop()
|
c.Stop()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue