The document discusses using Go language to build a distributed computing architecture with multiple machines. It covers using RabbitMQ and NSQ for queues, building a simple queue mechanism for single machine versions, and rewriting the architecture to address concurrency limits. It also discusses setting up a server-agent system with RPC communication and context cancellation to enable job cancellation.
2. About me
• Software Engineer in Mediatek
• Member of Drone CI/CD Platform
• Member of Gitea Platform
• Member of Gin Golang Framework
• Maintain Some GitHub Actions Plugins.
• Teacher of Udemy Platform: Golang + Drone
57. Watch the Cancel event (Agent)
go func() {
done, _ := r.Manager.Watch(ctx, id)
if done {
cancel()
}
}()
58. Handle cancel event on Server
subscribers: make(map[chan struct{}]int64),
cancelled: make(map[int64]time.Time),
59. User cancel running job
c.Lock()
c.cancelled[id] = time.Now().Add(time.Minute * 5)
for subscriber, build := range c.subscribers {
if id == build {
close(subscriber)
}
}
c.Unlock()
60. Agent subscribe the cancel event
for {
select {
case <-ctx.Done():
return false, ctx.Err()
case <-time.After(time.Minute):
c.Lock()
_, ok := c.cancelled[id]
c.Unlock()
if ok {
return true, nil
}
case <-subscriber:
return true, nil
}
}