Skip to content

Commit

Permalink
Remove dead code in MCPServer
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein authored and replaceafill committed May 22, 2024
1 parent d28909e commit 27491ce
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 62 deletions.
38 changes: 10 additions & 28 deletions src/MCPServer/lib/server/jobs/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
"""
import logging

from django.utils import timezone
from server.jobs.client import ClientScriptJob
from server.jobs.client import DirectoryClientScriptJob
from server.jobs.client import FilesClientScriptJob
from server.jobs.client import OutputClientScriptJob
Expand Down Expand Up @@ -73,7 +71,6 @@ def __init__(self, package, chain, workflow, starting_link=None):
self.package = package
self.chain = chain
self.workflow = workflow
self.started_on = timezone.now()

self.initial_link = starting_link or self.chain.link
self.current_link = None
Expand Down Expand Up @@ -106,35 +103,20 @@ def __next__(self):
except KeyError:
next_link = None

if next_link:
self.current_link = next_link
job_class = get_job_class_for_link(self.current_link)
self.current_job = job_class(self, self.current_link, self.package)
return self.current_job
else:
# Chain completion.
if not next_link:
self.current_link = None
self.current_job = None
self.chain_completed()
logger.debug(
"Done with chain %s for package %s", self.id, self.package.uuid
)
raise StopIteration

self.current_link = next_link
job_class = get_job_class_for_link(self.current_link)
self.current_job = job_class(self, self.current_link, self.package)
return self.current_job

@property
def id(self):
return self.chain.id

def job_completed(self):
logger.debug(
"%s %s done with exit code %s",
self.current_job.__class__.__name__,
self.current_job.uuid,
self.current_job.exit_code,
)
if isinstance(self.current_job, ClientScriptJob):
self.current_job.update_status_from_exit_code()
else:
self.current_job.mark_complete()

def chain_completed(self):
"""Log chain completion"""
logger.debug(
"Done with chain %s for package %s", self.chain.id, self.package.uuid
)
11 changes: 5 additions & 6 deletions src/MCPServer/lib/server/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,17 @@ def watched_dir_handler(package_queue, path, watched_dir):
logger.debug("Starting chain for %s", path)

package = None
package_type = watched_dir["unit_type"]
watched_dir_path = watched_dir["path"]
package_type = watched_dir.unit_type
is_dir = os.path.isdir(path)

if package_type == "SIP" and is_dir:
package = SIP.get_or_create_from_db_by_path(path, watched_dir_path)
package = SIP.get_or_create_from_db_by_path(path, watched_dir.path)
elif package_type == "DIP" and is_dir:
package = DIP.get_or_create_from_db_by_path(path, watched_dir_path)
package = DIP.get_or_create_from_db_by_path(path, watched_dir.path)
elif package_type == "Transfer" and is_dir:
package = Transfer.get_or_create_from_db_by_path(path, watched_dir_path)
package = Transfer.get_or_create_from_db_by_path(path, watched_dir.path)
elif package_type == "Transfer" and not is_dir:
package = Transfer.get_or_create_from_db_by_path(path, watched_dir_path)
package = Transfer.get_or_create_from_db_by_path(path, watched_dir.path)
else:
raise ValueError(f"Unexpected unit type given for file {path}")

Expand Down
22 changes: 0 additions & 22 deletions src/MCPServer/lib/server/processing_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import abc
import logging
import os
import shutil

import storageService as storage_service
from django.conf import settings
Expand Down Expand Up @@ -300,27 +299,6 @@ def get_processing_fields(workflow, lang="en"):
return [field.to_dict(workflow, lang) for field in processing_fields]


def copy_processing_config(processing_config, destination_path):
if processing_config is None:
return

src = os.path.join(
settings.SHARED_DIRECTORY,
"sharedMicroServiceTasksConfigs/processingMCPConfigs",
"%sProcessingMCP.xml" % processing_config,
)
dest = os.path.join(destination_path, "processingMCP.xml")
try:
shutil.copyfile(src, dest)
except OSError:
logger.warning(
"Processing configuration could not be copied: (from=%s to=%s)",
src,
dest,
exc_info=True,
)


def load_processing_xml(package_path):
processing_file_path = os.path.join(package_path, settings.PROCESSING_XML_FILE)

Expand Down
4 changes: 0 additions & 4 deletions src/MCPServer/lib/server/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,6 @@ def process_one_job(self, timeout=None):

return result

def stop(self):
"""Trigger queue shutdown."""
self.shutdown_event.set()

def _package_completed_callback(self, package, link_id, future):
"""Marks the package as inactive and schedules a new package.
Expand Down
4 changes: 2 additions & 2 deletions tests/MCPServer/test_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_watched_dir_handler_creates_transfer_if_it_does_not_exist(mocker, tmpdi
job_chain_mock.return_value = iter(["some_chain_link"])
mocker.patch("server.mcp.JobChain", job_chain_mock)
package_queue = mocker.Mock()
watched_dir = mocker.MagicMock(**{"__getitem__.return_value": "Transfer"})
watched_dir = mocker.MagicMock(unit_type="Transfer")

# Mock a known UUID for the new transfer.
transfer_uuid = uuid.uuid4()
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_watched_dir_handler_creates_transfer_for_file(mocker, tmpdir):
job_chain_mock.return_value = iter(["some_chain_link"])
mocker.patch("server.mcp.JobChain", job_chain_mock)
package_queue = mocker.Mock()
watched_dir = mocker.MagicMock(**{"__getitem__.return_value": "Transfer"})
watched_dir = mocker.MagicMock(unit_type="Transfer")

# Mock a known UUID for the new transfer.
transfer_uuid = uuid.uuid4()
Expand Down

0 comments on commit 27491ce

Please sign in to comment.