Browse Source

Handle STOP file and high memory usage before full disk to allow stopping while the disk is above the limit

tags/v0.2.2
JustAnotherArchivist 4 years ago
parent
commit
b1a1c03f7e
1 changed files with 7 additions and 7 deletions
  1. +7
    -7
      qwarc/__init__.py

+ 7
- 7
qwarc/__init__.py View File

@@ -287,6 +287,13 @@ class QWARC:
while len(self._tasks) >= self._concurrency:
await self._wait_for_free_task()

if os.path.exists('STOP'):
logging.info('Gracefully shutting down due to STOP file')
break
if self._memoryLimit and qwarc.utils.uses_too_much_memory(self._memoryLimit):
logging.info(f'Gracefully shutting down due to memory usage (current = {qwarc.utils.get_rss()} > limit = {self._memoryLimit})')
break

if self._minFreeDisk and qwarc.utils.too_little_disk_space(self._minFreeDisk):
logging.info('Disk space is low, sleeping')
sleepTask = asyncio.ensure_future(asyncio.sleep(random.uniform(self._concurrency / 2, self._concurrency * 1.5)))
@@ -295,13 +302,6 @@ class QWARC:
self._sleepTasks.add(sleepTask)
continue

if os.path.exists('STOP'):
logging.info('Gracefully shutting down due to STOP file')
break
if self._memoryLimit and qwarc.utils.uses_too_much_memory(self._memoryLimit):
logging.info(f'Gracefully shutting down due to memory usage (current = {qwarc.utils.get_rss()} > limit = {self._memoryLimit})')
break

cursor = await self.obtain_exclusive_db_lock()
try:
cursor.execute('SELECT id, type, value, status FROM items WHERE status = ? LIMIT 1', (STATUS_TODO,))


Loading…
Cancel
Save