Django - Cronjobs Made Easy!

August 8, 2009 3:04 pm

For those that have no interest in reading about my nerd-ventures, you can stop reading this post now.

If you're still reading, don't say I didn't warn you.

As has been mentioned previously (mainly on my previous blog), I've been doing a fair bit of side project work using the Django Framework. Sadly, the out-of-the-box Django doesn't provide a solution for running cronjobs (for tasks that need to be run within the Django environment).

Since that's a fairly common requirement I didn't think it was going to be a big deal, but there wasn't a really solid solution out there. There are a few different attempts, but they each have some limitation. There's django-cron but that just skips over the native cron entirely, which I felt was a bit extreme. Cron can already do a good job of waking up and running a command, so duplicating that functionality doesn't seem necessary. It also self-declares that it is designed for frequent tasks (hourly or more frequently), which doesn't work for me. Tasks on the Board need to be able to run from a minute scale to a daily scale and beyond.

Then I found this guy's method, which works, but I'd like a little more integration. That way when developing apps the "go add cron job" isn't a separate step. I want the job information to right in with the rest of my app information. That way I can see what should be happening and when.

That's when I came across Django-Chronograph. This solution was 95% of what I wanted. It provides a nice interface to the system to monitor your jobs and view logs. It requires only a single crontab entry. It uses the iCalendar style of task declaration so you have total control of when your jobs run. However, it is limited to running commands through the Django Management system. I wanted something a little more programmatic. Such that I could just point at whatever function I wanted for my jobs.

So I took Django-Chronograph and started my modifications. The result is Django Cron Manager. Setup is very similar to using the Admin system. You call the cron_manager.autodiscover() function from your urls.py file. This goes out and inspect your installed apps and registers any Cron Jobs they declare. Then, using the guts of Django-Chronograph, it keeps track of these jobs in the database and monitors when they need to run.

I'm planning on posting all the code with an example at some point, but I'm going to try to get in touch with Weston (the guy who wrote Django-Chronograph) to see if he just wants to roll my changes into his system permanently. If you stumble upon this post and the changes aren't in Django-Chronograph, and I haven't provided any further information. Just leave a comment that you're interested in the code with a way to contact you and I'll get something to you.

*** Update ***
I've posted the code here: http://code.google.com/p/django-chronograph/issues/detail?id=15

Ubuntu 9.04 Touchpad Scroll Region

July 25, 2009 4:26 pm

Jess has switched her laptop to Ubuntu and in the process there are some tweaks to be done. One of them was that her touchpad has a little area set apart for scrolling and the default option on Ubuntu was allowing scrolling for a small amount past that set apart area. Unfortunately, they've just updated those settings to be part of the HAL device settings rather than the Xorg.conf settings. So now there is not a nice clean GUI configuration program.

After some messing around I was able to figure it out though. You need to create an FDI policy in the directory "/etc/hal/fdi/policy". It doesn't seem to matter what you call this as long as it ends in ".fdi". So I called mine "touchpad.fdi". In this file we put:

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
<device>
<match key="input.x11_driver" string="synaptics">
 <merge key="input.x11_options.RightEdge" type="string">5900</merge>
</match>
</device>
</deviceinfo>

(For more information on how to form this file see: https://wiki.ubuntu.com/X/Config/Input.)

If you follow these instructions and things don't seem to work, you might try switching the encoding option from "ISO-8859-1" to "UTF-8".

Anyway, save that text into a file like "/etc/hal/fdi/policy/touchpad.fdi". The next step (which was left out of 99% of the information I found online and made me very frustrated) is to restart HAL:

sudo /etc/init.d/hal restart

After HAL restarts, log out and then log back in.

If it found and read your file properly something should have changed. If you want to test to see if things are working at all you can try setting the RightEdge value (5900 in the above) to something small (I'll warn you that this will probably turn your entire touchpad into a vertical scroll area, however you can do some sneakiness to recover, first you can still access a terminal by accessing your menus using ALT+F1, and you can access the shutdown menu (not the logout menu sadly) with ALT+CTRL+DEL).

You'll need to play with that value in order to get it to work for you. I tried to be clever and calculate it from some information, but it didn't work, so [shrug] just play with it. I changed things about 200 at a time which was enough of a change to notice.

I hope this helps someone out.

Franken-video-card

July 10, 2009 5:29 pm

I offered to keep my nerd-posts to my original blog, but Jess said, "If you're still going to post to your old blog, there's no reason to have a joint blog." So, I'm posting a nerdy post to start things out.

The video card in my desktop has been dying slowly over the last couple of months. I was hoping it wouldn't die on me completely, like some of my hardware (I'm looking at you laptop), until I had finished my thesis and moved. Well, it honored that request and lived not a minute longer. I got my computer out and setup so I could make some bookmark changes to my thesis so it can get approved by the electronic submission people, and the fan wouldn't spin at all.

Needing to make these changes regardless of fan operation, but not wanting to run the system without a fan on the video card I had a problem to solve. I have 2 old little fans that I took off of broken motherboards. These have been sitting in a "nerd box", as Jess refers to it, since my electronics lab Physics course. I took off the dead fan and determined that the possible replacement fans wouldn't quite fit and the electrical plugs were slightly too large. So, with some creative adjustments (cutting off the circle of plastic that goes around the outside of the fins) and a little extra force on the electrical pins I got a fan in place and it spins. I probably shouldn't be playing any graphics-intensive games until I get a new card, but I can at least make changes to my thesis and browse the web.

Here's the mess which is my video card:
Franke-video card