Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout after 1 min for transfer of files #518

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions mirar/monitor/base_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from watchdog.observers import Observer

from mirar.data import Dataset, Image, ImageBatch
from mirar.errors import ErrorReport, ErrorStack, ImageNotFoundError
from mirar.errors import ErrorReport, ErrorStack, ImageNotFoundError, ProcessorError
from mirar.io import check_file_is_complete
from mirar.paths import (
DITHER_N_KEY,
Expand Down Expand Up @@ -49,6 +49,10 @@
logger = logging.getLogger(__name__)


class ImageTimeoutError(ProcessorError):
"""Timeout for downloading an image has been exceeded."""


class NewImageHandler(FileSystemEventHandler):
"""Class to watch a directory, and add newly-created files to a queue."""

Expand Down Expand Up @@ -439,17 +443,36 @@ def process_load_queue(self, queue: Queue):
# Verify that file transfer is complete, useful for rsync latency

transfer_done = False
t_start = Time.now()

while not transfer_done:
transfer_done = check_file_is_complete(event.src_path)

if not transfer_done:
print(
"Seems like the file is not fully transferred. "
f"Seems like the file {event.src_path} is not "
f"fully transferred. "
"Waiting a couple of seconds before trying again."
)
time.sleep(3)

# If a corrupt image comes in, give up eventually
if Time.now() - t_start > 60:
err = (
f"File {event.src_path} has not been fully "
f"transferred after 60 seconds. Skipping this file."
)
logger.error(err)
exc = ImageTimeoutError(err)
err_report = ErrorReport(
exc, "monitor", contents=[event.src_path]
)
self.errorstack.add_report(err_report)
self.update_error_log()

self.failed_images.append(event.src_path)
break

try:
# Start processing
img_batch = self.pipeline.load_raw_image(event.src_path)
Expand Down
Loading