created storage method to execute a coderef using master storage only, changed tnx_do...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Replicated / Pool.pm
index 8f0d66d..bf46823 100644 (file)
@@ -36,13 +36,32 @@ return a number of seconds that the replicating database is lagging.
 =cut
 
 has 'maximum_lag' => (
-    is=>'ro',
+    is=>'rw',
     isa=>'Num',
     required=>1,
     lazy=>1,
     default=>0,
 );
 
+=head2 last_validated
+
+This is an integer representing a time since the last time the replicants were
+validated. It's nothing fancy, just an integer provided via the perl time 
+builtin.
+
+=cut
+
+has 'last_validated' => (
+    is=>'rw',
+    isa=>'Int',
+    reader=>'last_validated',
+    writer=>'_last_validated',
+    lazy=>1,
+    default=>sub {
+        0;
+    },
+);
+
 =head2 replicant_type ($classname)
 
 Base class used to instantiate replicants that are in the pool.  Unless you
@@ -192,8 +211,8 @@ array is given, nor should any meaning be derived.
 =cut
 
 sub all_replicants {
-       my $self = shift @_;
-       return values %{$self->replicants};
+    my $self = shift @_;
+    return values %{$self->replicants};
 }
 
 =head2 validate_replicants
@@ -215,10 +234,23 @@ not recommended that you run them very often.
 =cut
 
 sub validate_replicants {
-       my $self = shift @_;
-       foreach my $replicant($self->all_replicants) {
-               
-       }
+    my $self = shift @_;
+    foreach my $replicant($self->all_replicants) {
+        if(
+            $replicant->is_replicating &&
+            $replicant->lag_behind_master <= $self->maximum_lag &&
+            $replicant->ensure_connected
+        ) {
+               ## TODO:: Hook debug for this
+            $replicant->active(1)
+        } else {
+               ## TODO:: Hook debug for this
+            $replicant->active(0);
+        }
+    }
+
+    ## Mark that we completed this validation.  
+    $self->_last_validated(time);
 }
 
 =head1 AUTHOR