[Bps-public-commit] smokingit branch, master, updated. 9a7622bb76e1a6badccf11d88a6dba6b86714244
Alex Vandiver
alexmv at bestpractical.com
Sun Dec 4 15:38:38 EST 2011
The branch, master has been updated
via 9a7622bb76e1a6badccf11d88a6dba6b86714244 (commit)
via 72447ea022911f3498e725f860423d5689c9a7df (commit)
via 03498b2ddd3ff3f6b5b2bedc951c6a5ca7cac7b4 (commit)
from 073f2e0f942b98500d8b306a929f87a8e5543119 (commit)
Summary of changes:
etc/config.yml | 2 +
lib/Smokingit.pm | 10 +++++--
lib/Smokingit/Model/Branch.pm | 2 +-
lib/Smokingit/Model/Commit.pm | 47 ++++++++++++++++++++++++-----------
lib/Smokingit/Model/SmokeResult.pm | 11 ++++++++
5 files changed, 53 insertions(+), 19 deletions(-)
- Log -----------------------------------------------------------------
commit 03498b2ddd3ff3f6b5b2bedc951c6a5ca7cac7b4
Author: Alex Vandiver <alex at chmrr.net>
Date: Sun Dec 4 15:34:07 2011 -0500
We also need the commit_id prefetched, to save on queries
diff --git a/lib/Smokingit/Model/Branch.pm b/lib/Smokingit/Model/Branch.pm
index 7821d85..6a5289a 100644
--- a/lib/Smokingit/Model/Branch.pm
+++ b/lib/Smokingit/Model/Branch.pm
@@ -233,7 +233,7 @@ sub commit_list {
name => "smoke_results",
alias => $results,
class => "Smokingit::Model::SmokeResultCollection",
- columns => [qw/id gearman_process configuration_id
+ columns => [qw/id gearman_process configuration_id commit_id
error is_ok exit wait
passed failed parse_errors todo_passed/],
);
commit 72447ea022911f3498e725f860423d5689c9a7df
Author: Alex Vandiver <alex at chmrr.net>
Date: Sun Dec 4 15:34:35 2011 -0500
Add memcached connection, for caching test statuses
diff --git a/etc/config.yml b/etc/config.yml
index 268d8c9..da58a75 100644
--- a/etc/config.yml
+++ b/etc/config.yml
@@ -32,3 +32,5 @@ framework:
application:
job_servers:
- 127.0.0.1:4730
+ memcached_servers:
+ - 127.0.0.1:11211
diff --git a/lib/Smokingit.pm b/lib/Smokingit.pm
index 8fbe9dc..de96f7c 100644
--- a/lib/Smokingit.pm
+++ b/lib/Smokingit.pm
@@ -3,14 +3,18 @@ use warnings;
package Smokingit;
use Gearman::Client;
+use Cache::Memcached;
-our $GEARMAN;
+our( $GEARMAN, $MEMCACHED );
sub start {
$GEARMAN = Gearman::Client->new;
$GEARMAN->job_servers( Jifty->config->app('job_servers') );
-}
-sub gearman { $GEARMAN }
+ $MEMCACHED = Cache::Memcached->new(
+ { servers => Jifty->config->app( 'memcached_servers' ) } );
+}
+sub gearman { $GEARMAN }
+sub memcached { $MEMCACHED }
1;
commit 9a7622bb76e1a6badccf11d88a6dba6b86714244
Author: Alex Vandiver <alex at chmrr.net>
Date: Sun Dec 4 15:36:02 2011 -0500
Cache finished test state in memcached, to save on computing it each time
diff --git a/lib/Smokingit/Model/Commit.pm b/lib/Smokingit/Model/Commit.pm
index 2314c81..3247508 100644
--- a/lib/Smokingit/Model/Commit.pm
+++ b/lib/Smokingit/Model/Commit.pm
@@ -103,6 +103,7 @@ sub status {
my $self = shift;
my $on = shift;
+ my $memcached = Smokingit->memcached;
if ($on) {
my $result = Smokingit::Model::SmokeResult->new;
if ($on->isa("Smokingit::Model::SmokeResult")) {
@@ -122,9 +123,13 @@ sub status {
die "Unknown argument to Smokingit::Model::Commit->status: $on";
}
- if (not $result->id) {
- return ("untested", "");
- } elsif ($result->gearman_process) {
+ return ("untested", "") unless $result->id;
+
+ my $cache_value = $memcached->get( $result->status_cache_key );
+ return @{$cache_value} if $cache_value;
+
+ my @return;
+ if ($result->gearman_process) {
my $status = $result->gearman_status;
if (not $status->known) {
return ("broken", "Unknown");
@@ -139,24 +144,26 @@ sub status {
return ("queued", "Queued to test");
}
} elsif ($result->error) {
- return ("errors", $result->short_error);
+ @return = ("errors", $result->short_error);
} elsif ($result->is_ok) {
- return ("passing", $result->passed . " OK")
+ @return = ("passing", $result->passed . " OK")
} elsif ($result->failed) {
- return ("failing", $result->failed . " failed");
+ @return = ("failing", $result->failed . " failed");
} elsif ($result->parse_errors) {
- return ("parsefail", $result->parse_errors . " parse errors");
+ @return = ("parsefail", $result->parse_errors . " parse errors");
} elsif ($result->exit) {
- return ("failing", "Bad exit status (".$result->exit.")");
+ @return = ("failing", "Bad exit status (".$result->exit.")");
} elsif ($result->wait) {
- return ("failing", "Bad wait status (".$result->wait.")");
+ @return = ("failing", "Bad wait status (".$result->wait.")");
} elsif ($result->todo_passed) {
- return ("todo", $result->todo_passed . " TODO passed");
+ @return = ("todo", $result->todo_passed . " TODO passed");
} else {
- return ("failing", "Unknown failure");
+ @return = ("failing", "Unknown failure");
}
- } elsif ($self->{status}) {
- return $self->{status};
+ $memcached->set( $result->status_cache_key, \@return );
+ return @return;
+ } elsif (my $cache_value = $memcached->get( $self->status_cache_key ) ) {
+ return $cache_value;
} else {
my @results;
if (exists $self->{results}) {
@@ -172,10 +179,15 @@ sub status {
my ($status) = $self->status($result);
$results{$status}++;
}
+ my $status = "untested";
for my $st (qw/broken errors failing todo passing parsefail testing queued/) {
- return $self->{status} = $st if $results{$st};
+ next unless $results{$st};
+ $status = $st;
+ last;
}
- return $self->{status} = "untested";
+ $memcached->set( $self->status_cache_key, $status)
+ unless $results{broken} or $results{testing} or $results{queued};
+ return $status;
}
}
@@ -200,5 +212,10 @@ sub parents {
return map {$self->project->sha($_)} split ' ', $self->_value('parents');
}
+sub status_cache_key {
+ my $self = shift;
+ return "status-" . $self->sha;
+}
+
1;
diff --git a/lib/Smokingit/Model/SmokeResult.pm b/lib/Smokingit/Model/SmokeResult.pm
index d4a82a9..22abb06 100644
--- a/lib/Smokingit/Model/SmokeResult.pm
+++ b/lib/Smokingit/Model/SmokeResult.pm
@@ -116,8 +116,19 @@ sub run_smoke {
}
$self->set_gearman_process($job_id);
$self->set_queued_at( Jifty::DateTime->now );
+
+ # If we had a result for this already, we need to clean its status
+ # out of the memcached cache. Remove both the cache on the commit,
+ # as well as this smoke.
+ Smokingit->memcached->delete( $self->commit->status_cache_key );
+ Smokingit->memcached->delete( $self->status_cache_key );
return 1;
}
+sub status_cache_key {
+ my $self = shift;
+ return "status-" . $self->commit->sha . "-" . $self->configuration->id;
+}
+
1;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list