gosom / google-maps-scraper

scrape data data from Google Maps. Extracts data such as the name, address, phone number, website URL, rating, reviews number, latitude and longitude, reviews,email and more for each place
MIT License
724 stars 93 forks source link

Processes never end #41

Open SegFault42 opened 3 months ago

SegFault42 commented 3 months ago

I've added this code to launch from my frontend


func worker(category, city, userResult, sec string, w http.ResponseWriter) {
if err := run(category, city, userResult+"/"+sec+".json"); err != nil {
        fmt.Println("Oops:")
        os.Stderr.WriteString(err.Error() + "\n")
    } else {
        fmt.Println("Else!")
        fmt.Fprintf(w, "event: close\n\n")
        w.(http.Flusher).Flush()
        fmt.Println("Closed")
        // panic("error")
        //saveSearchToFireStore(userResult+"/"+sec+".json", email, documentName)
    }
}

http.HandleFunc("/api/google-search", func(w http.ResponseWriter, r *http.Request) {

        //code to get parameters
    worker(category, city, userResult, sec, w,)
}

Everything is working well but for some reasons, I have 5 subprocesses that never end when the search is done.

Screenshot 2024-03-30 at 10 36 24

Any idea how I can end those processes ?

gosom commented 2 months ago

I assume your run function does the initialization of the app etc.

pass the request context there and once this context is done the processes should be cleaned up

gosom commented 1 month ago

@SegFault42 did my recommendation fixed your issue?

SegFault42 commented 1 month ago

No didn't really understand

This is my run function

Screenshot 2024-05-22 at 13 35 56

It just create the ctx and then run the runFromLocalFile function