Skip to content
Browse files

update last_fetch_* fields on success

  • Loading branch information...
1 parent ad1f386 commit b1de02918c251044922b3125b93a9329e0036ca6 @szabgab committed Sep 25, 2012
Showing with 27 additions and 10 deletions.
  1. +7 −0 lib/Dwimmer/Feed/Collector.pm
  2. +8 −0 lib/Dwimmer/Feed/DB.pm
  3. +1 −2 script/dwimmer_feed_admin.pl
  4. +11 −8 t/100_feed_collector.t
View
7 lib/Dwimmer/Feed/Collector.pm
@@ -9,6 +9,7 @@ my $MAX_SIZE = 500;
my $TRIM_SIZE = 400;
use Cwd qw(abs_path);
+use Data::Dumper qw(Dumper);
use File::Basename qw(dirname);
use File::Path qw(mkpath);
use List::Util qw(min);
@@ -72,6 +73,7 @@ sub collect {
alarm 10;
main::LOG("Processing feed");
+ #main::LOG(Dumper $e);
main::LOG("$INDENT $e->{feed}");
main::LOG("$INDENT Title by us : $e->{title}");
$feed = XML::Feed->parse(URI->new($e->{feed}));
@@ -80,10 +82,12 @@ sub collect {
alarm 0;
if ($err) {
main::LOG(" EXCEPTION: $err");
+ $self->db->update_last_fetch($e->{id}, 'fail', $err);
next;
}
if (not $feed) {
main::LOG(" ERROR: " . XML::Feed->errstr);
+ $self->db->update_last_fetch($e->{id}, 'fail', XML::Feed->errstr);
next;
}
if ($feed->title) {
@@ -131,7 +135,10 @@ sub collect {
main::LOG(" EXCEPTION: $@");
}
}
+ $self->db->update_last_fetch($e->{id}, 'success', '');
}
+
+ return;
}
# should be in its own class?
View
8 lib/Dwimmer/Feed/DB.pm
@@ -133,6 +133,14 @@ sub get_source_by_id {
return $s;
}
+sub update_last_fetch {
+ my ($self, $source_id, $status, $error) = @_;
+ my $sql = qq{UPDATE sources SET last_fetch_time=?, last_fetch_status=?, last_fetch_error=? WHERE id=?};
+ $self->dbh->do($sql, undef, time(), $status, $error, $source_id);
+
+ return;
+}
+
sub update {
my ($self, $id, $field, $value) = @_;
View
3 script/dwimmer_feed_admin.pl
@@ -118,8 +118,7 @@ sub setup {
site_id INTEGER NOT NULL,
last_fetch_time VARCHAR(10),
last_fetch_status VARCHAR(10),
- last_fetch_content BLOB,
- last_fetch_erro BLOB,
+ last_fetch_error BLOB,
CONSTRAINT url_site UNIQUE (url, site_id),
CONSTRAINT feed_site UNIQUE (feed, site_id),
FOREIGN KEY (site_id) REFERENCES sites(id)
View
19 t/100_feed_collector.t
@@ -29,8 +29,7 @@ my @sources = (
'url' => 'http://beer.com/',
'last_fetch_time' => undef,
'last_fetch_status' => undef,
- 'last_fetch_content' => undef,
- 'last_fetch_erro' => undef,
+ 'last_fetch_error' => undef,
},
{
'site_id' => 1,
@@ -43,8 +42,7 @@ my @sources = (
'url' => 'http://vodka.com/',
'last_fetch_time' => undef,
'last_fetch_status' => undef,
- 'last_fetch_content' => undef,
- 'last_fetch_erro' => undef,
+ 'last_fetch_error' => undef,
},
);
my @sources2 = (
@@ -59,8 +57,7 @@ my @sources2 = (
'url' => 'http://burger.com/',
'last_fetch_time' => undef,
'last_fetch_status' => undef,
- 'last_fetch_content' => undef,
- 'last_fetch_erro' => undef,
+ 'last_fetch_error' => undef,
},
);
@@ -396,16 +393,22 @@ $disabled->{status} = 'disabled';
}
my $disabled = clone($sources[0]);
$disabled->{status} = 'disabled';
+ $sources[1]{last_fetch_error} = '';
+ $sources[1]{last_fetch_status} = 'success';
+ $sources[1]{last_fetch_time} = re('\d{10}');
{
my ($out, $err) = capture { system "$^X script/dwimmer_feed_admin.pl --store $store --listsource --site 1" };
my $data = check_dump($out);
- is_deeply $data, [ $disabled, $sources[1] ], 'listed correctly' or diag $out;
+ cmp_deeply $data, [ $disabled, $sources[1] ], 'listed correctly' or diag $out;
is $err, '', 'no STDERR';
}
+ $sources2[0]{last_fetch_error} = '';
+ $sources2[0]{last_fetch_status} = 'success';
+ $sources2[0]{last_fetch_time} = re('\d{10}');
{
my ($out, $err) = capture { system "$^X script/dwimmer_feed_admin.pl --store $store --listsource --site 2" };
my $data = check_dump($out);
- is_deeply $data, [ $sources2[0] ], 'listed correctly' or diag $out;
+ cmp_deeply $data, [ $sources2[0] ], 'listed correctly' or diag $out;
is $err, '', 'no STDERR';
}

0 comments on commit b1de029

Please sign in to comment.
Something went wrong with that request. Please try again.