def create_app(handle, instance): check.inst_param(handle, 'handle', ExecutionTargetHandle) check.inst_param(instance, 'instance', DagsterInstance) app = Flask('dagster-ui') sockets = Sockets(app) app.app_protocol = lambda environ_path_info: 'graphql-ws' schema = create_schema() subscription_server = DagsterSubscriptionServer(schema=schema) execution_manager = MultiprocessingExecutionManager() print('Loading repository...') context = DagsterGraphQLContext(handle=handle, instance=instance, execution_manager=execution_manager, version=__version__) app.add_url_rule( '/graphql', 'graphql', DagsterGraphQLView.as_view( 'graphql', schema=schema, graphiql=True, # XXX(freiksenet): Pass proper ws url graphiql_template=PLAYGROUND_TEMPLATE, executor=Executor(), context=context, ), ) sockets.add_url_rule( '/graphql', 'graphql', dagster_graphql_subscription_view(subscription_server, context)) app.add_url_rule( # should match the `build_local_download_url` '/download/<string:run_id>/<string:step_key>/<string:file_type>', 'download_view', download_view(context), ) # these routes are specifically for the Dagit UI and are not part of the graphql # API that we want other people to consume, so they're separate for now. # Also grabbing the magic global request args dict so that notebook_view is testable app.add_url_rule('/dagit/notebook', 'notebook', lambda: notebook_view(request.args)) app.add_url_rule('/static/<path:path>/<string:file>', 'static_view', static_view) app.add_url_rule('/vendor/<path:path>/<string:file>', 'vendor_view', vendor_view) app.add_url_rule('/<path:_path>', 'index_catchall', index_view) app.add_url_rule('/', 'index', index_view, defaults={'_path': ''}) CORS(app) return app
def create_app(handle, pipeline_run_storage, use_synchronous_execution_manager=False): check.inst_param(handle, 'handle', ExecutionTargetHandle) check.inst_param(pipeline_run_storage, 'pipeline_run_storage', PipelineRunStorage) check.bool_param(use_synchronous_execution_manager, 'use_synchronous_execution_manager') app = Flask('dagster-ui') sockets = Sockets(app) app.app_protocol = lambda environ_path_info: 'graphql-ws' schema = create_schema() subscription_server = DagsterSubscriptionServer(schema=schema) if use_synchronous_execution_manager: execution_manager = SynchronousExecutionManager() else: execution_manager = MultiprocessingExecutionManager() context = DagsterGraphQLContext( handle=handle, pipeline_runs=pipeline_run_storage, execution_manager=execution_manager, version=__version__, ) app.add_url_rule( '/graphql', 'graphql', DagsterGraphQLView.as_view( 'graphql', schema=schema, graphiql=True, # XXX(freiksenet): Pass proper ws url graphiql_template=PLAYGROUND_TEMPLATE, executor=Executor(), context=context, ), ) sockets.add_url_rule( '/graphql', 'graphql', dagster_graphql_subscription_view(subscription_server, context)) # these routes are specifically for the Dagit UI and are not part of the graphql # API that we want other people to consume, so they're separate for now. # Also grabbing the magic glabl request args dict so that notebook_view is testable app.add_url_rule('/dagit/notebook', 'notebook', lambda: notebook_view(request.args)) app.add_url_rule('/static/<path:path>/<string:file>', 'static_view', static_view) app.add_url_rule('/<path:_path>', 'index_catchall', index_view) app.add_url_rule('/', 'index', index_view, defaults={'_path': ''}) CORS(app) return app
def execute_query(handle, query, variables=None, pipeline_run_storage=None, raise_on_error=False): check.inst_param(handle, 'handle', ExecutionTargetHandle) check.str_param(query, 'query') check.opt_dict_param(variables, 'variables') query = query.strip('\'" \n\t') # We allow external creation of the pipeline_run_storage to support testing contexts where we # need access to the underlying run storage pipeline_run_storage = pipeline_run_storage or PipelineRunStorage() execution_manager = SynchronousExecutionManager() context = DagsterGraphQLContext( handle=handle, pipeline_runs=pipeline_run_storage, execution_manager=execution_manager, raise_on_error=raise_on_error, version=__version__, ) result = graphql( request_string=query, schema=create_schema(), context=context, variables=variables, executor=Executor(), ) result_dict = result.to_dict() # Here we detect if this is in fact an error response # If so, we iterate over the result_dict and the original result # which contains a GraphQLError. If that GraphQL error contains # an original_error property (which is the exception the resolver # has thrown, typically) we serialize the stack trace of that exception # in the 'stack_trace' property of each error to ease debugging if 'errors' in result_dict: check.invariant(len(result_dict['errors']) == len(result.errors)) for python_error, error_dict in zip(result.errors, result_dict['errors']): if hasattr(python_error, 'original_error') and python_error.original_error: error_dict['stack_trace'] = get_stack_trace_array( python_error.original_error) return result_dict
def execute_query_from_cli(repository_container, query, variables): check.str_param(query, 'query') check.opt_str_param(variables, 'variables') query = query.strip('\'" \n\t') create_pipeline_run = InMemoryPipelineRun pipeline_run_storage = PipelineRunStorage( create_pipeline_run=create_pipeline_run) execution_manager = SynchronousExecutionManager() context = DagsterGraphQLContext( repository_container=repository_container, pipeline_runs=pipeline_run_storage, execution_manager=execution_manager, version=__version__, ) # import pdb; pdb.set_trace() result = graphql( request_string=query, schema=create_schema(), context=context, variables=json.loads(variables) if variables else None, executor=Executor(), ) result_dict = result.to_dict() # Here we detect if this is in fact an error response # If so, we iterate over the result_dict and the original result # which contains a GraphQLError. If that GraphQL error contains # an original_error property (which is the exception the resolver # has thrown, typically) we serialize the stack trace of that exception # in the 'stack_trace' property of each error to ease debugging if 'errors' in result_dict: check.invariant(len(result_dict['errors']) == len(result.errors)) for python_error, error_dict in zip(result.errors, result_dict['errors']): if hasattr(python_error, 'original_error') and python_error.original_error: error_dict['stack_trace'] = get_stack_trace_array( python_error.original_error) str_res = seven.json.dumps(result_dict) print(str_res) return str_res
def instantiate_app_with_views(context): app = Flask( 'dagster-ui', static_url_path='', static_folder=os.path.join(os.path.dirname(__file__), './webapp/build'), ) sockets = Sockets(app) app.app_protocol = lambda environ_path_info: 'graphql-ws' schema = create_schema() subscription_server = DagsterSubscriptionServer(schema=schema) app.add_url_rule( '/graphql', 'graphql', DagsterGraphQLView.as_view( 'graphql', schema=schema, graphiql=True, # XXX(freiksenet): Pass proper ws url graphiql_template=PLAYGROUND_TEMPLATE, executor=Executor(), context=context, ), ) app.add_url_rule('/graphiql', 'graphiql', lambda: redirect('/graphql', 301)) sockets.add_url_rule( '/graphql', 'graphql', dagster_graphql_subscription_view(subscription_server, context)) app.add_url_rule( # should match the `build_local_download_url` '/download/<string:run_id>/<string:step_key>/<string:file_type>', 'download_view', download_view(context), ) # these routes are specifically for the Dagit UI and are not part of the graphql # API that we want other people to consume, so they're separate for now. # Also grabbing the magic global request args dict so that notebook_view is testable app.add_url_rule('/dagit/notebook', 'notebook', lambda: notebook_view(request.args)) app.add_url_rule('/dagit_info', 'sanity_view', info_view) app.register_error_handler(404, index_view) CORS(app) return app
def create_app(repository_container, pipeline_runs, use_synchronous_execution_manager=False): app = Flask('dagster-ui') sockets = Sockets(app) app.app_protocol = lambda environ_path_info: 'graphql-ws' schema = create_schema() subscription_server = DagsterSubscriptionServer(schema=schema) if use_synchronous_execution_manager: execution_manager = SynchronousExecutionManager() else: execution_manager = MultiprocessingExecutionManager() context = DagsterGraphQLContext( repository_container=repository_container, pipeline_runs=pipeline_runs, execution_manager=execution_manager, version=__version__, ) app.add_url_rule( '/graphql', 'graphql', DagsterGraphQLView.as_view( 'graphql', schema=schema, graphiql=True, # XXX(freiksenet): Pass proper ws url graphiql_template=PLAYGROUND_TEMPLATE, executor=Executor(), context=context, ), ) sockets.add_url_rule( '/graphql', 'graphql', dagster_graphql_subscription_view(subscription_server, context) ) # these routes are specifically for the Dagit UI and are not part of the graphql # API that we want other people to consume, so they're separate for now. app.add_url_rule('/dagit/notebook', 'notebook', notebook_view) app.add_url_rule('/static/<path:path>/<string:file>', 'static_view', static_view) app.add_url_rule('/<path:_path>', 'index_catchall', index_view) app.add_url_rule('/', 'index', index_view, defaults={'_path': ''}) CORS(app) return app
def execute_query_from_cli(repository_container, query, variables): check.str_param(query, 'query') check.opt_str_param(variables, 'variables') create_pipeline_run = InMemoryPipelineRun pipeline_run_storage = PipelineRunStorage(create_pipeline_run=create_pipeline_run) execution_manager = SynchronousExecutionManager() context = DagsterGraphQLContext( repository_container=repository_container, pipeline_runs=pipeline_run_storage, execution_manager=execution_manager, ) result = graphql( request_string=query, schema=create_schema(), context=context, variables=json.loads(variables) if variables else None, executor=Executor(), ) print(json.dumps(result.to_dict(), sort_keys=True))
def instantiate_app_with_views(context, schema, app_path_prefix, target_dir=os.path.dirname(__file__)): app = Flask( "dagster-ui", static_url_path=app_path_prefix, static_folder=os.path.join(target_dir, "./webapp/build"), ) subscription_server = DagsterSubscriptionServer(schema=schema) # Websocket routes sockets = Sockets(app) sockets.add_url_rule( f"{app_path_prefix}/graphql", "graphql", dagster_graphql_subscription_view(subscription_server, context), ) # HTTP routes bp = Blueprint("routes", __name__, url_prefix=app_path_prefix) bp.add_url_rule("/graphiql", "graphiql", lambda: redirect(f"{app_path_prefix}/graphql", 301)) bp.add_url_rule( "/graphql", "graphql", DagsterGraphQLView.as_view( "graphql", schema=schema, graphiql=True, graphiql_template=PLAYGROUND_TEMPLATE, executor=Executor(), context=context, ), ) bp.add_url_rule( # should match the `build_local_download_url` "/download/<string:run_id>/<string:step_key>/<string:file_type>", "download_view", download_log_view(context), ) bp.add_url_rule( "/download_debug/<string:run_id>", "download_dump_view", download_dump_view(context), ) # these routes are specifically for the Dagit UI and are not part of the graphql # API that we want other people to consume, so they're separate for now. # Also grabbing the magic global request args dict so that notebook_view is testable bp.add_url_rule("/dagit/notebook", "notebook", lambda: notebook_view(request.args)) bp.add_url_rule("/dagit_info", "sanity_view", info_view) index_path = os.path.join(target_dir, "./webapp/build/index.html") def index_view(): try: with open(index_path) as f: rendered_template = render_template_string(f.read()) return rendered_template.replace( 'src="/static', f'src="{app_path_prefix}/static').replace( 'href="/static', f'href="{app_path_prefix}/static') except FileNotFoundError: raise Exception( """Can't find webapp files. Probably webapp isn't built. If you are using dagit, then probably it's a corrupted installation or a bug. However, if you are developing dagit locally, your problem can be fixed as follows: cd ./python_modules/ make rebuild_dagit""") def error_redirect(_path): return index_view() bp.add_url_rule("/", "index_view", index_view) bp.context_processor(lambda: {"app_path_prefix": app_path_prefix}) app.app_protocol = lambda environ_path_info: "graphql-ws" app.register_blueprint(bp) app.register_error_handler(404, error_redirect) # if the user asked for a path prefix, handle the naked domain just in case they are not # filtering inbound traffic elsewhere and redirect to the path prefix. if app_path_prefix: app.add_url_rule("/", "force-path-prefix", lambda: redirect(app_path_prefix, 301)) CORS(app) return app
def create_app(handle, instance, reloader=None): check.inst_param(handle, 'handle', ExecutionTargetHandle) check.inst_param(instance, 'instance', DagsterInstance) check.opt_inst_param(reloader, 'reloader', Reloader) app = Flask('dagster-ui') sockets = Sockets(app) app.app_protocol = lambda environ_path_info: 'graphql-ws' schema = create_schema() subscription_server = DagsterSubscriptionServer(schema=schema) execution_manager_settings = instance.dagit_settings.get( 'execution_manager') if execution_manager_settings and execution_manager_settings.get( 'max_concurrent_runs'): execution_manager = QueueingSubprocessExecutionManager( instance, execution_manager_settings.get('max_concurrent_runs')) else: execution_manager = SubprocessExecutionManager(instance) warn_if_compute_logs_disabled() print('Loading repository...') context = DagsterGraphQLContext( handle=handle, instance=instance, execution_manager=execution_manager, reloader=reloader, version=__version__, ) # Automatically initialize scheduler everytime Dagit loads scheduler_handle = context.scheduler_handle scheduler = instance.scheduler if scheduler_handle: if scheduler: handle = context.get_handle() python_path = sys.executable repository_path = handle.data.repository_yaml repository = context.get_repository() scheduler_handle.up(python_path, repository_path, repository=repository, instance=instance) else: warnings.warn(MISSING_SCHEDULER_WARNING) app.add_url_rule( '/graphql', 'graphql', DagsterGraphQLView.as_view( 'graphql', schema=schema, graphiql=True, # XXX(freiksenet): Pass proper ws url graphiql_template=PLAYGROUND_TEMPLATE, executor=Executor(), context=context, ), ) sockets.add_url_rule( '/graphql', 'graphql', dagster_graphql_subscription_view(subscription_server, context)) app.add_url_rule( # should match the `build_local_download_url` '/download/<string:run_id>/<string:step_key>/<string:file_type>', 'download_view', download_view(context), ) # these routes are specifically for the Dagit UI and are not part of the graphql # API that we want other people to consume, so they're separate for now. # Also grabbing the magic global request args dict so that notebook_view is testable app.add_url_rule('/dagit/notebook', 'notebook', lambda: notebook_view(request.args)) app.add_url_rule('/static/<path:path>/<string:file>', 'static_view', static_view) app.add_url_rule('/vendor/<path:path>/<string:file>', 'vendor_view', vendor_view) app.add_url_rule('/<string:worker_name>.worker.js', 'worker_view', worker_view) app.add_url_rule('/dagit_info', 'sanity_view', info_view) app.add_url_rule('/<path:_path>', 'index_catchall', index_view) app.add_url_rule('/', 'index', index_view, defaults={'_path': ''}) CORS(app) return app
def instantiate_app_with_views(context, app_path_prefix): app = Flask( 'dagster-ui', static_url_path=app_path_prefix, static_folder=os.path.join(os.path.dirname(__file__), './webapp/build'), ) schema = create_schema() subscription_server = DagsterSubscriptionServer(schema=schema) # Websocket routes sockets = Sockets(app) sockets.add_url_rule( '{}/graphql'.format(app_path_prefix), 'graphql', dagster_graphql_subscription_view(subscription_server, context), ) # HTTP routes bp = Blueprint('routes', __name__, url_prefix=app_path_prefix) bp.add_url_rule( '/graphiql', 'graphiql', lambda: redirect('{}/graphql'.format(app_path_prefix), 301) ) bp.add_url_rule( '/graphql', 'graphql', DagsterGraphQLView.as_view( 'graphql', schema=schema, graphiql=True, graphiql_template=PLAYGROUND_TEMPLATE.replace('APP_PATH_PREFIX', app_path_prefix), executor=Executor(), context=context, ), ) bp.add_url_rule( # should match the `build_local_download_url` '/download/<string:run_id>/<string:step_key>/<string:file_type>', 'download_view', download_view(context), ) # these routes are specifically for the Dagit UI and are not part of the graphql # API that we want other people to consume, so they're separate for now. # Also grabbing the magic global request args dict so that notebook_view is testable bp.add_url_rule('/dagit/notebook', 'notebook', lambda: notebook_view(request.args)) bp.add_url_rule('/dagit_info', 'sanity_view', info_view) index_path = os.path.join(os.path.dirname(__file__), './webapp/build/index.html') def index_view(_path): try: with open(index_path) as f: return ( f.read() .replace('href="/', 'href="{}/'.format(app_path_prefix)) .replace('src="/', 'src="{}/'.format(app_path_prefix)) .replace( '<meta name="dagit-path-prefix"', '<meta name="dagit-path-prefix" content="{}"'.format(app_path_prefix), ) ) except seven.FileNotFoundError: raise Exception( '''Can't find webapp files. Probably webapp isn't built. If you are using dagit, then probably it's a corrupted installation or a bug. However, if you are developing dagit locally, your problem can be fixed as follows: cd ./python_modules/ make rebuild_dagit''' ) app.app_protocol = lambda environ_path_info: 'graphql-ws' app.register_blueprint(bp) app.register_error_handler(404, index_view) # if the user asked for a path prefix, handle the naked domain just in case they are not # filtering inbound traffic elsewhere and redirect to the path prefix. if app_path_prefix: app.add_url_rule('/', 'force-path-prefix', lambda: redirect(app_path_prefix, 301)) CORS(app) return app