[Jifty-commit] r4733 - in jifty/trunk: lib/Jifty/Plugin

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Mon Dec 17 23:46:22 EST 2007


Author: alexmv
Date: Mon Dec 17 23:46:21 2007
New Revision: 4733

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Plugin/Monitoring.pm

Log:
 r25896 at zoq-fot-pik:  chmrr | 2007-12-17 23:44:06 -0500
  * Lockfile support


Modified: jifty/trunk/lib/Jifty/Plugin/Monitoring.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Monitoring.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/Monitoring.pm	Mon Dec 17 23:46:21 2007
@@ -52,7 +52,7 @@
 
 =cut
 
-__PACKAGE__->mk_accessors(qw/base_classes monitors now current_monitor/);
+__PACKAGE__->mk_accessors(qw/base_classes monitors now current_monitor lockfile has_lock/);
 
 our @EXPORT = qw/monitor every
                  minute minutes
@@ -194,6 +194,7 @@
     my @path = $args{path} ? @{$args{path}} : (Jifty->app_class("Monitor"));
     $self->base_classes(\@path);
     $self->monitors({});
+    $self->lockfile($args{lockfile} || "var/monitoring.pid");
     local $Jifty::Plugin::Monitoring::self = $self;
     Jifty::Module::Pluggable->import(
         require => 1,
@@ -273,6 +274,7 @@
 
 sub run_monitors {
     my $self = shift;
+    return unless $self->lock;
     my $now = Jifty::DateTime->now->truncate( to => "minute" );
     $now->set_time_zone("UTC");
     $self->now($now);
@@ -298,4 +300,19 @@
     $self->current_monitor(undef);
 }
 
+sub lock {
+    my $self = shift;
+    return if -e $self->lockfile;
+    open PID, ">", $self->lockfile;
+    print PID $$;
+    close PID;
+    $self->has_lock(1);
+    return 1;
+}
+
+sub DESTROY {
+    my $self = shift;
+    unlink $self->lockfile if $self->has_lock;
+}
+
 1;


More information about the Jifty-commit mailing list