line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
IPC::DirQueue::Job - an IPC::DirQueue task |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my $dq = IPC::DirQueue->new({ dir => "/path/to/queue" }); |
8
|
|
|
|
|
|
|
my $job = $dq->pickup_queued_job(); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
open(IN, "<".$job->get_data_path()); |
11
|
|
|
|
|
|
|
my $str = ; |
12
|
|
|
|
|
|
|
# ... |
13
|
|
|
|
|
|
|
close IN; |
14
|
|
|
|
|
|
|
$job->finish(); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# or... |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $data = $job->get_data(); |
19
|
|
|
|
|
|
|
$job->finish(); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
A job object returned by C. This class provides various |
24
|
|
|
|
|
|
|
methods to access job information, and report job progress and completion. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DATA |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Any submitted metadata can be accessed through the C<$job-E{metadata}> |
29
|
|
|
|
|
|
|
hash reference. For example: |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
print "email: ", $job->{metadata}->{submitter_email}, "\n"; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Otherwise, you can access the queued data file using C, |
34
|
|
|
|
|
|
|
or directly as a string using C. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 METHODS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=over 4 |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
package IPC::DirQueue::Job; |
43
|
23
|
|
|
23
|
|
126
|
use strict; |
|
23
|
|
|
|
|
54
|
|
|
23
|
|
|
|
|
844
|
|
44
|
23
|
|
|
23
|
|
425
|
use bytes; |
|
23
|
|
|
|
|
47
|
|
|
23
|
|
|
|
|
5794
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
our @ISA = (); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
########################################################################### |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new { |
51
|
490
|
|
|
490
|
0
|
760
|
my $class = shift; |
52
|
490
|
|
|
|
|
691
|
my $dqmaster = shift; |
53
|
490
|
|
|
|
|
541
|
my $opts = shift; |
54
|
490
|
|
33
|
|
|
2023
|
$class = ref($class) || $class; |
55
|
|
|
|
|
|
|
|
56
|
490
|
|
|
|
|
688
|
my $self = $opts; |
57
|
490
|
|
|
|
|
970
|
$self->{dqmaster} = $dqmaster; |
58
|
490
|
|
|
|
|
998
|
$self->{metadata} = { }; |
59
|
|
|
|
|
|
|
|
60
|
490
|
|
|
|
|
1778
|
bless ($self, $class); |
61
|
490
|
|
|
|
|
1449
|
$self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
########################################################################### |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item $data = $job->get_data(); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Return the job's data. The return value will be a string, the data that was |
69
|
|
|
|
|
|
|
originally enqueued for this job. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub get_data { |
74
|
310
|
|
|
310
|
1
|
582
|
my ($self) = @_; |
75
|
310
|
|
|
|
|
4231
|
my $data; |
76
|
310
|
50
|
|
|
|
27896
|
open IN, $self->{QDFN} or die $!; |
77
|
310
|
|
|
|
|
4315
|
while () { |
78
|
310
|
|
|
|
|
3338
|
$data .= $_; |
79
|
|
|
|
|
|
|
} |
80
|
310
|
|
|
|
|
4426
|
close IN; |
81
|
310
|
|
|
|
|
1208
|
return $data; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item $path = $job->get_data_path(); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Return the full path to the task's data file. This can be opened and read |
87
|
|
|
|
|
|
|
safely while the job is active. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub get_data_path { |
92
|
620
|
|
|
620
|
1
|
2131
|
my ($self) = @_; |
93
|
620
|
|
|
|
|
18337
|
return $self->{QDFN}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item $nbytes = $job->get_data_size_bytes(); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Retrieve the size of the data without performing a C operation. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub get_data_size_bytes { |
103
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
104
|
0
|
|
|
|
|
0
|
return $self->{QDSB}; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item $secs = $job->get_time_submitted_secs(); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Get the seconds-since-epoch (in other words, the C) on the |
110
|
|
|
|
|
|
|
submitting host when this task was submitted. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub get_time_submitted_secs { |
115
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
116
|
0
|
|
|
|
|
0
|
return $self->{QSTT}; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item $usecs = $job->get_time_submitted_usecs(); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Get the microseconds within that second, as measured by C on |
122
|
|
|
|
|
|
|
the submitting host, when this task was submitted. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub get_time_submitted_usecs { |
127
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
128
|
0
|
|
|
|
|
0
|
return $self->{QSTM}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item $hostname = $job->get_hostname_submitted(); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Get the name of the submitting host where this task originated. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub get_hostname_submitted { |
138
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
139
|
0
|
|
|
|
|
0
|
return $self->{QSHN}; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item $job->touch_active_lock(); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Update the lockfile to reflect that this task is still being processed. If a |
145
|
|
|
|
|
|
|
task has been active, but the lockfile has not been touched for more than 600 |
146
|
|
|
|
|
|
|
seconds, another C queue processor may take it over. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub touch_active_lock { |
151
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
152
|
0
|
|
|
|
|
0
|
open (TOUCH, ">>".$self->{pathactive}); |
153
|
0
|
|
|
|
|
0
|
close TOUCH; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
########################################################################### |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item $job->finish(); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Report that the job has been completed, and may be removed from the queue. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub finish { |
165
|
400
|
|
|
400
|
1
|
132734
|
my ($self) = @_; |
166
|
400
|
|
|
|
|
1881
|
$self->{dqmaster}->finish_job ($self, 1); |
167
|
400
|
|
|
|
|
2375
|
delete $self->{dqmaster}; # clean up circ ref |
168
|
400
|
|
|
|
|
2835
|
return 1; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item $job->return_to_queue(); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Return the job to the queue, unfinished. Another task processor |
174
|
|
|
|
|
|
|
may then pick it up. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub return_to_queue { |
179
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
180
|
0
|
|
|
|
|
|
$self->{dqmaster}->finish_job ($self, 0); |
181
|
0
|
|
|
|
|
|
delete $self->{dqmaster}; # clean up circ ref |
182
|
0
|
|
|
|
|
|
return 1; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
########################################################################### |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
1; |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=back |