Esempio n. 1
0
File: app.py Progetto: xjhc/dagster
def create_app_from_workspace(workspace: Workspace,
                              instance: DagsterInstance,
                              path_prefix: str = ""):
    check.inst_param(workspace, "workspace", Workspace)
    check.inst_param(instance, "instance", DagsterInstance)
    check.str_param(path_prefix, "path_prefix")

    if path_prefix:
        if not path_prefix.startswith("/"):
            raise Exception(
                f'The path prefix should begin with a leading "/": got {path_prefix}'
            )
        if path_prefix.endswith("/"):
            raise Exception(
                f'The path prefix should not include a trailing "/": got {path_prefix}'
            )

    warn_if_compute_logs_disabled()

    print("Loading repository...")  # pylint: disable=print-call

    context = WorkspaceProcessContext(instance=instance,
                                      workspace=workspace,
                                      version=__version__)

    log_workspace_stats(instance, context)

    schema = create_schema()

    return instantiate_app_with_views(context, schema, path_prefix)
Esempio n. 2
0
def create_app_with_reconstructable_repo(recon_repo, instance, reloader=None):
    check.inst_param(recon_repo, 'recon_repo', ReconstructableRepository)
    check.inst_param(instance, 'instance', DagsterInstance)
    check.opt_inst_param(reloader, 'reloader', Reloader)

    warn_if_compute_logs_disabled()

    print('Loading repository...')
    context = DagsterGraphQLContext(
        instance=instance,
        locations=[InProcessRepositoryLocation(recon_repo, reloader=reloader)],
        version=__version__,
    )

    # Automatically initialize scheduler everytime Dagit loads
    scheduler = instance.scheduler
    repository = context.legacy_get_repository_definition()

    if repository.schedule_defs:
        if scheduler:
            python_path = sys.executable
            repository_path = context.legacy_location.get_reconstructable_repository(
            ).yaml_path
            reconcile_scheduler_state(python_path,
                                      repository_path,
                                      repository=repository,
                                      instance=instance)
        else:
            warnings.warn(MISSING_SCHEDULER_WARNING)

    return instantiate_app_with_views(context)
Esempio n. 3
0
File: app.py Progetto: keyz/dagster
def create_app_from_workspace_process_context(
    workspace_process_context: WorkspaceProcessContext,
    path_prefix: str = "",
) -> Flask:
    check.inst_param(workspace_process_context, "workspace_process_context",
                     WorkspaceProcessContext)
    check.str_param(path_prefix, "path_prefix")

    instance = workspace_process_context.instance

    if path_prefix:
        if not path_prefix.startswith("/"):
            raise Exception(
                f'The path prefix should begin with a leading "/": got {path_prefix}'
            )
        if path_prefix.endswith("/"):
            raise Exception(
                f'The path prefix should not include a trailing "/": got {path_prefix}'
            )

    warn_if_compute_logs_disabled()

    log_workspace_stats(instance, workspace_process_context)

    schema = create_schema()

    return instantiate_app_with_views(workspace_process_context,
                                      schema,
                                      path_prefix,
                                      include_notebook_route=True)
Esempio n. 4
0
def create_app_from_workspace_process_context(
    workspace_process_context: WorkspaceProcessContext,
    path_prefix: str = "",
) -> Starlette:
    check.inst_param(workspace_process_context, "workspace_process_context",
                     WorkspaceProcessContext)
    check.str_param(path_prefix, "path_prefix")

    instance = workspace_process_context.instance

    if path_prefix:
        if not path_prefix.startswith("/"):
            raise Exception(
                f'The path prefix should begin with a leading "/": got {path_prefix}'
            )
        if path_prefix.endswith("/"):
            raise Exception(
                f'The path prefix should not include a trailing "/": got {path_prefix}'
            )

    warn_if_compute_logs_disabled()

    log_workspace_stats(instance, workspace_process_context)

    return DagitWebserver(
        workspace_process_context,
        path_prefix,
    ).create_asgi_app()
Esempio n. 5
0
def create_app_from_workspace(workspace, instance):
    check.inst_param(workspace, 'workspace', Workspace)
    check.inst_param(instance, 'instance', DagsterInstance)

    warn_if_compute_logs_disabled()

    print('Loading repository...')

    locations = []
    for repository_location_handle in workspace.repository_location_handles:
        if isinstance(repository_location_handle,
                      InProcessRepositoryLocationHandle):
            # will need to change for multi repo
            check.invariant(
                len(repository_location_handle.repository_code_pointer_dict) ==
                1)
            pointer = next(
                iter(repository_location_handle.repository_code_pointer_dict.
                     values()))
            recon_repo = ReconstructableRepository(pointer)
            locations.append(InProcessRepositoryLocation(recon_repo))
        elif isinstance(repository_location_handle,
                        PythonEnvRepositoryLocationHandle):
            locations.append(
                PythonEnvRepositoryLocation(repository_location_handle))
        else:
            check.failed('{} unsupported'.format(repository_location_handle))

    context = DagsterGraphQLContext(instance=instance,
                                    locations=locations,
                                    version=__version__)

    return instantiate_app_with_views(context)
Esempio n. 6
0
def create_app_with_execution_handle(handle, instance, reloader=None):
    check.inst_param(handle, 'handle', ExecutionTargetHandle)
    check.inst_param(instance, 'instance', DagsterInstance)
    check.opt_inst_param(reloader, 'reloader', Reloader)

    execution_manager = get_execution_manager(instance)
    warn_if_compute_logs_disabled()

    print('Loading repository...')
    context = DagsterGraphQLInProcessRepositoryContext(
        handle=handle,
        instance=instance,
        execution_manager=execution_manager,
        reloader=reloader,
        version=__version__,
    )

    # Automatically initialize scheduler everytime Dagit loads
    scheduler = instance.scheduler
    repository = context.get_repository()

    if repository.schedule_defs:
        if scheduler:
            handle = context.get_handle()
            python_path = sys.executable
            repository_path = handle.data.repository_yaml
            reconcile_scheduler_state(python_path,
                                      repository_path,
                                      repository=repository,
                                      instance=instance)
        else:
            warnings.warn(MISSING_SCHEDULER_WARNING)

    return instantiate_app_with_views(context)
Esempio n. 7
0
def create_app_with_environments(dagster_environments, instance):
    check.list_param(dagster_environments, 'dagster_environments', of_type=DagsterEnvironment)
    check.inst_param(instance, 'instance', DagsterInstance)

    warn_if_compute_logs_disabled()

    print('Loading repository...')
    context = DagsterGraphQLContext(
        environments=dagster_environments, instance=instance, version=__version__,
    )
    return instantiate_app_with_views(context)
Esempio n. 8
0
def create_app_with_snapshot(repository_snapshot, instance):
    check.inst_param(repository_snapshot, 'snapshot', RepositorySnapshot)
    check.inst_param(instance, 'instance', DagsterInstance)

    execution_manager = get_execution_manager(instance)
    warn_if_compute_logs_disabled()

    print('Loading repository...')
    context = DagsterSnapshotGraphQLContext(
        repository_snapshot=repository_snapshot,
        instance=instance,
        execution_manager=execution_manager,
        version=__version__,
    )
    return instantiate_app_with_views(context)
Esempio n. 9
0
def create_app_with_active_repository_data(active_repository_data, instance):
    check.inst_param(active_repository_data, 'active_repository_data',
                     ActiveRepositoryData)
    check.inst_param(instance, 'instance', DagsterInstance)

    execution_manager = get_execution_manager(instance)
    warn_if_compute_logs_disabled()

    print('Loading repository...')
    context = DagsterGraphQLOutOfProcessRepositoryContext(
        active_repository_data=active_repository_data,
        instance=instance,
        execution_manager=execution_manager,
        version=__version__,
    )
    return instantiate_app_with_views(context)
Esempio n. 10
0
def create_app_with_external_repository(external_repository, instance):
    check.inst_param(external_repository, 'external_repository',
                     ExternalRepository)
    check.inst_param(instance, 'instance', DagsterInstance)

    execution_manager = get_execution_manager(instance)
    warn_if_compute_logs_disabled()

    print('Loading repository...')
    context = DagsterGraphQLOutOfProcessRepositoryContext(
        external_repository=external_repository,
        instance=instance,
        execution_manager=execution_manager,
        version=__version__,
    )
    return instantiate_app_with_views(context)
Esempio n. 11
0
def create_app_from_workspace(workspace, instance, path_prefix=''):
    check.inst_param(workspace, 'workspace', Workspace)
    check.inst_param(instance, 'instance', DagsterInstance)
    check.str_param(path_prefix, 'path_prefix')

    if path_prefix:
        if not path_prefix.startswith('/'):
            raise Exception('The path prefix should begin with a leading "/".')
        if path_prefix.endswith('/'):
            raise Exception(
                'The path prefix should not include a trailing "/".')

    warn_if_compute_logs_disabled()

    print('Loading repository...')  # pylint: disable=print-call

    locations = []
    for repository_location_handle in workspace.repository_location_handles:
        if isinstance(repository_location_handle,
                      InProcessRepositoryLocationHandle):
            # will need to change for multi repo
            check.invariant(
                len(repository_location_handle.repository_code_pointer_dict) ==
                1)
            pointer = next(
                iter(repository_location_handle.repository_code_pointer_dict.
                     values()))
            recon_repo = ReconstructableRepository(pointer)
            locations.append(InProcessRepositoryLocation(recon_repo))
        elif isinstance(repository_location_handle,
                        PythonEnvRepositoryLocationHandle):
            locations.append(
                PythonEnvRepositoryLocation(repository_location_handle))
        elif isinstance(repository_location_handle,
                        GrpcServerRepositoryLocationHandle):
            locations.append(
                GrpcServerRepositoryLocation(repository_location_handle))
        else:
            check.failed('{} unsupported'.format(repository_location_handle))

    context = DagsterGraphQLContext(instance=instance,
                                    locations=locations,
                                    version=__version__)

    return instantiate_app_with_views(context, path_prefix)
Esempio n. 12
0
File: app.py Progetto: sd2k/dagster
def create_app_from_workspace(workspace, instance, path_prefix=""):
    check.inst_param(workspace, "workspace", Workspace)
    check.inst_param(instance, "instance", DagsterInstance)
    check.str_param(path_prefix, "path_prefix")

    if path_prefix:
        if not path_prefix.startswith("/"):
            raise Exception('The path prefix should begin with a leading "/".')
        if path_prefix.endswith("/"):
            raise Exception('The path prefix should not include a trailing "/".')

    warn_if_compute_logs_disabled()

    print("Loading repository...")  # pylint: disable=print-call

    context = DagsterGraphQLContext(instance=instance, workspace=workspace, version=__version__)

    return instantiate_app_with_views(context, path_prefix)
Esempio n. 13
0
def create_app_from_workspace(workspace, instance, path_prefix=''):
    check.inst_param(workspace, 'workspace', Workspace)
    check.inst_param(instance, 'instance', DagsterInstance)
    check.str_param(path_prefix, 'path_prefix')

    if path_prefix:
        if not path_prefix.startswith('/'):
            raise Exception('The path prefix should begin with a leading "/".')
        if path_prefix.endswith('/'):
            raise Exception('The path prefix should not include a trailing "/".')

    warn_if_compute_logs_disabled()

    print('Loading repository...')  # pylint: disable=print-call

    locations = []
    for repository_location_handle in workspace.repository_location_handles:
        locations.append(RepositoryLocation.from_handle(repository_location_handle))

    context = DagsterGraphQLContext(instance=instance, locations=locations, version=__version__)

    return instantiate_app_with_views(context, path_prefix)
Esempio n. 14
0
File: app.py Progetto: nikie/dagster
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