Retrieves information and options from the node API and saves it into the database. :returns: True if information could be updated, False otherwise
(self)
| 67 | self.last_refreshed >= timezone.now() - timedelta(minutes=settings.NODE_OFFLINE_MINUTES) |
| 68 | |
| 69 | def update_node_info(self): |
| 70 | """ |
| 71 | Retrieves information and options from the node API |
| 72 | and saves it into the database. |
| 73 | |
| 74 | :returns: True if information could be updated, False otherwise |
| 75 | """ |
| 76 | api_client = self.api_client(timeout=5) |
| 77 | try: |
| 78 | info = api_client.info() |
| 79 | |
| 80 | self.api_version = info.version |
| 81 | self.queue_count = info.task_queue_count |
| 82 | |
| 83 | if isinstance(info.max_images, (int, float)): |
| 84 | self.max_images = max(0, info.max_images) |
| 85 | else: |
| 86 | self.max_images = None |
| 87 | self.engine_version = info.engine_version |
| 88 | self.engine = info.engine |
| 89 | |
| 90 | options = list(map(lambda o: o.__dict__, api_client.options())) |
| 91 | self.available_options = options |
| 92 | self.last_refreshed = timezone.now() |
| 93 | self.save() |
| 94 | return True |
| 95 | except exceptions.GenericError: |
| 96 | return False |
| 97 | |
| 98 | def api_client(self, timeout=30): |
| 99 | return Node(self.hostname, self.port, self.token, timeout) |