Skip to content

Commit 8abf6af

Browse files
committed
fix scan bugs
1 parent 97bca3d commit 8abf6af

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

.github/workflows/docker.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
file: "m4t_server/Dockerfile"
2929
image: "m4t-server"
3030
platforms: "linux/amd64,linux/arm64"
31-
base: "python:3.10.8-slim" # CPU only
31+
base: "nvidia/cuda:12.2.2-base-ubuntu22.04" # CPU only
3232
image_type: "cpu"
3333
- context: "."
3434
file: "Dockerfile"

api/epub/selfhost/scan.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ func NewScan(ctx context.Context, root, meta string) (*Scanner, error) {
5959

6060
}
6161

62+
func (m *Scanner) status(errs []string, done bool) ScanStatus {
63+
return ScanStatus{
64+
Running: done,
65+
ScanCount: m.Count,
66+
EpubCount: m.Count, // 当前只是扫描了 epub 文件
67+
Errs: errs,
68+
}
69+
}
70+
6271
func (m *Scanner) scanEpub(manager *ScannerManager, books <-chan *schema.Book) {
6372

6473
errs := []string{}
@@ -73,6 +82,7 @@ func (m *Scanner) scanEpub(manager *ScannerManager, books <-chan *schema.Book) {
7382

7483
m.wg.Done()
7584
// close(errChan)
85+
7686
close(statusChan)
7787
ticker.Stop()
7888
log.I(`退出扫描程序`)
@@ -83,14 +93,17 @@ func (m *Scanner) scanEpub(manager *ScannerManager, books <-chan *schema.Book) {
8393
select {
8494

8595
case <-m.ctx.Done():
96+
statusChan <- m.status(errs, false)
8697
log.W(`接收到退出命令,退出扫描`)
8798
return
99+
case <-ticker.C: // 定时器触发时发送当前状态
100+
statusChan <- m.status(errs, true)
101+
errs = []string{}
88102
case book, ok := <-books:
89-
//debug
90-
// time.Sleep(200 * time.Millisecond)
91103
if !ok {
92104
//books is closed
93-
log.I(`书籍为空,退出解析文件。`)
105+
statusChan <- m.status(errs, false)
106+
log.I(`扫描完成,退出解析文件。`)
94107
return
95108
}
96109
m.Count++
@@ -109,15 +122,6 @@ func (m *Scanner) scanEpub(manager *ScannerManager, books <-chan *schema.Book) {
109122

110123
}
111124

112-
case <-ticker.C: // 定时器触发时发送当前状态
113-
status := ScanStatus{
114-
Running: true,
115-
ScanCount: m.Count,
116-
EpubCount: m.Count, // 当前只是扫描了 epub 文件
117-
Errs: errs,
118-
}
119-
statusChan <- status
120-
errs = []string{}
121125
}
122126
}
123127

@@ -131,7 +135,7 @@ func (m *Scanner) scanEpub(manager *ScannerManager, books <-chan *schema.Book) {
131135
manager.updateStatus(status)
132136
}
133137
//关闭扫描器
134-
manager.dumpStats(m.cached, true)
138+
manager.dumpStats(m.cached)
135139

136140
m.cached.Close()
137141
m.cached = nil

api/epub/selfhost/scan_manager.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,12 @@ func (m *ScannerManager) newScan(refresh bool) {
110110
return
111111
}
112112
m.stats.Running = true
113+
m.stats.Errs = nil
113114
m.Unlock()
114115

115116
scan.Start(m, refresh)
116117
}
117118

118-
func (m *ScannerManager) updateStatus(stats ScanStatus) {
119-
m.Lock()
120-
defer m.Unlock()
121-
m.stats = stats
122-
123-
}
124-
125119
func (m *ScannerManager) Stop() {
126120
m.Lock()
127121
defer m.Unlock()
@@ -135,11 +129,18 @@ func (m *ScannerManager) Stop() {
135129

136130
}
137131

138-
func (m *ScannerManager) dumpStats(cached *nutsdb.DB, done bool) error {
132+
func (m *ScannerManager) updateStatus(stats ScanStatus) {
133+
m.Lock()
134+
defer m.Unlock()
135+
stats.Errs = append(stats.Errs, m.stats.Errs...)
136+
stats.Total = m.stats.Total + int64(m.stats.ScanCount)
137+
m.stats = stats
138+
139+
}
140+
141+
func (m *ScannerManager) dumpStats(cached *nutsdb.DB) error {
139142

140-
stats := m.Status()
141-
stats.Running = !done
142-
bytes, _ := json.Marshal(stats)
143+
bytes, _ := json.Marshal(m.Status())
143144

144145
return cached.Update(
145146
func(tx *nutsdb.Tx) error {

m4t_server/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ docker_gpu:
1818
@docker buildx build --build-arg BUILD_COUNTRY="CN" -t m4t-server:0.0.2 ./
1919

2020
docker_cpu:
21-
@docker buildx build --build-arg BUILD_COUNTRY="CN" --build-arg BASE="python:3.10.8-slim" --build-arg DEVICE="cpu" -t m4t-server:0.0.2-cpu ./
21+
@docker buildx build --build-arg BUILD_COUNTRY="CN" --build-arg DEVICE="cpu" -t m4t-server:0.0.2-cpu ./
2222

0 commit comments

Comments
 (0)