Ping? PONG!

After the exhausing nightmare of working with cron, I was finally able to really get to work on my queue system. The first part is a simple ping request. This is where someone sees that their drop-box is not active, and they want the web server to talk to it to see if it’s still running. The server get’s the request from the end-user and schedules for the dropbox to be contacted in a moment. A worker process later finds the request to ping the dropbox and moves forward with the task. The process may fail, so it’s scheduled to try again in a few minutes until it is successful, or it had failed for one too many times.

It sounds simple, and it may be simple for some folks. I continued to run into various problems throughout the day. Coding can seem like a continuous struggle at times, and hardly much of actually moving along. Is that desire to solve a problem that excites me though. Once I figure out the answer to a problem, it feels very gratifying.

So the main issue is that I continued to run into one problem after the next. I was able to monitor my log4php interface to keep an eye on what was failing. The hardest part to keep on top of is when code doesn’t compile, as those methods are not logged. I’ve also figured out how to dynamically load different classes to handle different worker processes using a create_function method like so:

if(file_exists($filename)){
include_once($filename);
if(class_exists($classname)) {
$f = create_function(‘$a, $b, $c, $d, $e’, ‘return new ‘.$classname.'($a, $b, $c, $d, $e);’);
$worker = $f($id, $name, $context, $attempts, $db);
$worker->work();
}
else {
trigger_error(“Unable to load class: $classname”, E_USER_WARNING);
}
}
else {trigger_error(“Unable to load file: $filename”, E_USER_WARNING);
}

Other problems came up with how I log arguments in the stack trace for objects. My database object was in there and started throwing an exception. I tried serializing it, but the PDO object that it encapsulates also yelled at me. In the end, I created a __toString method that worked fine. I also did some checks to sniff out objects to see if they reflect the __toString method, otherwise I don’t write them out.

I also got my HTTP requests generalized into one method call rather than copy/pasting code everywhere. It helps with debugging/fixing problems in one place later and avoids spaghetti code.

Next is requesting dropboxes to report (easy), then some complex logic for deliveries. Joy.

posted by Dedric Mauriac on Style and Elegance using a blogHUD : [blogHUD permalink]

Comments are closed.

%d bloggers like this: