+ def get_current_etag(self):
+ import pkg_resources
+ librarian_version = pkg_resources.get_distribution("librarian").version
+ return librarian_version
+
+ def schedule_stale(self, queryset=None):
+ """Schedule building this format for all the books where etag is stale."""
+ # If there is not ETag field, bail. That's true for xml file field.
+ if not self.with_etag:
+ return
+
+ etag = self.get_current_etag()
+ if queryset is None:
+ queryset = self.model.objects.all()
+
+ if self.format_name in EBOOK_FORMATS_WITHOUT_CHILDREN + ['html']:
+ queryset = queryset.filter(children=None)
+
+ queryset = queryset.exclude(**{
+ f'{self.etag_field_name}__in': [
+ etag, f'{etag}{ETAG_SCHEDULED_SUFFIX}'
+ ]
+ })
+ for obj in queryset:
+ fieldfile = getattr(obj, self.attname)
+ priority = EBOOK_REBUILD_PRIORITY if fieldfile else EBOOK_BUILD_PRIORITY
+ fieldfile.build_delay(priority=priority)