summaryrefslogtreecommitdiff
path: root/httemplate/search/queue.html
blob: 63a5d6c96f002641e896a3e1ad6108987ae0a597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
%
%
%my $hashref = {};
%
%my $conf = new FS::Conf;
%my $dangerous = $conf->exists('queue_dangerous_controls');
%
%my $noactions = 0;
%
%my $count_query = 'SELECT COUNT(*) FROM queue'; # + $hashref
%
%my $areboxes = 0;
%
%
<% include( 'elements/search.html',
                 'title'       => 'Job Queue',
                 'menubar'     => [ 'Main menu' => $p, ],
                 'name'        => 'jobs',
		 'html_form'   => qq!<FORM ACTION="$p/misc/queue.cgi" METHOD="POST">!,
                 'query'       => { 'table'     => 'queue',
                                    'hashref'   => $hashref,
                                    'extra_sql' => 'ORDER BY jobnum',
                                  },
                 'count_query' => $count_query,
                 'header' => [ '#',
                               'Job',
                               'Args',
                               'Date',
                               'Status',
                               'Account', # unless $hashref->{'svcnum'}
                               '', # checkbox column
                             ],
                 'fields' => [
                               'jobnum',
                               'job',
                               sub {
                                 my $queue = shift;
                                 if (    $dangerous
                                      || $queue->job !~ /^FS::part_export::/
                                      || !$noactions
                                    )
                                 {
                                   encode_entities( join(' ', $queue->args) );
                                 } else {
                                   '';
                                 }
                               },
                               sub {
                                 time2str( "%a %b %e %T %Y", shift->_date );
                               },
                               sub {
                                 my $queue = shift;
                                 my $jobnum = $queue->jobnum;
                                 my $status = $queue->status;
                                 $status .= ': '. $queue->statustext
                                   if $queue->statustext;
                                 my @queue_depend = $queue->queue_depend;
                                 $status .= ' (waiting for '.
                                            join(', ', map { $_->depend_jobnum }
                                                           @queue_depend
                                                ). 
                                            ')'
                                   if @queue_depend;
                                 my $changable = $dangerous
                                                 || ( ! $noactions
                                                      && $status =~ /^failed/
                                                      || $status =~ /^locked/
                                                    );
                                 if ( $changable ) {
                                   $status .=
                                     qq! (&nbsp;<A HREF="$p/misc/queue.cgi?jobnum=$jobnum&action=new">retry</A>&nbsp;|!.
                                     qq!&nbsp;<A HREF="$p/misc/queue.cgi?jobnum=$jobnum&action=del">remove</A>&nbsp;)!;
                                 }
                                 $status;
                               },
                               sub {
                                 my $queue = shift;
                                 # return '' if $hashref->{'svcnum'}
                                 my $cust_svc = $queue->cust_svc;
                                 my $account;
                                 if ( $cust_svc ) {
                                   my $table = $cust_svc->part_svc->svcdb;
                                   my $label = ( $cust_svc->label )[1];
                                   qq!<A HREF="../view/$table.cgi?!. $queue->svcnum.
                                   qq!">$label</A>!;
                                 } else {
                                   '';
                                 }
                               },
                               sub {
                                 my $queue = shift;
                                 my $jobnum = $queue->jobnum;
                                 my $status = $queue->status;
                                 my $changable = $dangerous
                                                 || ( ! $noactions
                                                      && $status eq 'failed'
                                                      || $status eq 'locked'
                                                    );
                                 if ( $changable ) {
                                   $areboxes = 1;
                                   qq!<INPUT NAME="jobnum$jobnum" TYPE="checkbox" VALUE="1">!;
                                 } else {
                                   '';
                                 }
                               },
                             ],
                 #'links' =>  [
                 #              '',
                 #              '',
                 #              '',
                 #              '',
                 #              '',
                 #              '', #$acct_link,
                 #              '',
                 #            ],
                 'html_foot' => sub {
                                  if ( $areboxes ) {
                                    '<BR><INPUT TYPE="submit" NAME="action" VALUE="retry selected">'.
                                    '<INPUT TYPE="submit" NAME="action" VALUE="remove selected"><BR>';
                                  } else {
                                    '';
                                  }
                                },
             )

%>