Skip to content

Commit b551c4b

Browse files
committed
Fixed broken usage of instance
1 parent 687a866 commit b551c4b

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

dagster_sqlmesh/controller/base.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from dataclasses import dataclass
2+
from math import log
23
import typing as t
34
import logging
45
import threading
@@ -350,13 +351,19 @@ def setup_with_config(
350351
controller = cls(
351352
console=console,
352353
config=config,
354+
log_override=log_override,
353355
)
354356
return controller
355357

356-
def __init__(self, config: SQLMeshContextConfig, console: EventConsole):
358+
def __init__(
359+
self,
360+
config: SQLMeshContextConfig,
361+
console: EventConsole,
362+
log_override: t.Optional[logging.Logger] = None,
363+
):
357364
self.config = config
358365
self.console = console
359-
self.logger = logger
366+
self.logger = log_override or logger
360367
self._context_open = False
361368

362369
def set_logger(self, logger: logging.Logger):
@@ -379,7 +386,10 @@ def _create_context(self):
379386
return Context(**options)
380387

381388
@contextmanager
382-
def instance(self, environment: str):
389+
def instance(self, environment: str, component: str = "unknown"):
390+
self.logger.info(
391+
f"Opening sqlmesh instance for env={environment} component={component}"
392+
)
383393
if self._context_open:
384394
raise Exception("Only one sqlmesh instance at a time")
385395

@@ -390,6 +400,9 @@ def instance(self, environment: str):
390400
environment, self.console, self.config, context, self.logger
391401
)
392402
finally:
403+
self.logger.info(
404+
f"Closing sqlmesh instance for env={environment} component={component}"
405+
)
393406
self._context_open = False
394407
context.close()
395408

@@ -398,7 +411,7 @@ def run(
398411
environment: str,
399412
**run_options: t.Unpack[RunOptions],
400413
):
401-
with self.instance(environment) as mesh:
414+
with self.instance(environment, "run") as mesh:
402415
yield from mesh.run(**run_options)
403416

404417
def plan(
@@ -408,7 +421,7 @@ def plan(
408421
default_catalog: t.Optional[str],
409422
plan_options: PlanOptions,
410423
):
411-
with self.instance(environment) as mesh:
424+
with self.instance(environment, "plan") as mesh:
412425
yield from mesh.plan(categorizer, default_catalog, **plan_options)
413426

414427
def plan_and_run(
@@ -419,7 +432,7 @@ def plan_and_run(
419432
plan_options: t.Optional[PlanOptions] = None,
420433
run_options: t.Optional[RunOptions] = None,
421434
):
422-
with self.instance(environment) as mesh:
435+
with self.instance(environment, "plan_and_run") as mesh:
423436
yield from mesh.plan_and_run(
424437
categorizer=categorizer,
425438
default_catalog=default_catalog,

dagster_sqlmesh/controller/dagster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DagsterSQLMeshController(SQLMeshController):
2222
def to_asset_outs(
2323
self, environment: str, translator: SQLMeshDagsterTranslator
2424
) -> SQLMeshMultiAssetOptions:
25-
with self.instance(environment) as instance:
25+
with self.instance(environment, "to_asset_outs") as instance:
2626
context = instance.context
2727
dag = context.dag
2828
output = SQLMeshMultiAssetOptions()

dagster_sqlmesh/resource.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,7 @@ def run(
248248
context, models_map, dag, "sqlmesh: "
249249
)
250250

251-
for event in controller.plan_and_run(
252-
environment=environment,
251+
for event in mesh.plan_and_run(
253252
plan_options=plan_options,
254253
run_options=run_options,
255254
):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "dagster-sqlmesh"
3-
version = "0.3.1-dev1"
3+
version = "0.3.1"
44
description = ""
55
authors = ["Reuven Gonzales <reuven@karibalabs.co>"]
66
license = "Apache 2.0"

0 commit comments

Comments
 (0)