chore(lint): address BLE001
This commit is contained in:
@@ -889,27 +889,28 @@ def download_media_metadata(media_id):
|
|||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
published_datetime = None
|
published_datetime = None
|
||||||
|
|
||||||
parts = e_str.split(': ', 1)[1].rsplit(' ', 2)
|
|
||||||
unit = lambda p: str(p[-1]).lower()
|
|
||||||
number = lambda p: int(str(p[-2]), base=10)
|
|
||||||
log.debug(parts)
|
|
||||||
try:
|
try:
|
||||||
if 'days' == unit(parts):
|
parts = e_str.split(': ', 1)[1].rsplit(' ', 2)
|
||||||
|
log.debug(parts)
|
||||||
|
unit = parts[-1].lower()
|
||||||
|
log.debug(unit)
|
||||||
|
number = lambda p: int(str(p[-2]), base=10)
|
||||||
|
|
||||||
|
if 'days' == unit:
|
||||||
published_datetime = now + timedelta(days=number(parts))
|
published_datetime = now + timedelta(days=number(parts))
|
||||||
if 'hours' == unit(parts):
|
if 'hours' == unit:
|
||||||
published_datetime = now + timedelta(hours=number(parts))
|
published_datetime = now + timedelta(hours=number(parts))
|
||||||
if 'minutes' == unit(parts):
|
if 'minutes' == unit:
|
||||||
published_datetime = now + timedelta(minutes=number(parts))
|
published_datetime = now + timedelta(minutes=number(parts))
|
||||||
log.debug(unit(parts))
|
if published_datetime:
|
||||||
log.debug(number(parts))
|
log.debug(number(parts))
|
||||||
except Exception:
|
media.published = published_datetime
|
||||||
|
media.manual_skip = True
|
||||||
|
media.save()
|
||||||
|
raise_exception = False
|
||||||
|
except (ValueError, IndexError, OverflowError):
|
||||||
log.exception('could not assign published_datetime')
|
log.exception('could not assign published_datetime')
|
||||||
|
|
||||||
if published_datetime:
|
|
||||||
media.published = published_datetime
|
|
||||||
media.manual_skip = True
|
|
||||||
media.save()
|
|
||||||
raise_exception = False
|
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise
|
raise
|
||||||
log.debug(str(e))
|
log.debug(str(e))
|
||||||
@@ -1142,44 +1143,40 @@ def rescan_media_server(mediaserver_id):
|
|||||||
|
|
||||||
@huey_task(delay=settings.MAX_RUN_TIME, expires=3600, priority=20, queue=Val(TaskQueue.NET))
|
@huey_task(delay=settings.MAX_RUN_TIME, expires=3600, priority=20, queue=Val(TaskQueue.NET))
|
||||||
def terminate_queue_worker(media_id, worker_pid, queue, log_message):
|
def terminate_queue_worker(media_id, worker_pid, queue, log_message):
|
||||||
|
proc_cmdline_path = Path(f'/proc/{worker_pid}/cmdline')
|
||||||
try:
|
try:
|
||||||
os.kill(worker_pid, 0)
|
os.kill(worker_pid, 0)
|
||||||
|
if not proc_cmdline_path.exists():
|
||||||
|
return
|
||||||
|
raw_bytes = proc_cmdline_path.read_bytes()
|
||||||
except OSError:
|
except OSError:
|
||||||
return
|
log.exception('[Watchdog] Failed to read /proc command line')
|
||||||
|
else:
|
||||||
proc_cmdline_path = Path(f'/proc/{worker_pid}/cmdline')
|
|
||||||
|
|
||||||
if proc_cmdline_path.exists():
|
|
||||||
try:
|
try:
|
||||||
raw_bytes = proc_cmdline_path.read_bytes()
|
decoded_string = raw_bytes.replace(b'\x00', b'\x20').decode('utf-8')
|
||||||
except Exception:
|
except UnicodeDecodeError:
|
||||||
log.exception('[Watchdog] Failed to read /proc command line')
|
log.exception('[Watchdog] Failed decoding process command line payload')
|
||||||
else:
|
else:
|
||||||
try:
|
needles = ('djangohuey', f'--queue {queue}',)
|
||||||
decoded_string = raw_bytes.replace(b'\x00', b'\x20').decode('utf-8')
|
haystack = decoded_string.rstrip(' ')
|
||||||
except Exception:
|
if haystack.endswith(needles[-1]) and all( needle in haystack for needle in needles ):
|
||||||
log.exception('[Watchdog] Failed decoding process command line payload')
|
try:
|
||||||
else:
|
os.kill(worker_pid, signal.SIGKILL)
|
||||||
needles = ('djangohuey', f'--queue {queue}',)
|
except OSError:
|
||||||
haystack = decoded_string.rstrip(' ')
|
log.exception('[Watchdog] Failed to kill: %d', worker_pid)
|
||||||
if haystack.endswith(needles[-1]) and all( needle in haystack for needle in needles ):
|
|
||||||
try:
|
|
||||||
os.kill(worker_pid, signal.SIGKILL)
|
|
||||||
log.warning('[Watchdog] %s', log_message)
|
|
||||||
except OSError:
|
|
||||||
log.exception('[Watchdog] Failed to kill: %d', worker_pid)
|
|
||||||
else:
|
|
||||||
# clear the media lock
|
|
||||||
huey_lock_task(
|
|
||||||
f'media:{media_id}',
|
|
||||||
queue=Val(TaskQueue.DB),
|
|
||||||
).clear()
|
|
||||||
else:
|
else:
|
||||||
log.error(
|
log.warning('[Watchdog] %s', log_message)
|
||||||
'[Watchdog] Refusing kill: PID %d was recycled by another process. '
|
# clear the media lock
|
||||||
'Target media: %s Command line: "%s"',
|
huey_lock_task(
|
||||||
worker_pid, media_id, haystack,
|
f'media:{media_id}',
|
||||||
)
|
queue=Val(TaskQueue.DB),
|
||||||
|
).clear()
|
||||||
|
else:
|
||||||
|
log.error(
|
||||||
|
'[Watchdog] Refusing kill: PID %d was recycled by another process. '
|
||||||
|
'Target media: %s Command line: "%s"',
|
||||||
|
worker_pid, media_id, haystack,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RefreshFormatsBackoff(BackoffAlgorithm):
|
class RefreshFormatsBackoff(BackoffAlgorithm):
|
||||||
|
|||||||
Reference in New Issue
Block a user