ThreeDotsLabs / wild-workouts-go-ddd-example

Go DDD example application. Complete project to show how to apply DDD, Clean Architecture, and CQRS by practical refactoring.
https://threedots.tech
MIT License
5.24k stars 479 forks source link

Background jobs #40

Closed Kabanets closed 3 years ago

Kabanets commented 3 years ago

Thank you for your book and sample project. Can you share your mind about the place of background workers in clear architecture? I think it may be some entities in the app module or specific commands. Anyway, this is an important point of the project. What do you think?

m110 commented 3 years ago

Hey @Kabanets!

We usually treat background processes as ports — it's essentially another entry point to the application. Most often, it's a cron port that triggers an application command on specific intervals.

It runs in a separate goroutine, just as the HTTP/gRPC servers or Pub/Sub handlers. An important point here is to treat all these goroutines as the same kind of workers. They should support cancellation (preferably by context) and graceful shutdown in response to OS signals.

Kabanets commented 3 years ago

Hi @m110 Thank you for your response. It is a good idea. I will try to realize it. We are waiting for new chapters of the book