Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
add a process lock for compile (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenyuLInx authored Oct 24, 2023
1 parent 5f4744f commit f6fb8e7
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions dbt_server/services/dbt_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import threading
from multiprocessing import Lock

from datetime import datetime

Expand Down Expand Up @@ -49,8 +49,7 @@
"on",
)

CONFIG_GLOBAL_LOCK = threading.Lock()

COMPILE_SQL_LOCK = Lock()

class Args(BaseModel):
profile: str = None
Expand Down Expand Up @@ -124,11 +123,8 @@ def deserialize_manifest(serialize_path):
def compile_sql(manifest, project_dir, sql_config):
# Currently this command will load project and profile from disk
# It uses the manifest passed in
COMPILE_SQL_LOCK.acquire()
try:
# remove any inline_query nodes that might be generated in previous parse
for node_name in manifest.nodes.keys():
if "inline_query" in node_name:
manifest.nodes.pop(node_name)
profile_name = get_profile_name(sql_config)
# Invoke dbtRunner to compile SQL code
# TODO skip relational cache.
Expand Down Expand Up @@ -175,6 +171,8 @@ def compile_sql(manifest, project_dir, sql_config):
except CompilationException as e:
logger.error(f"Failed to compile sql. Compilation Error: {repr(e)}")
raise dbtCoreCompilationException(e)
finally:
COMPILE_SQL_LOCK.release()

if type(result) != RemoteCompileResult:
# Theoretically this shouldn't happen-- handling just in case
Expand Down

0 comments on commit f6fb8e7

Please sign in to comment.