LogMessageAdaptor.pm 1.84 KB
Newer Older
1
2
3
4
=pod

=head1 NAME

5
    Bio::EnsEMBL::Hive::DBSQL::LogMessageAdaptor
6
7
8

=head1 SYNOPSIS

9
    $dba->get_LogMessageAdaptor->store_job_message($job_id, $msg, $is_error);
10

11
    $dba->get_LogMessageAdaptor->store_worker_message($worker_id, $msg, $is_error);
12
13
14

=head1 DESCRIPTION

15
    This is currently an "objectless" adaptor that helps to store either warning-messages or die-messages generated by jobs
16
17
18
19
20
21
22
23

=head1 CONTACT

    Please contact ehive-users@ebi.ac.uk mailing list with questions/suggestions.

=cut


24
package Bio::EnsEMBL::Hive::DBSQL::LogMessageAdaptor;
25
26
27

use strict;

28
use base ('Bio::EnsEMBL::Hive::DBSQL::NakedTableAdaptor');
29
30
31


sub default_table_name {
32
    return 'log_message';
33
34
}

35

36
sub store_job_message {
37
    my ($self, $job_id, $msg, $is_error) = @_;
38

39
    chomp $msg;   # we don't want that last "\n" in the database
40

41
42
    my $table_name = $self->table_name();

43
        # Note: the timestamp 'time' column will be set automatically
44
    my $sql = qq{
45
        INSERT INTO $table_name (job_id, worker_id, retry, status, msg, is_error)
46
                           SELECT job_id, worker_id, retry_count, status, ?, ?
47
                             FROM job WHERE job_id=?
48
49
50
    };

    my $sth = $self->prepare( $sql );
51
    $sth->execute( $msg, $is_error ? 1 : 0, $job_id );
52
53
54
    $sth->finish();
}

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

sub store_worker_message {
    my ($self, $worker_id, $msg, $is_error) = @_;

    chomp $msg;   # we don't want that last "\n" in the database

    my $table_name = $self->table_name();

        # Note: the timestamp 'time' column will be set automatically
    my $sql = qq{
        INSERT INTO $table_name (worker_id, status, msg, is_error)
                           SELECT worker_id, status, ?, ?
                             FROM worker WHERE worker_id=?
    };
    my $sth = $self->prepare( $sql );
    $sth->execute( $msg, $is_error ? 1 : 0, $worker_id );
    $sth->finish();
}

74
75
1;