9 $role_adaptor = $db_adaptor->get_RoleAdaptor;
11 $role_adaptor = $role_object->adaptor;
15 Module to encapsulate all db access
for persistent
class Role.
16 There should be just one per application and database connection.
20 See the NOTICE file distributed with
this work
for additional information
21 regarding copyright ownership.
23 Licensed under the Apache License,
Version 2.0 (the
"License"); you may not use
this file except in compliance with the License.
24 You may obtain a copy of the License at
28 Unless required by applicable law or agreed to in writing, software distributed under the License
29 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 See the License
for the specific language governing permissions and limitations under the License.
34 Please subscribe to the
Hive mailing list: http:
39 package Bio::EnsEMBL::Hive::DBSQL::RoleAdaptor;
46 use base (
'Bio::EnsEMBL::Hive::DBSQL::ObjectAdaptor');
49 sub default_table_name {
55 return 'Bio::EnsEMBL::Hive::Role';
60 my ($self, $role, $release_undone_jobs) = @_;
62 $role->when_finished(
'CURRENT_TIMESTAMP' );
63 $self->update_when_finished( $role );
65 $self->db->get_AnalysisStatsAdaptor->increment_a_counter(
'num_running_workers', -1, $role->analysis_id );
67 if( $release_undone_jobs ) {
68 $self->db->get_AnalysisJobAdaptor->release_undone_jobs_from_role( $role );
71 # Re-sync the analysis_stats when a worker dies as part of dynamic sync system.
72 # It will also re-calculate num_running_workers (from active roles)
73 # so no further adjustment should be necessary.
74 $self->db->get_WorkerAdaptor->safe_synchronize_AnalysisStats( $role->analysis->stats );
78 sub fetch_last_unfinished_by_worker_id {
79 my ($self, $worker_id) = @_;
81 return $self->fetch_all(
"WHERE worker_id=$worker_id AND when_finished IS NULL ORDER BY role_id DESC LIMIT 1", 1 );
85 sub get_hive_current_load {
88 SELECT sum(1/hive_capacity)
90 JOIN analysis_base USING(analysis_id)
91 WHERE when_finished IS NULL
92 AND hive_capacity IS NOT NULL
95 my $sth = $self->prepare($sql);
97 my ($current_load)=$sth->fetchrow_array();
99 return ($current_load || 0);
104 my ($self, $role) = @_;
106 return $self->count_all(
'analysis_id=' . $role->analysis_id .
' AND when_finished IS NULL AND role_id<' . $role->dbID );
110 sub count_active_roles {
111 my ($self, $analysis_id) = @_;
113 return $self->count_all( ($analysis_id ?
"analysis_id=$analysis_id AND " :
'') .
'when_finished IS NULL' );
117 sub print_active_role_counts {
121 SELECT logic_name, count(*)
123 JOIN analysis_base a USING(analysis_id)
124 WHERE when_finished IS NULL
125 GROUP BY a.analysis_id
129 my $sth = $self->prepare($sql);
132 print
"\n===== Stats of active Roles as recorded in the pipeline database: ======\n";
133 while(my ($logic_name, $active_role_count) = $sth->fetchrow_array()) {
134 printf(
"%30s : %d active Roles\n", $logic_name, $active_role_count);
135 $total_roles += $active_role_count;
138 printf(
"%30s : %d active Roles\n\n",
'======= TOTAL =======', $total_roles);
142 sub fetch_all_finished_roles_with_unfinished_jobs {
145 return $self->fetch_all(
"JOIN job USING(role_id) WHERE when_finished IS NOT NULL AND status IN ($Bio::EnsEMBL::Hive::DBSQL::AnalysisJobAdaptor::ALL_STATUSES_OF_TAKEN_JOBS) GROUP BY role_id" );
149 sub fetch_all_unfinished_roles_of_dead_workers {
152 return $self->fetch_all(
"JOIN worker USING(worker_id) WHERE when_finished IS NULL AND status='DEAD'" );