Skip to content

Commit

Permalink
fix!: remove latency wait support as this should rather be handled in…
Browse files Browse the repository at this point in the history
… main Snakemake (as it is already done). The reason is that the plugin cannot distinguish between cases where latency has to be taken into accound and where not, leading to overall much slower processing when latency wait is applied regardless of the context. This introduces a breaking change because this plugin now does not offer any settings anymore. (#13)
  • Loading branch information
johanneskoester authored Feb 24, 2024
1 parent 2132a5a commit 1c78d88
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.
37 changes: 1 addition & 36 deletions snakemake_storage_plugin_fs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
from dataclasses import dataclass, field
from functools import wraps
import os
from pathlib import Path
import shutil
import subprocess
import time
from typing import Any, Iterable, List, Optional

import sysrsync
from reretry import retry

from snakemake_interface_common.logging import get_logger
from snakemake_interface_common.exceptions import WorkflowError
from snakemake_interface_storage_plugins.storage_provider import (
StorageProviderBase,
Expand All @@ -30,22 +25,9 @@
get_constant_prefix,
Mtime,
)
from snakemake_interface_storage_plugins.settings import StorageProviderSettingsBase
from snakemake_interface_common.utils import lutime


@dataclass
class StorageProviderSettings(StorageProviderSettingsBase):
latency_wait: Optional[int] = field(
default=1,
metadata={
"help": "Time in seconds to wait until retry if file operation is not "
"successfull. This is useful to deal with filesystem latency as it can "
"occur with network filesystems. Default is 1 second.",
},
)


# Required:
# Implementation of your storage provider
# This class can be empty as the one below.
Expand Down Expand Up @@ -124,16 +106,6 @@ def list_objects(self, query: Any) -> Iterable[str]:
return ()


def latency_wait(f):
@wraps(f)
def wrapper(self, *args, **kwargs):
return retry(
tries=2, delay=self.provider.settings.latency_wait, logger=get_logger()
)(f)(self, *args, **kwargs)

return wrapper


# Required:
# Implementation of storage object. If certain methods cannot be supported by your
# storage (e.g. because it is read-only see
Expand Down Expand Up @@ -204,13 +176,7 @@ def cleanup(self):

def exists(self) -> bool:
# return True if the object exists
exists = self.query_path.exists()
if not exists and self.provider.settings.latency_wait:
# Retry once
time.sleep(self.provider.settings.latency_wait)
return self.query_path.exists()
else:
return exists
return self.query_path.exists()

def mtime(self) -> float:
# return the modification time
Expand Down Expand Up @@ -264,7 +230,6 @@ def list_candidate_matches(self) -> Iterable[str]:
else:
return (prefix,)

@latency_wait
def _stat(self, follow_symlinks: bool = True):
# We don't want the cached variant (Path.stat), as we cache ourselves in
# inventory and afterwards the information may change.
Expand Down
6 changes: 2 additions & 4 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from snakemake_interface_storage_plugins.tests import TestStorageBase
from snakemake_interface_storage_plugins.storage_provider import StorageProviderBase
from snakemake_interface_storage_plugins.settings import StorageProviderSettingsBase
from snakemake_storage_plugin_fs import StorageProvider, StorageProviderSettings
from snakemake_storage_plugin_fs import StorageProvider


class TestStorageNoSettings(TestStorageBase):
Expand All @@ -24,6 +24,4 @@ def get_storage_provider_cls(self) -> Type[StorageProviderBase]:
return StorageProvider

def get_storage_provider_settings(self) -> Optional[StorageProviderSettingsBase]:
return StorageProviderSettings(
latency_wait=1,
)
return None

0 comments on commit 1c78d88

Please sign in to comment.