mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-12-02 10:36:29 +00:00
Fix: dbt cloud latest run execution (#20573)
* Fix: dbt cloud latest run execution * update latest run id * set default to 100
This commit is contained in:
parent
7ec8552742
commit
18bcf9eaaf
@ -75,17 +75,37 @@ class DBTCloudClient:
|
|||||||
fetch jobs for an account in dbt cloud
|
fetch jobs for an account in dbt cloud
|
||||||
"""
|
"""
|
||||||
job_list = []
|
job_list = []
|
||||||
|
# we will get 100 jobs at a time
|
||||||
|
query_params = {"offset": 0, "limit": 100}
|
||||||
try:
|
try:
|
||||||
job_path = f"{job_id}/" if job_id else ""
|
job_path = f"{job_id}/" if job_id else ""
|
||||||
project_path = f"?project_id={project_id}" if project_id else ""
|
project_path = f"?project_id={project_id}" if project_id else ""
|
||||||
result = self.client.get(
|
result = self.client.get(
|
||||||
f"/accounts/{self.config.accountId}/jobs/{job_path}{project_path}"
|
f"/accounts/{self.config.accountId}/jobs/{job_path}{project_path}",
|
||||||
|
data=query_params,
|
||||||
)
|
)
|
||||||
job_list = (
|
|
||||||
[DBTJob.model_validate(result["data"])]
|
if job_id:
|
||||||
if job_id
|
job_list = [DBTJob.model_validate(result["data"])]
|
||||||
else DBTJobList.model_validate(result).Jobs
|
else:
|
||||||
|
job_list_response = DBTJobList.model_validate(result)
|
||||||
|
job_list = job_list_response.Jobs
|
||||||
|
|
||||||
|
while job_list_response.extra and job_list_response.extra.pagination:
|
||||||
|
total_count = job_list_response.extra.pagination.total_count
|
||||||
|
current_count = job_list_response.extra.pagination.count
|
||||||
|
|
||||||
|
if current_count >= total_count:
|
||||||
|
break
|
||||||
|
|
||||||
|
query_params["offset"] += query_params["limit"]
|
||||||
|
result = self.client.get(
|
||||||
|
f"/accounts/{self.config.accountId}/jobs/{job_path}{project_path}",
|
||||||
|
data=query_params,
|
||||||
)
|
)
|
||||||
|
job_list_response = DBTJobList.model_validate(result)
|
||||||
|
job_list.extend(job_list_response.Jobs)
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.debug(traceback.format_exc())
|
logger.debug(traceback.format_exc())
|
||||||
logger.error(
|
logger.error(
|
||||||
@ -147,13 +167,42 @@ class DBTCloudClient:
|
|||||||
list runs for a job in dbt cloud
|
list runs for a job in dbt cloud
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
number_of_runs = self.config.numberOfRuns
|
||||||
|
runs = []
|
||||||
|
# we will get 100 runs at a time and order by created_at in descending order
|
||||||
|
query_params = {
|
||||||
|
"job_definition_id": job_id,
|
||||||
|
"offset": 0,
|
||||||
|
"limit": min(100, number_of_runs) if number_of_runs else 100,
|
||||||
|
"order_by": "-created_at",
|
||||||
|
}
|
||||||
|
|
||||||
|
result = self.client.get(
|
||||||
|
f"/accounts/{self.config.accountId}/runs/", data=query_params
|
||||||
|
)
|
||||||
|
run_list_response = DBTRunList.model_validate(result)
|
||||||
|
runs.extend(run_list_response.Runs)
|
||||||
|
|
||||||
|
while (
|
||||||
|
(number_of_runs is None or len(runs) < number_of_runs)
|
||||||
|
and run_list_response.extra
|
||||||
|
and run_list_response.extra.pagination
|
||||||
|
):
|
||||||
|
total_count = run_list_response.extra.pagination.total_count
|
||||||
|
current_count = run_list_response.extra.pagination.count
|
||||||
|
|
||||||
|
if current_count >= total_count:
|
||||||
|
break
|
||||||
|
|
||||||
|
query_params["offset"] += query_params["limit"]
|
||||||
result = self.client.get(
|
result = self.client.get(
|
||||||
f"/accounts/{self.config.accountId}/runs/",
|
f"/accounts/{self.config.accountId}/runs/",
|
||||||
data={"job_definition_id": job_id},
|
data=query_params,
|
||||||
)
|
)
|
||||||
if result:
|
run_list_response = DBTRunList.model_validate(result)
|
||||||
run_list = DBTRunList.model_validate(result).Runs
|
runs.extend(run_list_response.Runs)
|
||||||
return run_list
|
|
||||||
|
return runs[:number_of_runs] if number_of_runs is not None else runs
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.debug(traceback.format_exc())
|
logger.debug(traceback.format_exc())
|
||||||
logger.warning(f"Unable to get run info :{exc}")
|
logger.warning(f"Unable to get run info :{exc}")
|
||||||
|
|||||||
@ -105,7 +105,7 @@ class DbtcloudSource(PipelineServiceSource):
|
|||||||
)
|
)
|
||||||
task_list.append(task)
|
task_list.append(task)
|
||||||
self.context.get().latest_run_id = (
|
self.context.get().latest_run_id = (
|
||||||
task_list[-1].name if task_list else None
|
task_list[0].name if task_list else None
|
||||||
)
|
)
|
||||||
return task_list or None
|
return task_list or None
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|||||||
@ -34,8 +34,18 @@ class DBTJob(BaseModel):
|
|||||||
project_id: int
|
project_id: int
|
||||||
|
|
||||||
|
|
||||||
|
class Pagination(BaseModel):
|
||||||
|
count: int
|
||||||
|
total_count: int
|
||||||
|
|
||||||
|
|
||||||
|
class Extra(BaseModel):
|
||||||
|
pagination: Optional[Pagination] = None
|
||||||
|
|
||||||
|
|
||||||
class DBTJobList(BaseModel):
|
class DBTJobList(BaseModel):
|
||||||
Jobs: List[DBTJob] = Field(alias="data")
|
Jobs: List[DBTJob] = Field(alias="data")
|
||||||
|
extra: Optional[Extra] = None
|
||||||
|
|
||||||
|
|
||||||
class DBTRun(BaseModel):
|
class DBTRun(BaseModel):
|
||||||
@ -51,12 +61,14 @@ class DBTRun(BaseModel):
|
|||||||
|
|
||||||
class DBTRunList(BaseModel):
|
class DBTRunList(BaseModel):
|
||||||
Runs: Optional[List[DBTRun]] = Field([], alias="data")
|
Runs: Optional[List[DBTRun]] = Field([], alias="data")
|
||||||
|
extra: Optional[Extra] = None
|
||||||
|
|
||||||
|
|
||||||
class DBTSources(BaseModel):
|
class DBTSources(BaseModel):
|
||||||
name: Optional[str] = None
|
name: Optional[str] = None
|
||||||
dbtschema: Optional[str] = Field(None, alias="schema")
|
dbtschema: Optional[str] = Field(None, alias="schema")
|
||||||
database: Optional[str] = None
|
database: Optional[str] = None
|
||||||
|
extra: Optional[Extra] = None
|
||||||
|
|
||||||
|
|
||||||
class DBTModel(BaseModel):
|
class DBTModel(BaseModel):
|
||||||
@ -70,3 +82,4 @@ class DBTModel(BaseModel):
|
|||||||
class DBTModelList(BaseModel):
|
class DBTModelList(BaseModel):
|
||||||
models: Optional[List[DBTModel]] = []
|
models: Optional[List[DBTModel]] = []
|
||||||
seeds: Optional[List[DBTModel]] = []
|
seeds: Optional[List[DBTModel]] = []
|
||||||
|
extra: Optional[Extra] = None
|
||||||
|
|||||||
@ -388,6 +388,7 @@ mock_dbtcloud_config = {
|
|||||||
"accountId": "70403103922125",
|
"accountId": "70403103922125",
|
||||||
"jobIds": ["70403103922125", "70403103922126"],
|
"jobIds": ["70403103922125", "70403103922126"],
|
||||||
"projectIds": ["70403103922127", "70403103922128"],
|
"projectIds": ["70403103922127", "70403103922128"],
|
||||||
|
"numberOfRuns": 10,
|
||||||
"token": "dbt_token",
|
"token": "dbt_token",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -55,6 +55,12 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"numberOfRuns": {
|
||||||
|
"title": "Number of Runs",
|
||||||
|
"description": "Number of runs to fetch from DBT cloud",
|
||||||
|
"type": "integer",
|
||||||
|
"default": 100
|
||||||
|
},
|
||||||
"token": {
|
"token": {
|
||||||
"title": "Token",
|
"title": "Token",
|
||||||
"description": "Generated Token to connect to DBTCloud.",
|
"description": "Generated Token to connect to DBTCloud.",
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2024 Collate.
|
* Copyright 2025 Collate.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
@ -10,8 +10,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DBTCloud Connection Config
|
* DBTCloud Connection Config
|
||||||
*/
|
*/
|
||||||
@ -32,6 +30,10 @@ export interface DbtCloudConnection {
|
|||||||
* List of IDs of your DBT cloud jobs seperated by comma `,`
|
* List of IDs of your DBT cloud jobs seperated by comma `,`
|
||||||
*/
|
*/
|
||||||
jobIds?: string[];
|
jobIds?: string[];
|
||||||
|
/**
|
||||||
|
* Number of runs to fetch from DBT cloud
|
||||||
|
*/
|
||||||
|
numberOfRuns?: number;
|
||||||
/**
|
/**
|
||||||
* List of IDs of your DBT cloud projects seperated by comma `,`
|
* List of IDs of your DBT cloud projects seperated by comma `,`
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user