LogMessageAdaptor.pm 3.26 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, $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
=head1 LICENSE

19
    Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
20 21 22 23 24 25 26 27 28 29

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License
    is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and limitations under the License.

30 31
=head1 CONTACT

32
    Please subscribe to the Hive mailing list:  http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users  to discuss Hive-related questions or to be notified of our updates
33 34 35 36

=cut


37
package Bio::EnsEMBL::Hive::DBSQL::LogMessageAdaptor;
38 39

use strict;
40
use warnings;
41

42
use base ('Bio::EnsEMBL::Hive::DBSQL::NakedTableAdaptor');
43 44 45


sub default_table_name {
46
    return 'log_message';
47 48
}

49

50
sub store_job_message {
51
    my ($self, $job_id, $msg, $is_error) = @_;
52

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

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

57
        # Note: the timestamp 'time' column will be set automatically
58
    my $sql = qq{
59 60 61 62 63
        INSERT INTO $table_name (job_id, role_id, worker_id, retry, status, msg, is_error)
                           SELECT job_id, role_id, worker_id, retry_count, status, ?, ?
                             FROM job
                             JOIN role USING(role_id)
                            WHERE job_id=?
64 65 66
    };

    my $sth = $self->prepare( $sql );
67
    $sth->execute( $msg, $is_error ? 1 : 0, $job_id );
68 69 70
    $sth->finish();
}

71 72

sub store_worker_message {
73 74 75 76
    my ($self, $worker, $msg, $is_error) = @_;

    my $worker_id = $worker->dbID;
    my $role_id   = $worker->current_role && $worker->current_role->dbID;
77 78 79 80 81 82 83

    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{
84 85
        INSERT INTO $table_name (worker_id, role_id, status, msg, is_error)
                           SELECT worker_id, ?, status, ?, ?
86 87 88
                             FROM worker WHERE worker_id=?
    };
    my $sth = $self->prepare( $sql );
89
    $sth->execute( $role_id, $msg, $is_error ? 1 : 0, $worker_id );
90 91 92
    $sth->finish();
}

93

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
sub store_hive_message {
    my ($self, $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 (status, msg, is_error) VALUES ('UNKNOWN', ?, ?)
    };
    my $sth = $self->prepare( $sql );
    $sth->execute( $msg, $is_error ? 1 : 0 );
    $sth->finish();
}

1;