| author | Vincent Tondellier <tonton+hg@team1664.org> |
| Sun, 14 Feb 2016 19:58:33 +0100 | |
| changeset 92 | 702e246e5c9f |
| parent 78 | 0ebef32c34af |
| child 122 | 8692800ec9ba |
| permissions | -rw-r--r-- |
|
78
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
1 |
# This program is free software: you can redistribute it and/or modify |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
2 |
# it under the terms of the GNU General Public License as published by |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
3 |
# the Free Software Foundation, either version 3 of the License, or |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
4 |
# (at your option) any later version. |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
5 |
# |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
6 |
# This program is distributed in the hope that it will be useful, |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
7 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
8 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
9 |
# GNU General Public License for more details. |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
10 |
# |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
11 |
# You should have received a copy of the GNU General Public License |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
12 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
13 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
14 |
package CrashTest::Plugin::CrashProcessor::Breakpad; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
15 |
use Mojo::Base 'Mojolicious::Plugin'; |
|
92
702e246e5c9f
Fix config key when inserting
Vincent Tondellier <tonton+hg@team1664.org>
parents:
78
diff
changeset
|
16 |
use Mojo::JSON::MaybeXS; |
|
78
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
17 |
use Mojo::JSON qw/decode_json/; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
18 |
use Mojo::Util qw/dumper/; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
19 |
use Mojolicious::Validator; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
20 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
21 |
has [ qw/app config dumper_config/ ]; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
22 |
has task_name => "breakpad_decode_task"; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
23 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
24 |
sub register {
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
25 |
my ($self, $app, $args) = @_; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
26 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
27 |
$self->app($app); |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
28 |
$self->config($args->{config});
|
|
92
702e246e5c9f
Fix config key when inserting
Vincent Tondellier <tonton+hg@team1664.org>
parents:
78
diff
changeset
|
29 |
$self->dumper_config($self->config->{Processor}->{CrashProcessor}->{Breakpad});
|
|
78
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
30 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
31 |
$app->minion->add_task($self->task_name => |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
32 |
sub {
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
33 |
my ($job, $uuid, $params, $files) = @_; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
34 |
#$job->app->log->debug(dumper $params); |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
35 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
36 |
$job->on(failed => sub { $self->cleanup($files); });
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
37 |
#$job->on(finished => sub { $self->cleanup($files); });
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
38 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
39 |
$self->decode($uuid, $params, $files); |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
40 |
$self->cleanup($files); |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
41 |
} |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
42 |
); |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
43 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
44 |
$app->log->debug("Registered Breakpad");
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
45 |
$args->{cb}->($self);
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
46 |
} |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
47 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
48 |
sub validate {
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
49 |
my ($self, $req) = @_; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
50 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
51 |
my $hash = $req->params->to_hash; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
52 |
$hash->{$_} = $req->every_upload($_) for map { $_->name } @{$req->uploads};
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
53 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
54 |
my $validation = Mojolicious::Validator->new->validation->input($hash); |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
55 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
56 |
$validation->required('UserID');
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
57 |
#$validation->required('Version');
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
58 |
$validation->required('ProductName');
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
59 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
60 |
$validation->required('upload_file_minidump')->upload->size(1024, 4 * 1024 * 1024);
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
61 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
62 |
return $validation; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
63 |
} |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
64 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
65 |
sub decode {
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
66 |
my ($self, $uuidstr, $client_info, $files) = @_; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
67 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
68 |
my $dmp_file = $files->{upload_file_minidump}->[0];
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
69 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
70 |
my $cmd = $self->dumper_config->{JSONStackwalker} . " $dmp_file " . $self->dumper_config->{SymbolsPath};
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
71 |
my $out = qx($cmd 2>/dev/null) or die $!; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
72 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
73 |
my $pjson = decode_json($out); |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
74 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
75 |
$self->app->crash_reports->create($uuidstr, $pjson, $client_info, $dmp_file); |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
76 |
} |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
77 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
78 |
sub cleanup {
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
79 |
my ($self, $files) = @_; |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
80 |
#$self->app->log->debug("cleanup " . dumper $files);
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
81 |
foreach my $values(values %$files) {
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
82 |
foreach my $f(@$values) {
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
83 |
unlink $f or $self->app->log->warn("Failed to unlink $f: $!");
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
84 |
} |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
85 |
} |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
86 |
} |
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
87 |
|
|
0ebef32c34af
Refactor everything
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
88 |
1; |