Index: /branches/release-38/lib/MT/TheSchwartz.pm
===================================================================
--- /branches/release-38/lib/MT/TheSchwartz.pm (revision 2272)
+++ /branches/release-38/lib/MT/TheSchwartz.pm (revision 2315)
@@ -86,23 +86,4 @@
     TheSchwartz::Error->properties->{datasource}      = 'ts_error';
     TheSchwartz::ExitStatus->properties->{datasource} = 'ts_exitstatus';
-
-    my $job_set_exit_status = \&TheSchwartz::Job::set_exit_status;
-    my $job_add_failure = \&TheSchwartz::Job::add_failure;
-
-    my $driver = MT::Object->driver;
-    no warnings 'redefine';
-    *TheSchwartz::Job::set_exit_status = sub {
-        $driver->Disabled(1);
-        my $res = $job_set_exit_status->(@_);
-        $driver->Disabled(0);
-        return $res;
-    };
-    *TheSchwartz::Job::add_failure = sub {
-        $driver->Disabled(1);
-        my $res = $job_add_failure->(@_);
-        $driver->Disabled(0);
-        return $res;
-    };
-
     return $initialized = 1;
 }
@@ -110,5 +91,5 @@
 sub driver_for {
     my MT::TheSchwartz $client = shift;
-    return MT::Object->driver;
+    return MT::Object->dbi_driver;
 }
 
@@ -147,11 +128,16 @@
     $delay ||= 5;
     my $last_task_run = 0;
+    my $did_work = 0;
     while (1) {
-        unless ($client->work_once) {
-            my $driver = $client->driver_for();
-            $driver->clear_cache
-                if $driver->can('clear_cache');
-            MT->request->reset();
-            sleep $delay;
+        if ($client->work_once) {
+            $did_work = 1;
+        } else {
+            if ($did_work) {
+                my $driver = MT::Object->driver;
+                $driver->clear_cache
+                    if $driver->can('clear_cache');
+                MT->request->reset();
+                $did_work = 0;
+            }
 
             if ($last_task_run + 60 * 5 < time) {
@@ -160,4 +146,5 @@
             }
         }
+        sleep $delay;
     }
 }
