Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xy] Support Airflow integration #665

Merged
merged 6 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mage_ai/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def main():
sys.path.append(os.path.dirname(project_path))
pipeline = Pipeline(pipeline_uuid, project_path)

asyncio.run(pipeline.execute(analyze_outputs=False))
asyncio.run(pipeline.execute(analyze_outputs=False, update_status=False))


if __name__ == "__main__":
Expand Down
26 changes: 21 additions & 5 deletions mage_ai/data_preparation/models/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,29 +157,45 @@ def delete(self):
p.delete_block(p.get_block(self.uuid))
os.remove(self.file_path)

def execute_sync(self, analyze_outputs=True, custom_code=None, redirect_outputs=False):
def execute_sync(
self,
analyze_outputs=True,
custom_code=None,
redirect_outputs=False,
update_status=True,
):
try:
output = self.execute_block(custom_code=custom_code, redirect_outputs=redirect_outputs)
block_output = output['output']
self.__verify_outputs(block_output)
variable_mapping = dict(zip(self.output_variables.keys(), block_output))
self.__store_variables(variable_mapping)
self.status = BlockStatus.EXECUTED
if update_status:
self.status = BlockStatus.EXECUTED
if analyze_outputs:
self.__analyze_outputs(variable_mapping)
except Exception as err:
self.status = BlockStatus.FAILED
if update_status:
self.status = BlockStatus.FAILED
raise Exception(f'Exception encountered in block {self.uuid}') from err
finally:
self.__update_pipeline_block()
if update_status:
self.__update_pipeline_block()
return output

async def execute(self, analyze_outputs=True, custom_code=None, redirect_outputs=False):
async def execute(
self,
analyze_outputs=True,
custom_code=None,
redirect_outputs=False,
update_status=True,
):
with VerboseFunctionExec(f'Executing {self.type} block: {self.uuid}'):
return self.execute_sync(
analyze_outputs=analyze_outputs,
custom_code=custom_code,
redirect_outputs=redirect_outputs,
update_status=update_status,
)

def __validate_execution(self, decorated_functions, input_vars):
Expand Down
14 changes: 12 additions & 2 deletions mage_ai/data_preparation/models/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ def block_deletable(self, block):
return True
return len(self.blocks_by_uuid[block.uuid].downstream_blocks) == 0

async def execute(self, analyze_outputs=True, run_all_blocks=False, redirect_outputs=False):
async def execute(
self,
analyze_outputs=True,
run_all_blocks=False,
redirect_outputs=False,
update_status=True,
):
"""
Async function for parallel processing
This function will schedule the block execution in topological
Expand All @@ -118,7 +124,11 @@ async def execute(self, analyze_outputs=True, run_all_blocks=False, redirect_out
continue
await asyncio.gather(*[tasks[u.uuid] for u in block.upstream_blocks])
task = asyncio.create_task(
block.execute(analyze_outputs=analyze_outputs, redirect_outputs=redirect_outputs)
block.execute(
analyze_outputs=analyze_outputs,
redirect_outputs=redirect_outputs,
update_status=update_status,
)
)
tasks[block.uuid] = task
for downstream_block in block.downstream_blocks:
Expand Down
1 change: 1 addition & 0 deletions mage_ai/data_preparation/templates/repo/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
variables_dir: ./
17 changes: 16 additions & 1 deletion mage_ai/data_preparation/variable_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
from typing import Any, Dict, List
import os
import pandas as pd
import yaml


class VariableManager:
def __init__(self, repo_path=None):
self.repo_path = repo_path or get_repo_path()
self.variables_dir = self.repo_path
try:
with open(os.path.join(self.repo_path, 'metadata.yaml')) as f:
repo_config = yaml.full_load(f) or {}
variables_dir = repo_config.get('variables_dir')
if variables_dir is not None:
self.variables_dir = os.path.abspath(
os.path.join(self.repo_path, variables_dir),
)
except Exception:
pass
# TODO: implement caching logic

def add_variable(
Expand Down Expand Up @@ -87,7 +99,10 @@ def get_variables_by_block(self, pipeline_uuid: str, block_uuid: str) -> Dict[st
return sorted([v.split('.')[0] for v in variables])

def __pipeline_path(self, pipeline_uuid: str) -> str:
return os.path.join(self.repo_path, 'pipelines', pipeline_uuid)
path = os.path.join(self.variables_dir, 'pipelines', pipeline_uuid)
if not os.path.exists(path):
os.makedirs(path, exist_ok=True)
return path


def get_global_variable(pipeline_uuid: str, key: str) -> Any:
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Faker==4.14.0
Flask==2.1.2
Jinja2==3.1.2
Flask~=1.1.2
Jinja2~=3.0.3
MarkupSafe==2.1.1
Werkzeug==2.1.2
Werkzeug~=2.0.0
asyncio==3.4.3
beautifulsoup4
boto3==1.24.19
Expand All @@ -12,7 +12,7 @@ flask-cors==3.0.10
importlib-metadata==4.11.3
ipykernel==6.15.0
ipython
itsdangerous==2.1.2
itsdangerous~=1.1.0
joblib>=1.1.0
jupyter_client==7.3.4
google-cloud-bigquery==3.2.0
Expand Down