9p: simplify BatchJobStore.Wait; remove CurrentWaitValue
State is terminal-only (running→done/failed), so base comparison adds nothing — block on the done channel directly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4d5ae06780
commit
0e43664b40
|
|
@ -490,38 +490,19 @@ func (js *BatchJobStore) content(name string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentWaitValue returns the current value for the named *wait file.
|
// Wait blocks until the job reaches a terminal state, then returns it.
|
||||||
func (js *BatchJobStore) CurrentWaitValue(name string) string {
|
|
||||||
if name == "statewait" {
|
|
||||||
js.job.mu.RLock()
|
|
||||||
defer js.job.mu.RUnlock()
|
|
||||||
return js.job.state
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait blocks until the job leaves "running" state, then returns the new state.
|
|
||||||
// Returns nil content (empty read) on context cancellation.
|
// Returns nil content (empty read) on context cancellation.
|
||||||
func (js *BatchJobStore) Wait(ctx context.Context, name, base string) ([]byte, error) {
|
func (js *BatchJobStore) Wait(ctx context.Context, name, _ string) ([]byte, error) {
|
||||||
if name != "statewait" {
|
if name != "statewait" {
|
||||||
return nil, fmt.Errorf("%s: not a wait file", name)
|
return nil, fmt.Errorf("%s: not a wait file", name)
|
||||||
}
|
}
|
||||||
js.job.mu.RLock()
|
|
||||||
current := js.job.state
|
|
||||||
js.job.mu.RUnlock()
|
|
||||||
if base == "" {
|
|
||||||
base = current
|
|
||||||
}
|
|
||||||
if current != base {
|
|
||||||
return []byte(current + "\n"), nil
|
|
||||||
}
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, nil
|
return nil, nil
|
||||||
case <-js.job.done:
|
case <-js.job.done:
|
||||||
}
|
}
|
||||||
js.job.mu.RLock()
|
js.job.mu.RLock()
|
||||||
current = js.job.state
|
state := js.job.state
|
||||||
js.job.mu.RUnlock()
|
js.job.mu.RUnlock()
|
||||||
return []byte(current + "\n"), nil
|
return []byte(state + "\n"), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in New Issue