]>
git.proxmox.com Git - pve-common.git/blob - src/PVE/Job/Registry.pm
1 package PVE
::Job
::Registry
;
6 # The job (config) base class, normally you would use this in one of two variants:
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
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
16 use base
qw(PVE::SectionConfig);
20 type
=> { description
=> "Section type." },
21 # FIXME: remove below? this is the section ID, schema would only be checked if a plugin
22 # declares this as explicit option, which isn't really required as its available anyway..
24 description
=> "The ID of the job.",
26 format
=> 'pve-configid',
30 description
=> "Determines if the job is enabled.",
36 description
=> "Backup schedule. The format is a subset of `systemd` calendar events.",
37 type
=> 'string', format
=> 'pve-calendar-event',
43 description
=> "Description for the Job.",
49 description
=> "If true, the job will be run as soon as possible if it was missed".
50 " while the scheduler was not running.",
61 my ($class, $filename, $raw, $allow_unknown) = @_;
63 my $cfg = $class->SUPER::parse_config
($filename, $raw, $allow_unknown);
65 for my $id (keys %{$cfg->{ids
}}) {
66 my $data = $cfg->{ids
}->{$id};
67 my $type = $data->{type
};
69 # FIXME: below id injection is gross, guard to avoid breaking plugins that don't declare id
70 # as option; *iff* we want this it should be handled by section config directly.
71 if ($defaultData->{options
}->{$type} && exists $defaultData->{options
}->{$type}->{id
}) {
74 $data->{enabled
} //= 1;
76 $data->{comment
} = PVE
::Tools
::decode_text
($data->{comment
}) if defined($data->{comment
});
82 # call the plugin specific decode/encode code
84 my ($class, $type, $key, $value) = @_;
86 my $plugin = __PACKAGE__-
>lookup($type);
87 return $plugin->decode_value($type, $key, $value);
91 my ($class, $type, $key, $value) = @_;
93 my $plugin = __PACKAGE__-
>lookup($type);
94 return $plugin->encode_value($type, $key, $value);
98 my ($class, $filename, $cfg, $allow_unknown) = @_;
100 for my $job (values $cfg->{ids
}->%*) {
101 $job->{comment
} = PVE
::Tools
::encode_text
($job->{comment
}) if defined($job->{comment
});
104 $class->SUPER::write_config
($filename, $cfg, $allow_unknown);
108 my ($class, $cfg) = @_;
110 die "not implemented"; # implement in subclass