Best way to keep a long running process running until its next scheduled run time

blov · · 363 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I have a golang application that needs to run every X days or at a specific day of the month every month. This application can take days or weeks to complete and after it has completed its process it should not start again until at its next scheduled time.</p> <p>The problem I have is that sometimes the computers are restarted in the middle of the process. The application can resume correctly though.</p> <p>The issue is, what is the best way to have a schedule and have the application resume if something happens to the process?</p> <hr/> <p>Solutions I have explored: </p> <p>Used the Windows Task Scheduler in the past, but that requires me to run a second task that just starts the first task if it is stopped and has not completed. Works but is rather shitty and only works on Windows.</p> <p>Used <a href="https://github.com/robfig/cron">https://github.com/robfig/cron</a> and <a href="https://github.com/kardianos/service">https://github.com/kardianos/service</a> to create a service that runs the application according to a cron schedule. Works very well to meet the schedule requirements and helps make the application cross platform. This does not solve the problem of resuming a failed task.</p> <hr/>**评论:**<br/><br/>: <pre><p>[deleted]</p></pre>Hexodam: <pre><p>Think something similar is the best solution.</p> <p>The application process is split into three parts, the init phase, process phase and the cleanup phase. If I change it so that the init phase is done by schedule only then I can have a checker every X that checks if the if the process is running and if the cleanup is done. If the process is not running and if the cleanup is not done then the process is started again, if the process is not running and the cleanup is done then nothing is done until the next scheduled time and the init phase is done.</p> <p>The only issue left here is how to handle if the scheduled cron time is missed.</p></pre>__crackers__: <pre><blockquote> <p>The only issue left here is how to handle if the scheduled cron time is missed.</p> </blockquote> <p>cron can’t do that for you. Perhaps you could create a file containing the due date of the next run, and if that file exists and the due date has passed, run the task.</p></pre>Hexodam: <pre><p>Think that is the best way to go in my case.</p></pre>svarog: <pre><p>Add a cron/scheduler task to run on scheduled date + on server startup.</p> <p>In the application code write some logic that makes sure that it runs either if the thing failed on last run, or when it&#39;s the time of the month.</p></pre>ericzhill: <pre><p>Not exactly a Go-only solution, but Amazon&#39;s <a href="https://aws.amazon.com/swf/" rel="nofollow">SWF</a> would be ideal for this kind of system. At a prior company, we started &#34;daily workflow&#34; at midnight every day performed several tasks throughout the day. Your use case sounds exactly like a long running activity with heartbeats.</p></pre>danielfischer: <pre><p>Can you commit a pointer to a reference on where to begin again? On startup of the program it can see where it left off then begin from there. </p></pre>

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

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