[Bio] / Clearinghouse / utils.pm Repository:
ViewVC logotype

Annotation of /Clearinghouse/utils.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download) (as text)

1 : olson 1.1
2 :     #
3 :     # Clearinghouse utility functions.
4 :     #
5 :    
6 :     use strict;
7 :     use base 'Exporter';
8 :    
9 : olson 1.2 use HTML;
10 : olson 1.1 use Clearinghouse::ch_database;
11 :    
12 :     our @EXPORT = qw(check_types
13 : olson 1.2 get_lock
14 :     release_lock
15 :     get_page_header
16 : olson 1.1 );
17 :    
18 : olson 1.2 sub get_page_header
19 :     {
20 :     my @page_header = &HTML::compute_html_header(undef, undef,
21 :     header_name => 'clearinghouse.hdr',
22 :     tail_name => 'clearinghouse.tail',
23 :     no_fig_search => 1,
24 :     no_release_info => 1);
25 :     return join("\n", @page_header);
26 :     }
27 :    
28 : olson 1.1 sub check_types {
29 :     my ($type) = @_;
30 :     my $db = db_init();
31 :    
32 :     my $ar = $db->SQL(qq(SELECT type FROM types WHERE type = '$type'));
33 :     return @$ar; #length = 0, if no rows
34 :     }
35 :    
36 :    
37 :    
38 :     sub get_lock {
39 :     my ($dbh, $name, $timeout) = @_;
40 :    
41 :     my $sth = $dbh->prepare(q{UPDATE locks set lock = 1 where name = ? and lock = 0}) or die $dbh->errstr;
42 :     my $res = $sth->execute($name);
43 :     while ($sth->rows == 0) {
44 :     if ($timeout-- == 0) {
45 :     die "Lock timout";
46 :     }
47 :     sleep 1;
48 :     my $res = $sth->execute($name);
49 :     }
50 :     }
51 :    
52 :    
53 :     sub release_lock {
54 :     my ($dbh, $name) = @_;
55 :    
56 :     my $sth = $dbh->prepare(q{UPDATE locks set lock = 0 where name = ?}) or die $dbh->errstr;
57 :     $sth->execute($name);
58 :     }
59 :    
60 :    
61 :    
62 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3