line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WFA::Job; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
57
|
use 5.008; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
144
|
|
4
|
4
|
|
|
4
|
|
17
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
103
|
|
5
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
91
|
|
6
|
4
|
|
|
4
|
|
16
|
use Moo; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
24
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'WFA::Role::Response'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
WFA::Job - A job object, representing a single WFA job |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has workflow => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
required => 1, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub BUILDARGS { |
22
|
0
|
|
|
0
|
0
|
|
my ($class, %args) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $response = $args{response}->{job}; |
25
|
0
|
|
|
|
|
|
delete $args{response}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return { |
28
|
0
|
|
|
|
|
|
%args, |
29
|
|
|
|
|
|
|
response => $response, |
30
|
|
|
|
|
|
|
workflow => WFA::Workflow->new(%args, response => $response), |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 METHODS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 my $workflow = $job->workflow() |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Retrieve the workflow associated with this job. Returns a C<WFA::Workflow> object. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 my $job_id = $job->id() |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Get the unique id of the job. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub id { |
47
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
48
|
0
|
|
|
|
|
|
return $self->response()->{jobId}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 my $job_start_time = $job->start_time() |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Get the start time of the job. This is a string formatted by WFA of the format C<Jan 29, 2015 2:26:14 PM>. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub start_time { |
58
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
59
|
0
|
|
|
|
|
|
return $self->response()->{jobStatus}->{startTime}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 my $job_end_time = $job->end_time() |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Get the end time of the job. This is a string formatted by WFA of the format C<Jan 29, 2015 2:26:14 PM>. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub end_time { |
69
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
70
|
0
|
|
|
|
|
|
return $self->response()->{jobStatus}->{endTime}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 my %job_parameters = $job->parameters() |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Get the parameters passed when executing the workflow. Example: |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
( |
78
|
|
|
|
|
|
|
Parameter1 => 'value1', |
79
|
|
|
|
|
|
|
Parameter2 => 'value2', |
80
|
|
|
|
|
|
|
) |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub parameters { |
85
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
86
|
0
|
|
|
|
|
|
return map { $_->{key} => $_->{value} } @{ $self->response()->{jobStatus}->{userInputValues}->{userInputEntry} }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 my $job_status = $job->status() |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Get the status of the job. This is a string that can be one of C<COMPLETED>, C<FAILED>, C<CANCELED>, C<OBSOLETE>, or C<SCHEDULED>. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub status { |
96
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
97
|
0
|
|
|
|
|
|
return $self->response()->{jobStatus}->{jobStatus}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 my $job_is_running = $job->running() |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Returns true if the job is still running (not completed or failed). |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub running { |
107
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
108
|
0
|
|
|
|
|
|
return $self->status() !~ m/COMPLETED|FAILED|CANCELED|OBSOLETE/; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 my $job_was_successful = $job->success() |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Returns true if the job has completed and was successful. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub success { |
118
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
119
|
0
|
|
|
|
|
|
return $self->status() =~ m/COMPLETED/; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 $job->refresh() |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
The C<$job> object does not automatically update as state changes on the WFA server. Call C<refresh> to update in-place the state of the C<$job> object. This is absolutely necessary if you are polling for completion with methods such as C<running> and C<success>. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub refresh { |
129
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
130
|
0
|
|
|
|
|
|
my $job = WFA::Job->new( |
131
|
|
|
|
|
|
|
client => $self->client(), |
132
|
|
|
|
|
|
|
response => $self->client()->submit_wfa_request($self->url_for_action('self')), |
133
|
|
|
|
|
|
|
); |
134
|
0
|
|
|
|
|
|
$self->response($job->response()); |
135
|
0
|
|
|
|
|
|
$self->workflow($job->workflow()); |
136
|
0
|
|
|
|
|
|
return $self; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 $job->poll_for_completion() |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Wait until the job is complete, regularly polling the WFA server. This is equivalent to: |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
while ($job->running()) { |
144
|
|
|
|
|
|
|
$job->refresh(); |
145
|
|
|
|
|
|
|
sleep(5); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub poll_for_completion { |
151
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
while ($self->running()) { |
154
|
0
|
|
|
|
|
|
sleep(5); |
155
|
0
|
|
|
|
|
|
$self->refresh(); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
return $self; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |