Skip to content

Commit

Permalink
Merge pull request #24 from Sage-Bionetworks-Workflows/bwmac/orca-209…
Browse files Browse the repository at this point in the history
…/monitor_synapse_submission_queue

[ORCA-209] Monitor Submission View
  • Loading branch information
BWMac authored May 31, 2023
2 parents dcb324b + 121937d commit d6e5782
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/orca/services/synapse/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,18 @@ def fs(self) -> SynapseFS:
raise ConfigError(message)

return SynapseFS(auth_token=auth_token)

def monitor_evaluation_queue(self, evaluation_id: str) -> bool:
"""Monitor an evaluation queue in Synapse.
Args:
evaluation_id: The Synapse ID of the queue to monitor.
Returns:
True if there are "RECEIVED" submissions, False otherwise.
"""
received_submissions = self.client.getSubmissionBundles(
evaluation_id, status="RECEIVED"
)
submissions_num = sum(1 for submission in received_submissions)
return submissions_num > 0
24 changes: 24 additions & 0 deletions tests/services/synapse/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
import pytest

from orca.services.synapse import SynapseClientFactory, SynapseConfig, SynapseOps


@pytest.fixture
def syn_project_id():
yield "syn51469029"


@pytest.fixture
def config(patch_os_environ):
yield SynapseConfig("foo")


@pytest.fixture
def client(config):
factory = SynapseClientFactory(config=config)
yield factory.create_client()


@pytest.fixture
def mocked_ops(config, client, mocker):
mocker.patch.object(SynapseOps, "client", return_value=client)
yield SynapseOps(config)


@pytest.fixture
def ops(config):
yield SynapseOps(config)
24 changes: 24 additions & 0 deletions tests/services/synapse/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,27 @@ def test_for_an_error_when_accessing_fs_without_credentials(
ops = SynapseOps()
with pytest.raises(ConfigError):
ops.fs.listdir(syn_project_id)


def test_monitor_evaluation_queue_returns_false_when_there_are_no_new_submissions(
mocker, mocked_ops
):
mock = mocker.patch.object(
mocked_ops.client, "getSubmissionBundles", return_value=[]
)
result = mocked_ops.monitor_evaluation_queue("foo")
mock.assert_called_once_with("foo", status="RECEIVED")
assert result is False


def test_monitor_evaluation_queue_returns_true_when_there_are_new_submissions(
mocker, mocked_ops
):
mock = mocker.patch.object(
mocked_ops.client,
"getSubmissionBundles",
return_value=["submission_1", "submission_2"],
)
result = mocked_ops.monitor_evaluation_queue("foo")
mock.assert_called_once_with("foo", status="RECEIVED")
assert result

0 comments on commit d6e5782

Please sign in to comment.