refactor: implement worker pool pattern, add persistent task queue, and decouple target loading logic
This commit is contained in:
@@ -21,14 +21,17 @@ func NewPipeline(filters ...JobFilter) *FilterPipeline {
|
||||
return &FilterPipeline{filters: filters}
|
||||
}
|
||||
|
||||
func (p *FilterPipeline) Execute(ctx context.Context, title, rawContent string) (bool, float64) {
|
||||
func (p *FilterPipeline) Execute(ctx context.Context, title, rawContent string) (bool, float64, string) {
|
||||
var totalScore float64
|
||||
for _, f := range p.filters {
|
||||
res, err := f.Process(ctx, title, rawContent)
|
||||
if err != nil || !res.Keep {
|
||||
return false, 0
|
||||
if err != nil {
|
||||
return false, 0, err.Error()
|
||||
}
|
||||
if !res.Keep {
|
||||
return false, 0, res.Reason
|
||||
}
|
||||
totalScore += res.Score
|
||||
}
|
||||
return true, totalScore
|
||||
return true, totalScore, ""
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestFilterPipeline(t *testing.T) {
|
||||
pipeline := NewPipeline(hardFilter, scoringFilter)
|
||||
|
||||
// Test job 1: Unpaid job -> rejected by hard filter
|
||||
keep1, score1 := pipeline.Execute(ctx, "Backend Intern", "Unpaid position working with Go.")
|
||||
keep1, score1, _ := pipeline.Execute(ctx, "Backend Intern", "Unpaid position working with Go.")
|
||||
if keep1 {
|
||||
t.Errorf("expected job 1 to be filtered out, got keep=true")
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func TestFilterPipeline(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test job 2: Qualified job -> passes both filters and accumulates score
|
||||
keep2, score2 := pipeline.Execute(ctx, "Senior Go Backend Engineer", "Building high throughput services.")
|
||||
keep2, score2, _ := pipeline.Execute(ctx, "Senior Go Backend Engineer", "Building high throughput services.")
|
||||
if !keep2 {
|
||||
t.Errorf("expected job 2 to pass filter pipeline, got keep=false")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user