LogMessageAdaptor.pm 3.33 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
20
    Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
    Copyright [2016] EMBL-European Bioinformatics Institute
21
22
23
24
25
26
27
28
29
30

    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.

31
32
=head1 CONTACT

33
    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
34
35
36
37

=cut


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

use strict;
41
use warnings;
42

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


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

50

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

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

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

58
        # Note: the timestamp 'time' column will be set automatically
59
    my $sql = qq{
60
61
62
63
64
        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=?
65
66
67
    };

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

72
73

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

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

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

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 'when_logged' 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();
}

111
112
1;