-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
133 additions
and
430 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
Empty file.
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
import argparse | ||
import os | ||
import sys | ||
|
||
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../")) | ||
|
||
from distributaur.core import submit_task | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Distributaur CLI") | ||
parser.add_argument("--code", type=str, help="Python code to execute.") | ||
args = parser.parse_args() | ||
|
||
result = submit_task(args.code) | ||
print(f"Execution Result: {result}") | ||
|
||
if __name__ == "__main__": | ||
main() |
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,33 @@ | ||
# core.py | ||
|
||
from celery import Celery | ||
from .environment import get_redis_url | ||
from .decorators import register_task | ||
|
||
app = Celery("distributaur_tasks", broker=get_redis_url(), backend=get_redis_url()) | ||
|
||
@app.task(bind=True) | ||
def execute_python_code(self, code): | ||
try: | ||
local_scope = {} | ||
exec(code, {'__builtins__': None}, local_scope) | ||
return local_scope.get('result', None) # Assuming the code defines 'result' | ||
except Exception as e: | ||
print(f"Error executing code: {str(e)}") | ||
return None | ||
|
||
def submit_task(code): | ||
""" | ||
Submits a Python code execution task to the Celery worker. | ||
Args: | ||
code (str): Python code to execute. | ||
Returns: | ||
result: The result of the Python code execution or None if an error occurs. | ||
""" | ||
try: | ||
result = app.send_task('execute_python_code', args=[code]) | ||
return result.get(timeout=10) # Waits for the task to complete and returns the result | ||
except Exception as e: | ||
print(f"Failed to submit task: {str(e)}") | ||
return None |
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,5 @@ | ||
def register_task(app): | ||
def decorator(func): | ||
task = app.task(bind=True)(func) | ||
return func | ||
return decorator |
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,17 @@ | ||
import os | ||
|
||
def get_redis_url(): | ||
"""Constructs the Redis connection URL from environment variables.""" | ||
host = os.getenv("REDIS_HOST", "localhost") | ||
password = os.getenv("REDIS_PASSWORD", None) | ||
port = os.getenv("REDIS_PORT", 6379) | ||
return f"redis://:{password}@{host}:{port}" if password else f"redis://{host}:{port}" | ||
|
||
def get_env_vars(): | ||
"""Loads environment variables critical for Distributaur operations.""" | ||
required_vars = ["VAST_API_KEY", "REDIS_HOST", "REDIS_PORT"] | ||
env_vars = {var: os.getenv(var) for var in required_vars} | ||
if not all(env_vars.values()): | ||
missing = [var for var, value in env_vars.items() if not value] | ||
raise EnvironmentError(f"Missing critical environment variables: {', '.join(missing)}") | ||
return env_vars |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
from .vast import * | ||
from distributaur.vast import * |
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.