|
@@ -2,6 +2,7 @@ package sub_supplier
|
|
|
|
|
|
import (
|
|
import (
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
|
+ "sync"
|
|
|
|
|
|
"github.com/ChineseSubFinder/ChineseSubFinder/pkg/media_info_dealers"
|
|
"github.com/ChineseSubFinder/ChineseSubFinder/pkg/media_info_dealers"
|
|
|
|
|
|
@@ -21,6 +22,7 @@ import (
|
|
type SubSupplierHub struct {
|
|
type SubSupplierHub struct {
|
|
log *logrus.Logger
|
|
log *logrus.Logger
|
|
Suppliers []ifaces.ISupplier
|
|
Suppliers []ifaces.ISupplier
|
|
|
|
+ locker sync.Mutex
|
|
}
|
|
}
|
|
|
|
|
|
func NewSubSupplierHub(one ifaces.ISupplier, _inSupplier ...ifaces.ISupplier) *SubSupplierHub {
|
|
func NewSubSupplierHub(one ifaces.ISupplier, _inSupplier ...ifaces.ISupplier) *SubSupplierHub {
|
|
@@ -186,22 +188,32 @@ func (d *SubSupplierHub) CheckSubSiteStatus() backend.ReplyCheckStatus {
|
|
SubSiteStatus: make([]backend.SiteStatus, 0),
|
|
SubSiteStatus: make([]backend.SiteStatus, 0),
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ var wg sync.WaitGroup
|
|
|
|
+
|
|
// 测试提供字幕的网站是有效的
|
|
// 测试提供字幕的网站是有效的
|
|
d.log.Infoln("Check Sub Supplier Start...")
|
|
d.log.Infoln("Check Sub Supplier Start...")
|
|
for _, supplier := range d.Suppliers {
|
|
for _, supplier := range d.Suppliers {
|
|
- bAlive, speed := supplier.CheckAlive()
|
|
|
|
- if bAlive == false {
|
|
|
|
- d.log.Warningln(supplier.GetSupplierName(), "Check Alive = false")
|
|
|
|
- } else {
|
|
|
|
- d.log.Infoln(supplier.GetSupplierName(), "Check Alive = true, Speed =", speed, "ms")
|
|
|
|
- }
|
|
|
|
|
|
+ wg.Add(1)
|
|
|
|
+ go func(supplier ifaces.ISupplier) {
|
|
|
|
+ defer wg.Done()
|
|
|
|
+ bAlive, speed := supplier.CheckAlive()
|
|
|
|
+ if bAlive == false {
|
|
|
|
+ d.log.Warningln(supplier.GetSupplierName(), "Check Alive = false")
|
|
|
|
+ } else {
|
|
|
|
+ d.log.Infoln(supplier.GetSupplierName(), "Check Alive = true, Speed =", speed, "ms")
|
|
|
|
+ }
|
|
|
|
|
|
- outStatus.SubSiteStatus = append(outStatus.SubSiteStatus, backend.SiteStatus{
|
|
|
|
- Name: supplier.GetSupplierName(),
|
|
|
|
- Valid: bAlive,
|
|
|
|
- Speed: speed,
|
|
|
|
- })
|
|
|
|
|
|
+ d.locker.Lock()
|
|
|
|
+ outStatus.SubSiteStatus = append(outStatus.SubSiteStatus, backend.SiteStatus{
|
|
|
|
+ Name: supplier.GetSupplierName(),
|
|
|
|
+ Valid: bAlive,
|
|
|
|
+ Speed: speed,
|
|
|
|
+ })
|
|
|
|
+ d.locker.Unlock()
|
|
|
|
+ }(supplier)
|
|
}
|
|
}
|
|
|
|
+ // 等待所有的检测完成
|
|
|
|
+ wg.Wait()
|
|
|
|
|
|
suppliersLen := len(d.Suppliers)
|
|
suppliersLen := len(d.Suppliers)
|
|
for i := 0; i < suppliersLen; {
|
|
for i := 0; i < suppliersLen; {
|