-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.xml
69 lines (50 loc) · 3.11 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>RESTful Blog</title>
<link href="http://blog.restful-labs.com/atom.xml" rel="self"/>
<link href="http://blog.restful-labs.com/"/>
<updated>2011-08-23T21:45:12-04:00</updated>
<id>http://blog.restful-labs.com/</id>
<author>
<name>RESTful Labs</name>
</author>
<entry>
<title>Catching Errors in Heroku Cron Tasks</title>
<link href="http://blog.restful-labs.com/blog/2011/08/23/catching-errors-in-heroku-cron-tasks/"/>
<updated>2011-08-23T21:10:00-04:00</updated>
<id>http://blog.restful-labs.com/blog/2011/08/23/catching-errors-in-heroku-cron-tasks</id>
<content type="html"><p>Once we started integrating <a href="http://www.restfulmetrics.com">RESTful Metrics</a> into our own applications, we quickly ran into some problems with the way we were using the task to invoke other Rake tasks.</p>
<p>Our <code>cron.rake</code> looked something like this:</p>
<p>``` ruby</p>
<pre><code>desc "Heroku Cron Task"
task :cron =&gt; :environment do
Rake::Task["accounts:bill"].invoke
Rake::Task["accounts:expire"].invoke
end
</code></pre>
<p>```</p>
<p>As we needed our cron to do more, we just invoked more tasks from within the cron task.</p>
<p>The problem with this approach is that once you start stacking code in your cron task, there is a chance that one of your tasks in the stack will raise an exception and prevent the remaining tasks from being invoked. Worse, unless you check your cron logs frequently, it's likely that your developers aren't aware that these tasks are failing.</p>
<p>In our case, we had created some tasks near the end of the cron stack that sent some data points to RESTful Metrics for aggregation. On the days that our cron script encountered an exception, metrics weren't collected.</p>
<p>To fix this, we've started to wrap each individual task invocation around a begin/rescue/end block and we send the exceptions to <a href="http://airbrakeapp.com">Airbrake</a>. This means that errors generate emails to developers and an error in one task doesn't prevent the remaining tasks from running. The above cron script was re-written to:</p>
<p>``` ruby</p>
<pre><code>desc "Heroku Cron Task"
task :cron =&gt; :environment do
begin
Rake::Task["accounts:bill"].invoke
rescue
HoptoadNotifier.notify($!)
end
begin
Rake::Task["accounts:expire"].invoke
rescue
HoptoadNotifier.notify($!)
end
end
</code></pre>
<p>```</p>
<p>This is a little verbose, but it does the trick for now. Ideally there would be some method that automatically wraps each task invocation in the cron task. This would ensure developers would automatically be protected and the cron task wouldn't become bloated.</p>
<p>What do you guys do?</p>
</content>
</entry>
</feed>