ensembl-hive  2.8.1
LogMessageAdaptor.pm
Go to the documentation of this file.
1 =pod
2 
3 =head1 NAME
4 
6 
7 =head1 SYNOPSIS
8 
9  $dba->get_LogMessageAdaptor->store_job_message($job_id, $msg, $message_class);
10 
11  $dba->get_LogMessageAdaptor->store_worker_message($worker, $msg, $message_class);
12 
13  $dba->get_LogMessageAdaptor->store_hive_message($msg, $message_class);
14 
15  $dba->get_LogMessageAdaptor->store_beekeeper_message($beekeeper_id, $msg, $message_class, $status);
16 
17 =head1 DESCRIPTION
18 
19  This is currently an "objectless" adaptor that helps to store either warning-messages or die-messages generated by jobs
20 
21 =head1 LICENSE
22 
23  See the NOTICE file distributed with this work for additional information
24  regarding copyright ownership.
25 
26  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
27  You may obtain a copy of the License at
28 
29  http://www.apache.org/licenses/LICENSE-2.0
30 
31  Unless required by applicable law or agreed to in writing, software distributed under the License
32  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33  See the License for the specific language governing permissions and limitations under the License.
34 
35 =head1 CONTACT
36 
37  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
38 
39 =cut
40 
41 
42 package Bio::EnsEMBL::Hive::DBSQL::LogMessageAdaptor;
43 
44 use strict;
45 use warnings;
46 
47 use base ('Bio::EnsEMBL::Hive::DBSQL::NakedTableAdaptor');
48 
49 
50 sub default_table_name {
51  return 'log_message';
52 }
53 
54 
55 sub store_job_message {
56  my ($self, $job_id, $msg, $message_class) = @_;
57 
58  if($job_id) {
59  chomp $msg; # we don't want that last "\n" in the database
60 
61  my $table_name = $self->table_name();
62 
63  # Note: the timestamp 'when_logged' column will be set automatically
64  my $sql = qq{
65  INSERT INTO $table_name (job_id, role_id, worker_id, retry, status, msg, message_class)
66  SELECT job_id, role_id, worker_id, retry_count, status, ?, ?
67  FROM job
68  JOIN role USING(role_id)
69  WHERE job_id=?
70  };
71 
72  my $sth = $self->prepare( $sql );
73  $sth->execute( $msg, $message_class, $job_id );
74  $sth->finish();
75 
76  } else {
77  $self->store_hive_message($msg, $message_class);
78  }
79 }
80 
81 
82 sub store_worker_message {
83  my ($self, $worker_or_id, $msg, $message_class) = @_;
84 
85  my ($worker, $worker_id) = ref($worker_or_id) ? ($worker_or_id, $worker_or_id->dbID) : (undef, $worker_or_id);
86  my $role_id = $worker && $worker->current_role && $worker->current_role->dbID;
87 
88  chomp $msg; # we don't want that last "\n" in the database
89 
90  my $table_name = $self->table_name();
91 
92  # Note: the timestamp 'when_logged' column will be set automatically
93  my $sql = qq{
94  INSERT INTO $table_name (worker_id, role_id, status, msg, message_class)
95  SELECT worker_id, ?, status, ?, ?
96  FROM worker WHERE worker_id=?
97  };
98  my $sth = $self->prepare( $sql );
99  $sth->execute( $role_id, $msg, $message_class, $worker_id );
100  $sth->finish();
101 }
102 
103 
104 sub store_hive_message {
105  my ($self, $msg, $message_class) = @_;
106 
107  chomp $msg; # we don't want that last "\n" in the database
108 
109  # Note: the timestamp 'when_logged' column will be set automatically
110  my $log_message = {
111  'msg' => $msg,
112  'message_class' => $message_class,
113  'status' => 'UNKNOWN',
114  };
115  return $self->store($log_message);
116 }
117 
118 sub store_beekeeper_message {
119  my ($self, $beekeeper_id, $msg, $message_class, $status) = @_;
120 
121  chomp $msg;
122 
123  my $log_message = {
124  'beekeeper_id' => $beekeeper_id,
125  'msg' => $msg,
126  'message_class' => $message_class,
127  'status' => $status,
128  };
129  return $self->store($log_message);
130 }
131 
132 sub count_analysis_events {
133  my ($self, $analysis_id, $message_class) = @_;
134 
135  return $self->count_all("JOIN role USING (role_id) WHERE analysis_id = ? AND message_class = ?", undef, $analysis_id, $message_class);
136 }
137 
138 1;
Bio::EnsEMBL::Hive::DBSQL::LogMessageAdaptor::store_job_message
public store_job_message()
Bio::EnsEMBL::Hive::DBSQL::LogMessageAdaptor
Definition: LogMessageAdaptor.pm:22