blib/lib/App/Netdisco/DB/Result/Virtual/TastyJobs.pm untested

filter: Statementstmt 0.0% 0 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod n/a totaltotal 0.0% 0 / 18 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package App::Netdisco::DB::Result::Virtual::TastyJobs;
2  
3 use strict;
4 use warnings;
5  
6 use base 'DBIx::Class::Core';
7  
8 __PACKAGE__->table_class('DBIx::Class::ResultSource::View');
9  
10 __PACKAGE__->table('tasty_jobs');
11 __PACKAGE__->result_source_instance->is_virtual(1);
12 __PACKAGE__->result_source_instance->view_definition(<<ENDSQL
13 WITH my_jobs AS
14 (SELECT admin.* FROM admin
15 LEFT OUTER JOIN device_skip ds
16 ON (ds.backend = ? AND admin.device = ds.device
17 AND admin.action = ANY (ds.actionset))
18 WHERE admin.status = 'queued'
19 AND admin.backend IS NULL
20 AND ds.device IS NULL
21 AND (split_part(admin.action, '::', 1) = ANY (string_to_array(btrim(?, '{"}'), '","'))) = ?::boolean)
22  
23 SELECT my_jobs.*,
24 CASE WHEN ( (my_jobs.username IS NOT NULL AND (((ds.deferrals = 0 OR ds.deferrals IS NULL) AND ds.last_defer IS NULL)
25 OR my_jobs.entered > ds.last_defer))
26 OR (my_jobs.action = ANY (string_to_array(btrim(?, '{"}'), '","'))) )
27 THEN 100
28 ELSE 0
29 END AS job_priority
30 FROM my_jobs
31  
32 LEFT OUTER JOIN device_skip ds
33 ON (ds.backend = ? AND ds.device = my_jobs.device)
34  
35 WHERE ds.deferrals < ?
36 OR (my_jobs.username IS NOT NULL AND (ds.last_defer IS NULL
37 OR my_jobs.entered > ds.last_defer))
38 OR (ds.deferrals IS NULL AND ds.last_defer IS NULL)
39 OR ds.last_defer <= ( LOCALTIMESTAMP - ?::interval )
40  
41 ORDER BY job_priority DESC,
42 ds.deferrals ASC NULLS FIRST,
43 ds.last_defer ASC NULLS LAST,
44 device_key DESC NULLS LAST,
45 random()
46 LIMIT ?
47 ENDSQL
48 );
49  
50 __PACKAGE__->add_columns(
51 "job",
52 { data_type => "integer", is_nullable => 0, },
53 "entered",
54 { data_type => "timestamp", is_nullable => 1 },
55 "started",
56 { data_type => "timestamp", is_nullable => 1 },
57 "finished",
58 { data_type => "timestamp", is_nullable => 1 },
59 "device",
60 { data_type => "inet", is_nullable => 1 },
61 "port",
62 { data_type => "text", is_nullable => 1 },
63 "action",
64 { data_type => "text", is_nullable => 1 },
65 "subaction",
66 { data_type => "text", is_nullable => 1 },
67 "status",
68 { data_type => "text", is_nullable => 1 },
69 "username",
70 { data_type => "text", is_nullable => 1 },
71 "userip",
72 { data_type => "inet", is_nullable => 1 },
73 "log",
74 { data_type => "text", is_nullable => 1 },
75 "debug",
76 { data_type => "boolean", is_nullable => 1 },
77 "device_key",
78 { data_type => "text", is_nullable => 1 },
79 "job_priority",
80 { data_type => "integer", is_nullable => 1 },
81 );
82  
83 __PACKAGE__->set_primary_key("job");
84  
85 1;