]> git.proxmox.com Git - pve-manager.git/blob - PVE/Jobs/Plugin.pm
update shipped aplinfo
[pve-manager.git] / PVE / Jobs / Plugin.pm
1 package PVE::Jobs::Plugin;
2
3 use strict;
4 use warnings;
5
6 use PVE::Cluster qw(cfs_register_file);
7
8 use base qw(PVE::SectionConfig);
9
10 cfs_register_file(
11 'jobs.cfg',
12 sub { __PACKAGE__->parse_config(@_); },
13 sub { __PACKAGE__->write_config(@_); }
14 );
15
16 my $defaultData = {
17 propertyList => {
18 type => { description => "Section type." },
19 id => {
20 description => "The ID of the job.",
21 type => 'string',
22 format => 'pve-configid',
23 maxLength => 64,
24 },
25 enabled => {
26 description => "Determines if the job is enabled.",
27 type => 'boolean',
28 default => 1,
29 optional => 1,
30 },
31 schedule => {
32 description => "Backup schedule. The format is a subset of `systemd` calendar events.",
33 type => 'string', format => 'pve-calendar-event',
34 maxLength => 128,
35 },
36 comment => {
37 optional => 1,
38 type => 'string',
39 description => "Description for the Job.",
40 maxLength => 512,
41 },
42 'repeat-missed' => {
43 optional => 1,
44 type => 'boolean',
45 description => "If true, the job will be run as soon as possible if it was missed".
46 " while the scheduler was not running.",
47 default => 0,
48 },
49 },
50 };
51
52 sub private {
53 return $defaultData;
54 }
55
56 sub parse_config {
57 my ($class, $filename, $raw) = @_;
58
59 my $cfg = $class->SUPER::parse_config($filename, $raw);
60
61 foreach my $id (sort keys %{$cfg->{ids}}) {
62 my $data = $cfg->{ids}->{$id};
63
64 $data->{id} = $id;
65 $data->{enabled} //= 1;
66
67 if (defined($data->{comment})) {
68 $data->{comment} = PVE::Tools::decode_text($data->{comment});
69 }
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) = @_;
92
93 for my $job (values $cfg->{ids}->%*) {
94 if (defined($job->{comment})) {
95 $job->{comment} = PVE::Tools::encode_text($job->{comment});
96 }
97 }
98
99 $class->SUPER::write_config($filename, $cfg);
100 }
101
102 sub run {
103 my ($class, $cfg) = @_;
104 # implement in subclass
105 die "not implemented";
106 }
107
108 1;