Changeset 2315

Show
Ignore:
Timestamp:
05/13/08 17:43:51 (21 months ago)
Author:
bchoate
Message:

Use DBI driver (non-caching) for TheSchwartz itself. Optimized daemon loop so it clears caches only when work was done.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-38/lib/MT/TheSchwartz.pm

    r2272 r2315  
    8686    TheSchwartz::Error->properties->{datasource}      = 'ts_error'; 
    8787    TheSchwartz::ExitStatus->properties->{datasource} = 'ts_exitstatus'; 
    88  
    89     my $job_set_exit_status = \&TheSchwartz::Job::set_exit_status; 
    90     my $job_add_failure = \&TheSchwartz::Job::add_failure; 
    91  
    92     my $driver = MT::Object->driver; 
    93     no warnings 'redefine'; 
    94     *TheSchwartz::Job::set_exit_status = sub { 
    95         $driver->Disabled(1); 
    96         my $res = $job_set_exit_status->(@_); 
    97         $driver->Disabled(0); 
    98         return $res; 
    99     }; 
    100     *TheSchwartz::Job::add_failure = sub { 
    101         $driver->Disabled(1); 
    102         my $res = $job_add_failure->(@_); 
    103         $driver->Disabled(0); 
    104         return $res; 
    105     }; 
    106  
    10788    return $initialized = 1; 
    10889} 
     
    11091sub driver_for { 
    11192    my MT::TheSchwartz $client = shift; 
    112     return MT::Object->driver; 
     93    return MT::Object->dbi_driver; 
    11394} 
    11495 
     
    147128    $delay ||= 5; 
    148129    my $last_task_run = 0; 
     130    my $did_work = 0; 
    149131    while (1) { 
    150         unless ($client->work_once) { 
    151             my $driver = $client->driver_for(); 
    152             $driver->clear_cache 
    153                 if $driver->can('clear_cache'); 
    154             MT->request->reset(); 
    155             sleep $delay; 
     132        if ($client->work_once) { 
     133            $did_work = 1; 
     134        } else { 
     135            if ($did_work) { 
     136                my $driver = MT::Object->driver; 
     137                $driver->clear_cache 
     138                    if $driver->can('clear_cache'); 
     139                MT->request->reset(); 
     140                $did_work = 0; 
     141            } 
    156142 
    157143            if ($last_task_run + 60 * 5 < time) { 
     
    160146            } 
    161147        } 
     148        sleep $delay; 
    162149    } 
    163150}