Tell me more about the Avito project — was it the only project for three years?
Golang
func (c *Client) Send(ctx context.Context, messages []Message, maxWorkers int) error { sem := make(chan struct{}, maxWorkers) var wg sync.WaitGroup var resultErr error var once sync.Once for _, msg := range messages { wg.Add(1) go func(msg Message) { defer wg.Done() sem <- struct{}{} defer func() { <-sem }() body, err := json.Marshal(msg) if err != nil { once.Do(func() { resultErr = err; cancel() }) return } req, _ := http.NewRequestWithContext( ctx, http.MethodPost, c.url, bytes.NewReader(body), ) req.Header.Set("Content-Type", "application/json") resp, err := c.httpClient.Do(req) if err != nil { once.Do(func() { resultErr = err; cancel()}) return } defer resp.Body.Close() if resp.StatusCode >= 500 { once.Do(func() { resultErr = fmt.Errorf("server error") cancel()}) return } c.sentCount.Add(1) time.Sleep(time.Second) }(msg) } wg.Wait() }
What is the type of msg in a goroutine and why should it be passed as an argument?
/* The developer was tasked with writing a notification sending service. Requirements: - The Send method should send messages in parallel. - No more than maxworkers HTTP requests can be executed simultaneously. - If at least one send fails, stop the rest and return an error. - The method should handle context cancellation properly. - All resources should be released correctly. - The method can be called concurrently from different goroutines. - The Client should keep track of the number of successfully sent messages. Review the code, find issues, and fix it.
Where should you defer resp.Body.Close()?
Are there any agreements with other employers or are you still in interview stages?
Why is resultErr not returned directly from the goroutine?
Tell us about AllTools — why did you join and why did you leave?
What is your overall commercial experience in Go development?
Will it be comfortable to work with technical documentation in English?
What experience do you have with SQL? Can you write and optimize queries?
Where do contexts end in this code?
What are quick games?
sentCount is transmitted without synchronization — how to fix this?
What happens if you do not pass a context in a database query?
What are you looking for in a new project? What technologies interest you? What would you not want to see at a new workplace?
When will an index not help or even harm?
What stages are usually present in a CI/CD pipeline for a Go service?