|
24 | 24 |
|
25 | 25 | from django.core.management.base import BaseCommand, CommandError
|
26 | 26 | from django.db import connection, transaction
|
| 27 | +from django.db.utils import OperationalError |
27 | 28 |
|
28 | 29 | from main.models import Arch, Repo
|
29 | 30 | from .reporead import read_repo
|
@@ -117,11 +118,12 @@ class Database(object):
|
117 | 118 | various bits of metadata and state representing the file path, when we last
|
118 | 119 | updated, how long our delay is before performing the update, whether we are
|
119 | 120 | updating now, etc.'''
|
120 |
| - def __init__(self, arch, path, delay=60.0, nice=3): |
| 121 | + def __init__(self, arch, path, delay=60.0, nice=3, retry_limit=5): |
121 | 122 | self.arch = arch
|
122 | 123 | self.path = path
|
123 | 124 | self.delay = delay
|
124 | 125 | self.nice = nice
|
| 126 | + self.retry_limit = retry_limit |
125 | 127 | self.mtime = None
|
126 | 128 | self.last_import = None
|
127 | 129 | self.update_thread = None
|
@@ -158,10 +160,23 @@ def update(self):
|
158 | 160 | # invoke reporead's primary method. we do this in a separate
|
159 | 161 | # process for memory conservation purposes; these processes grow
|
160 | 162 | # rather large so it is best to free up the memory ASAP.
|
| 163 | + # A retry mechanism exists for when reporead_inotify runs on a different machine. |
161 | 164 | def run():
|
| 165 | + retry = True |
| 166 | + retry_count = 0 |
162 | 167 | if self.nice != 0:
|
163 | 168 | os.nice(self.nice)
|
164 |
| - read_repo(self.arch, self.path, {}) |
| 169 | + while retry and retry_count < self.retry_limit: |
| 170 | + try: |
| 171 | + read_repo(self.arch, self.path, {}) |
| 172 | + retry = False |
| 173 | + except OperationalError as exc: |
| 174 | + retry_count += 1 |
| 175 | + logger.error('Unable to update database \'%s\', retrying=%d', self.path, retry_count, exc_info=exc) |
| 176 | + time.sleep(5) |
| 177 | + |
| 178 | + if retry_count == self.retry_limit: |
| 179 | + logger.error('Unable to update database, exceeded maximum retries') |
165 | 180 |
|
166 | 181 | process = multiprocessing.Process(target=run)
|
167 | 182 | process.start()
|
|
0 commit comments