-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ldap ha periodic task did not execute as expected
- Loading branch information
1 parent
7791d62
commit c0b301d
Showing
4 changed files
with
45 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.utils.translation import gettext_lazy as _ | ||
from rest_framework import serializers | ||
from ops.mixin import PeriodTaskSerializerMixin | ||
|
||
|
||
class LDAPSerializerMixin: | ||
def validate(self, attrs): | ||
is_periodic = attrs.get(self.periodic_key) | ||
crontab = attrs.get(self.crontab_key) | ||
interval = attrs.get(self.interval_key) | ||
if is_periodic and not any([crontab, interval]): | ||
msg = _("Require interval or crontab setting") | ||
raise serializers.ValidationError(msg) | ||
return super().validate(attrs) | ||
|
||
def post_save(self): | ||
keys = [self.periodic_key, self.interval_key, self.crontab_key] | ||
kwargs = {k: self.validated_data[k] for k in keys if k in self.validated_data} | ||
if not kwargs: | ||
return | ||
self.import_task_function(**kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters