-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from cgat-developers/AC-kubernetes
Ac kubernetes
- Loading branch information
Showing
11 changed files
with
872 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
codecov: | ||
notify: | ||
require_ci_to_pass: yes | ||
|
||
coverage: | ||
precision: 2 | ||
round: down | ||
paths: | ||
- ./cgatcore/** | ||
ignore: | ||
- tests/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# cgatcore/pipeline/base_executor.py | ||
import os | ||
import tempfile | ||
|
||
|
||
class BaseExecutor: | ||
"""Base class for executors that defines the interface for running jobs.""" | ||
|
||
def __init__(self, **kwargs): | ||
"""Initialize the executor with configuration options.""" | ||
self.config = kwargs | ||
self.task_name = "base_task" # Should be overridden by subclasses | ||
self.default_total_time = 0 # Should be overridden by subclasses | ||
|
||
def run(self, statement, *args, **kwargs): | ||
"""Run the given job statement. This should be implemented by subclasses.""" | ||
raise NotImplementedError("Subclasses must implement this method") | ||
|
||
def collect_metric_data(self, *args, **kwargs): | ||
"""Collect metric data if needed.""" | ||
raise NotImplementedError("Subclasses must implement this method") | ||
|
||
def collect_benchmark_data(self, statements, resource_usage=None): | ||
"""Collect benchmark data for job execution. | ||
Args: | ||
statements (list): List of executed statements | ||
resource_usage (list, optional): Resource usage data | ||
Returns: | ||
dict: Benchmark data including task name and execution time | ||
""" | ||
return { | ||
"task": self.task_name, | ||
"total_t": self.default_total_time, | ||
"statements": statements, | ||
"resource_usage": resource_usage or [] | ||
} | ||
|
||
def build_job_script(self, statement): | ||
"""Build a simple job script for execution. | ||
Args: | ||
statement (str): The command or script to be executed. | ||
Returns: | ||
tuple: A tuple containing the full command (as a string) and the path where the job script is stored. | ||
""" | ||
|
||
job_script_dir = self.config.get("job_script_dir", tempfile.gettempdir()) | ||
os.makedirs(job_script_dir, exist_ok=True) | ||
|
||
script_path = os.path.join(job_script_dir, "job_script.sh") | ||
with open(script_path, "w") as script_file: | ||
script_file.write(f"#!/bin/bash\n\n{statement}\n") | ||
|
||
os.chmod(script_path, 0o755) # Make it executable | ||
return statement, script_path | ||
|
||
def __enter__(self): | ||
"""Enter the runtime context related to this object.""" | ||
# Any initialisation logic needed for the executor can be added here | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
"""Exit the runtime context related to this object.""" | ||
# Cleanup logic, if any, can be added here | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.