jobs-monorepo/services/linked-scraper/pipeline/job_pipeline.go
Elshimy Ziad Magdy Taha 0ab6954231 feat: add job analysis infrastructure and Glassdoor support
- Added new job analysis result repository and database migration system
- Expanded job creation to support Glassdoor as a new provider alongside LinkedIn
- Added CV analysis service launch configuration in VS Code
- Updated Makefile with new commands for scraper service and migrations
- Improved environment loading in cron analyzer to support local development
- Added error handling for unsupported job providers
- Integrated job analysis results
2025-10-24 15:10:20 +05:00

65 lines
1.9 KiB
Go

package pipeline
import (
"context"
"fmt"
// "log"
"sync"
"time"
"github.com/jobs-scraper/shared/domain"
"github.com/jobs-scraper/shared/repo"
)
// JobDescriptionResult represents the result of job description scraping
type JobDescriptionResult struct {
Job domain.Job
Description string
Criteria map[string]string
Error error
}
// JobPipeline manages the job processing pipeline
type JobPipeline struct {
scraperService *Scraper
numWorkers int
rateLimit time.Duration
}
// NewJobPipeline creates a new job processing pipeline
func NewJobPipeline(scraperService *Scraper, numWorkers int, rateLimit time.Duration) *JobPipeline {
return &JobPipeline{
scraperService: scraperService,
numWorkers: numWorkers,
rateLimit: rateLimit,
}
}
// ProcessJobsStreaming processes jobs and job descriptions concurrently
func (p *JobPipeline) ProcessJobsStreaming(ctx context.Context, jobRepo *repo.JobRepository, jobDescRepo *repo.JobDescriptionRepository, searchQuery domain.SearchQuery) error {
allJobs := make([]domain.Job, 0, 100)
allJobDescriptions := make([]domain.JobDescription, 0, 100)
var jbMu sync.Mutex
jobsChan := GetJobs(ctx, p.scraperService, searchQuery)
jobWithDescriptionChan := GetJobDescription(ctx, p.scraperService, jobsChan, p.numWorkers)
for jobWithDescription := range jobWithDescriptionChan {
fmt.Printf("Received job description for job : %d\n", jobWithDescription.Job.ID)
jbMu.Lock()
allJobs = append(allJobs, jobWithDescription.Job)
allJobDescriptions = append(allJobDescriptions, jobWithDescription.JobDescription)
jbMu.Unlock()
}
if err := jobRepo.SaveJobs(allJobs); err != nil {
return fmt.Errorf("failed to save jobs to database: %w", err)
}
if err := jobDescRepo.SaveJobDescriptions(allJobDescriptions); err != nil {
return fmt.Errorf("failed to save job descriptions: %w", err)
}
return nil
}