I am writing my first web application in Go. It is a simple SEO tool that will analyse web pages and send an email report with ideas for improvement.
I want to implement the parsing + sending-emails logic in a background process and I was wondering what is the best way to handle it.
Here is how I am currently doing it - As soon as the user submits a form with the URL, store it in the database and render a response. Then create a new go routine and call the extract+email function in that go routine.
But I think this approach is naive. It does not take into account failures that happen in the go routine. Is there a better way to implement this? How can I retry failures?
Or should I use a task queue like gocraft/work or https://github.com/RichardKnop/machinery. Both these tools require a redis backend and I felt that they might be an overkill for a small project.
I'd appreciate your inputs.
评论:
cjbprime:
The smallest possible change would be:
Make the goroutine write a timestamp to the DB when it has sent an email
Make the goroutine check all rows without a timestamp and try to send email for them, each time it runs
Guarantees no more than one message, and failed goroutine get retried later.
