Question about background processes.

blov · · 459 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>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.</p> <p>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.</p> <p>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.</p> <p>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?</p> <p>Or should I use a task queue like gocraft/work or <a href="https://github.com/RichardKnop/machinery" rel="nofollow">https://github.com/RichardKnop/machinery</a>. Both these tools require a redis backend and I felt that they might be an overkill for a small project.</p> <p>I&#39;d appreciate your inputs.</p> <hr/>**评论:**<br/><br/>cjbprime: <pre><p>The smallest possible change would be:</p> <ul> <li><p>Make the goroutine write a timestamp to the DB when it has sent an email</p></li> <li><p>Make the goroutine check all rows without a timestamp and try to send email for them, each time it runs</p></li> </ul> <p>Guarantees no more than one message, and failed goroutine get retried later.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

459 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传