/
index.html
501 lines (362 loc) · 19.5 KB
/
index.html
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>OpenShift Cron Takes Over Celerybeat</title>
<meta name="author" content="Alexander Todorov">
<meta name="description" content="Celery is an asynchronous task queue/job queue
based on distributed message passing. You can define tasks as Python functions,
execute them in the …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="http://atodorov.org/blog/2012/03/14/openshift-cron-takes-over-celerybeat/">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="/javascripts/ender.js"></script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>
<link href="http://feeds.feedburner.com/atodorov" rel="alternate" title="atodorov.org - you can logoff, but you can never leave" type="application/atom+xml">
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Russo+One" rel="stylesheet" type="text/css" />
<meta name="google-site-verification" content="XynqZtldWNBbmsynVQZremIxaaO8Wgs6AGR8UZ7KIkM" />
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-37979549-1', 'atodorov.org');
ga('send', 'pageview');
</script>
</head>
<body >
<header role="banner"><hgroup>
<div id="logo-container">
<div id="logo">atodorov.org</div>
<div id="logo-sub"><em>
you can logoff, but you can never leave
</em></div>
</div>
</hgroup>
</header>
<nav role="navigation"><ul class="subscription" data-subscription="rss">
<li><a href="http://feeds.feedburner.com/atodorov" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
</ul>
<ul class="main-navigation">
<li><a href="/">Home</a></li>
<li><a href="/give-away/">Give Away List</a></li>
<li><a href="/projects/">Projects</a></li>
<li><a href="/domains/">Domains</a></li>
<li><a href="http://amzn.to/1wTPaLe">Previous: Traction</a></li>
<li><a href="http://amzn.to/1lLi5NU">Previous: How to Win Friends</a></li>
</ul>
</nav>
<div id="main">
<div id="content">
<div>
<article class="hentry" role="article">
<header>
<h1 class="entry-title">OpenShift Cron Takes Over Celerybeat</h1>
<p class="meta">
<time datetime="2012-03-14T20:48:00+02:00" pubdate data-updated="true">Mar 14<span>th</span>, 2012</time>
| <a href="#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p><a href="http://celeryproject.org/"><em>Celery</em></a> is an asynchronous task queue/job queue
based on distributed message passing. You can define tasks as Python functions,
execute them in the background and in a periodic fashion.
<a href="http://www.dif.io"><em>Difio</em></a> uses <em>Celery</em> for virtually everything.
Some of the tasks are scheduled after some event takes place (like user pressed a button)
or scheduled periodically.</p>
<p><em>Celery</em> provides several components of which <em>celerybeat</em> is the periodic task scheduler.
When combined with <a href="http://djangoproject.com"><em>Django</em></a> it gives you a very nice admin interface
which allows periodic tasks to be added to the scheduler.</p>
<h2>Why change</h2>
<p><em>Difio</em> has relied on <em>celerybeat</em> for a couple of months. Back then, when <em>Difio</em> launched,
there was no cron support for OpenShift so running <em>celerybeat</em> sounded reasonable.
It used to run on a dedicated virtual server and for most of the time that was fine.</p>
<p>There were a number of issues which <em>Difio</em> faced during its first months:</p>
<ul>
<li><p><em>celerybeat</em> would sometime die due to no free memory on the virtual instance.
When that happened no new tasks were scheduled and data was left unprocessed.
Let alone that higher memory instance and the processing power which comes with it
cost extra money.</p></li>
<li><p><em>Difio</em> is split into several components which need to have the same code base
locally - the most important are database settings and the periodic tasks
code. At least in one occasion <em>celerybeat</em> failed to start because of a buggy
task code. The offending code was fixed in the application server on OpenShift but
not properly synced to the <em>celerybeat</em> instance. Keeping code in sync is a priority
for distributed projects which rely on <em>Celery</em>.</p></li>
<li><p><em>Celery</em> and <em>django-celery</em> seem to be updated quite often. This poses a significant risk
of ending up with different versions on the scheduler, worker nodes and the app server. This will
bring the whole application to a halt if at some point a backward incompatible change is introduced
and not properly tested and updated. Keeping infrastructure components in sync can be a big challenge
and I try to minimize this effort as much as possible.</p></li>
<li><p>Having to navigate to the admin pages every time I add a new task or want to change the execution
frequency doesn’t feel very natural for a console user like myself and IMHO is less productive.
For the record I primarily use <em>mcedit</em>. I wanted to have something more close to the
write, commit and push work-flow.</p></li>
</ul>
<h2>The take over</h2>
<p>It’s been some time since OpenShift
<a href="https://www.redhat.com/openshift/community/blogs/getting-started-with-cron-jobs-on-openshift">introduced</a>
the cron cartridge and I decided to give it a try.</p>
<p>The first thing I did is to write a simple script which can execute any task from the difio.tasks module
by piping it to the Django shell (a Python shell actually).</p>
<figure class='code'><figcaption><span>run_celery_task </span></figcaption>
<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="c">#!/bin/bash</span>
</span><span class='line'><span class="c">#</span>
</span><span class='line'><span class="c"># Copyright (c) 2012, Alexander Todorov <atodorov@nospam.otb.bg></span>
</span><span class='line'><span class="c">#</span>
</span><span class='line'><span class="c"># This script is symlinked to from the hourly/minutely, etc. directories</span>
</span><span class='line'><span class="c">#</span>
</span><span class='line'><span class="c"># SYNOPSIS</span>
</span><span class='line'><span class="c">#</span>
</span><span class='line'><span class="c"># ./run_celery_task cron_search_dates</span>
</span><span class='line'><span class="c">#</span>
</span><span class='line'><span class="c"># OR</span>
</span><span class='line'><span class="c">#</span>
</span><span class='line'><span class="c"># ln -s run_celery_task cron_search_dates</span>
</span><span class='line'><span class="c"># ./cron_search_dates</span>
</span><span class='line'><span class="c">#</span>
</span><span class='line'>
</span><span class='line'><span class="nv">TASK_NAME</span><span class="o">=</span><span class="nv">$1</span>
</span><span class='line'><span class="o">[</span> -z <span class="s2">"$TASK_NAME"</span> <span class="o">]</span> <span class="o">&&</span> <span class="nv">TASK_NAME</span><span class="o">=</span><span class="k">$(</span>basename <span class="nv">$0</span><span class="k">)</span>
</span><span class='line'>
</span><span class='line'><span class="k">if</span> <span class="o">[</span> -n <span class="s2">"$OPENSHIFT_APP_DIR"</span> <span class="o">]</span>; <span class="k">then</span>
</span><span class='line'><span class="k"> </span><span class="nb">source</span> <span class="nv">$OPENSHIFT_APP_DIR</span>/virtenv/bin/activate
</span><span class='line'> <span class="nb">export </span><span class="nv">PYTHON_EGG_CACHE</span><span class="o">=</span><span class="nv">$OPENSHIFT_DATA_DIR</span>/.python-eggs
</span><span class='line'> <span class="nv">REPO_DIR</span><span class="o">=</span><span class="nv">$OPENSHIFT_REPO_DIR</span>
</span><span class='line'><span class="k">else</span>
</span><span class='line'><span class="k"> </span><span class="nv">REPO_DIR</span><span class="o">=</span><span class="k">$(</span>dirname <span class="nv">$0</span><span class="k">)</span><span class="s2">"/../../.."</span>
</span><span class='line'><span class="k">fi</span>
</span><span class='line'>
</span><span class='line'><span class="nb">echo</span> <span class="s2">"import difio.tasks; difio.tasks.$TASK_NAME.delay()"</span> | <span class="nv">$REPO_DIR</span>/wsgi/difio/manage.py shell
</span></code></pre></td></tr></table></div></figure>
<p>This is a multicall script which allows symlinks with different names to point to it.
Thus to add a new task to cron I just need to make a symlink to the script from one of the
hourly/, minutely/, daily/, etc. directories under cron/.</p>
<p>The script accepts a parameter as well which allows me to execute it locally for debugging purposes
or to schedule some tasks out of band.
This is how it looks like on the file system:</p>
<pre><code>$ ls -l .openshift/cron/hourly/
some_task_name -> ../tasks/run_celery_task
another_task -> ../tasks/run_celery_task
</code></pre>
<p>After having done these preparations I only had to embed the cron cartridge and git push to OpenShift:</p>
<pre><code>rhc-ctl-app -a difio -e add-cron-1.4 && git push
</code></pre>
<h2>What’s next</h2>
<p>At present OpenShift can schedule your jobs every minute, hour, day, week or month and does so using the
<em>run-parts</em> script. You can’t schedule a script to execute at 4:30 every Monday or every 45 minutes for example.
See <a href="https://bugzilla.redhat.com/show_bug.cgi?id=803485">rhbz #803485</a> if you want to follow the
progress. Luckily <em>Difio</em> doesn’t use this sort of job scheduling for the moment.</p>
<p><em>Difio</em> is scheduling periodic tasks from OpenShift cron for a few days already.
It seems to work reliably and with no issues. One less component to maintain and worry about.
More time to write code.</p>
</div>
<footer>
<p class="meta">
<span class="byline author vcard">Posted by <span class="fn">Alexander Todorov</span></span>
<time datetime="2012-03-14T20:48:00+02:00" pubdate data-updated="true">Mar 14<span>th</span>, 2012</time>
<span class="categories">
<a class='category' href='/blog/categories/openshift/'>OpenShift</a>, <a class='category' href='/blog/categories/cloud/'>cloud</a>, <a class='category' href='/blog/categories/tips/'>tips</a>
</span>
</p>
<div class="sharing">
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style addthis_32x32_style">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_preferred_5"></a>
<a class="addthis_button_preferred_6"></a>
<a class="addthis_button_preferred_7"></a>
<a class="addthis_button_preferred_8"></a>
<a class="addthis_button_preferred_9"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5103cc5a2bc6ba17"></script>
<!-- AddThis Button END -->
</div>
<p class="meta">
<a class="basic-alignment left" href="/blog/2012/03/09/how-to-get-to-the-openshift-shell/" title="Previous Post: Tip: How to Get to the OpenShift Shell">« Tip: How to Get to the OpenShift Shell</a>
<a class="basic-alignment right" href="/blog/2012/04/17/using-openshift-as-amazon-cloudfront-origin-server/" title="Next Post: Using OpenShift as Amazon CloudFront Origin Server">Using OpenShift as Amazon CloudFront Origin Server »</a>
</p>
</footer>
</article>
<section>
<h1>Comments</h1>
<div id="disqus_thread" aria-live="polite"><noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
</section>
</div>
<aside class="sidebar">
<section>
<p>
I am a QA contractor at Red Hat responsible for over
<a href="/blog/2014/02/19/7-years-1400-bugs-red-hat-qa/">1500 bugs</a>,
a general purpose open source developer, Red Hat Certified professional,
cloud hacker and an <a href="/projects/">entrepreneur</a>.
</p>
<p>
I'm living in the <a href="http://planet.sofiavalley.com">Sofia Valley</a>
which is emerging as a busy place for start-up founders and tech enthusiasts
in Eastern Europe! You can find more about me <a href="/about/">here</a>.
</p>
</section>
<section>
<a href="http://twitter.com/atodorov_" class="twitter-follow-button" data-show-count="true">Follow @atodorov_</a>
</section>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="sitesearch" value="atodorov.org" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<section>
<h1>
<a href="/blog/categories/books/">Book Reviews</a>
</h1>
</section>
<section>
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="/blog/2015/07/27/call-for-ideas-graphical-test-coverage-reports/">Call for Ideas: Graphical Test Coverage Reports</a>
</li>
<li class="post">
<a href="/blog/2015/07/01/open-data-event-coming-to-sofia/">Open Data Event Coming to Sofia</a>
</li>
<li class="post">
<a href="/blog/2015/05/22/devit-conf-2015-impressions/">DEVit Conf 2015 Impressions</a>
</li>
<li class="post">
<a href="/blog/2015/05/20/free-software-testing-books/">Free Software Testing Books</a>
</li>
<li class="post">
<a href="/blog/2015/05/13/why-does-sysctl-not-write-under-slash-sys/">Why does sysctl not write under /sys</a>
</li>
<li class="post">
<a href="/blog/2015/05/05/using-usb-to-vga-adapter-on-macbook-air-with-linux/">Using USB to VGA Adapter on MacBook Air with Linux</a>
</li>
<li class="post">
<a href="/blog/2015/05/04/thunderbolt-to-ethernet-adapter-on-linux/">Thunderbolt to Ethernet Adapter on Linux</a>
</li>
<li class="post">
<a href="/blog/2015/05/01/compiling-twinkle-sip-phone-on-rhel-7/">Compiling Twinkle SIP Phone on RHEL 7</a>
</li>
<li class="post">
<a href="/blog/2015/04/30/fixing-tilde-and-function-keys-mapping-for-macbook-air-on-linux/">Fixing Tilde and Function Keys Mapping for MacBook Air on Linux</a>
</li>
<li class="post">
<a href="/blog/2015/04/29/rhel-7-repository-for-macbook-air/">RHEL 7 Repository for MacBook Air</a>
</li>
</ul>
</section>
<section>
<h1>Disclaimer</h1>
<p>
Some of the links contained within this site have my referral id (e.g., Amazon), which provides me with a small commission for each sale. Thank you for your support.
</p>
</section>
</aside>
</div>
</div>
<footer role="contentinfo"><p>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_US">CC-BY-SA</a>
&
<a rel="license" href="http://opensource.org/licenses/MIT">MIT</a>
2011-2015 ♦ Alexander Todorov
♦
<a href="/about/">About Me</a>
♦
Popular categories:
<a href="/blog/categories/rhel/">Red Hat</a>,
<a href="/blog/categories/cloud/">Cloud</a>,
<a href="/blog/categories/fedora/">Fedora</a>,
<a href="/blog/categories/qa/">QA</a>,
<a href="/blog/categories/start-up/">Start-up</a>
<a href="http://planet.sofiavalley.com" style="float:right">SofiaValley Blog</a>
</p>
<script type="text/javascript">
var uri = window.location.toString();
if (uri.indexOf("?") > 0) {
var clean_uri = uri.substring(0, uri.indexOf("?"));
window.history.replaceState({}, document.title, clean_uri);
}
</script>
</footer>
<script type="text/javascript">
var disqus_shortname = 'atodorov';
// var disqus_developer = 1;
var disqus_identifier = 'http://atodorov.org/blog/2012/03/14/openshift-cron-takes-over-celerybeat/';
var disqus_url = 'http://atodorov.org/blog/2012/03/14/openshift-cron-takes-over-celerybeat/';
var disqus_script = 'embed.js';
(function () {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
}());
</script>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#appId=212934732101925&xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<script type="text/javascript">
(function() {
var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true;
script.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(script, s);
})();
</script>
<script type="text/javascript">
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>
</body>
</html>