]>
Commit | Line | Data |
---|---|---|
0d830ac7 TL |
1 | package PVE::Job::Registry; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | # The job (config) base class, normally you would use this in one of two variants: | |
7 | # | |
8 | # 1) base of directly in manager and handle everything there; great for stuff that isn't residing | |
9 | # outside of the manager, so that there is no cyclic dependency (forbidden!) required | |
10 | # | |
11 | # 2) use two (or even more) classes, one in the library (e.g., guest-common, access-control, ...) | |
12 | # basing off this module, providing the basic config implementation. Then one in pve-manager | |
13 | # (where every dependency is available) basing off the intermediate config one, that then holds | |
14 | # the implementation of the 'run` method and is used in the job manager | |
15 | ||
16 | use base qw(PVE::SectionConfig); | |
17 | ||
18 | my $defaultData = { | |
19 | propertyList => { | |
20 | type => { description => "Section type." }, | |
21 | id => { | |
22 | description => "The ID of the job.", | |
23 | type => 'string', | |
24 | format => 'pve-configid', | |
25 | maxLength => 64, | |
26 | }, | |
27 | enabled => { | |
28 | description => "Determines if the job is enabled.", | |
29 | type => 'boolean', | |
30 | default => 1, | |
31 | optional => 1, | |
32 | }, | |
33 | schedule => { | |
34 | description => "Backup schedule. The format is a subset of `systemd` calendar events.", | |
35 | type => 'string', format => 'pve-calendar-event', | |
36 | maxLength => 128, | |
37 | }, | |
38 | comment => { | |
39 | optional => 1, | |
40 | type => 'string', | |
41 | description => "Description for the Job.", | |
42 | maxLength => 512, | |
43 | }, | |
44 | 'repeat-missed' => { | |
45 | optional => 1, | |
46 | type => 'boolean', | |
47 | description => "If true, the job will be run as soon as possible if it was missed". | |
48 | " while the scheduler was not running.", | |
49 | default => 0, | |
50 | }, | |
51 | }, | |
52 | }; | |
53 | ||
54 | sub private { | |
55 | return $defaultData; | |
56 | } | |
57 | ||
0d830ac7 TL |
58 | sub parse_config { |
59 | my ($class, $filename, $raw, $allow_unknown) = @_; | |
60 | ||
61 | my $cfg = $class->SUPER::parse_config($filename, $raw, $allow_unknown); | |
62 | ||
63 | foreach my $id (sort keys %{$cfg->{ids}}) { | |
64 | my $data = $cfg->{ids}->{$id}; | |
65 | ||
66 | $data->{id} = $id; | |
67 | $data->{enabled} //= 1; | |
68 | ||
69 | $data->{comment} = PVE::Tools::decode_text($data->{comment}) if defined($data->{comment}); | |
70 | } | |
71 | ||
72 | return $cfg; | |
73 | } | |
74 | ||
75 | # call the plugin specific decode/encode code | |
76 | sub decode_value { | |
77 | my ($class, $type, $key, $value) = @_; | |
78 | ||
79 | my $plugin = __PACKAGE__->lookup($type); | |
80 | return $plugin->decode_value($type, $key, $value); | |
81 | } | |
82 | ||
83 | sub encode_value { | |
84 | my ($class, $type, $key, $value) = @_; | |
85 | ||
86 | my $plugin = __PACKAGE__->lookup($type); | |
87 | return $plugin->encode_value($type, $key, $value); | |
88 | } | |
89 | ||
90 | sub write_config { | |
91 | my ($class, $filename, $cfg, $allow_unknown) = @_; | |
92 | ||
93 | for my $job (values $cfg->{ids}->%*) { | |
94 | $job->{comment} = PVE::Tools::encode_text($job->{comment}) if defined($job->{comment}); | |
95 | } | |
96 | ||
97 | $class->SUPER::write_config($filename, $cfg, $allow_unknown); | |
98 | } | |
99 | ||
100 | sub run { | |
101 | my ($class, $cfg) = @_; | |
102 | ||
103 | die "not implemented"; # implement in subclass | |
104 | } | |
105 | ||
106 | 1; |