Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task execute_dbt created #585

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
592c028
Task execute_dbt created
andremartins31 Dec 1, 2023
59c4f22
Merge branch 'master' into staging/execute-dbt
mergify[bot] Dec 1, 2023
996bd05
Merge branch 'master' into staging/execute-dbt
mergify[bot] Dec 11, 2023
3386e3a
Merge branch 'master' into staging/execute-dbt
mergify[bot] Dec 12, 2023
a57c824
Merge branch 'master' into staging/execute-dbt
mergify[bot] Dec 12, 2023
cdf4c2b
Merge branch 'master' into staging/execute-dbt
mergify[bot] Dec 12, 2023
6e7c953
Merge branch 'master' into staging/execute-dbt
mergify[bot] Dec 13, 2023
1a00c57
Merge branch 'master' into staging/execute-dbt
mergify[bot] Dec 14, 2023
2ed7acf
Merge branch 'master' into staging/execute-dbt
mergify[bot] Dec 14, 2023
7a02e00
Merge branch 'master' into staging/execute-dbt
mergify[bot] Dec 18, 2023
b20e151
Merge branch 'master' into staging/execute-dbt
mergify[bot] Dec 18, 2023
6b62607
Merge branch 'master' into staging/execute-dbt
mergify[bot] Dec 18, 2023
8901029
Merge branch 'master' into staging/execute-dbt
mergify[bot] Dec 18, 2023
0ad225b
Merge branch 'master' into staging/execute-dbt
mergify[bot] Dec 21, 2023
08a0700
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 2, 2024
00dd7af
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 8, 2024
5c374a7
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 14, 2024
9f7ed78
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 15, 2024
145c80c
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 15, 2024
3ee4a3b
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 16, 2024
d72f136
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 16, 2024
b16c058
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 18, 2024
a74ea5e
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 19, 2024
d761081
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 22, 2024
c153ed1
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 23, 2024
ae490c1
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 24, 2024
179234b
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 25, 2024
90e7eea
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 25, 2024
9d48b70
Merge branch 'master' into staging/execute-dbt
mergify[bot] Jan 26, 2024
f9e2983
Merge branch 'master' into staging/execute-dbt
mergify[bot] Feb 5, 2024
28880a6
Merge branch 'master' into staging/execute-dbt
mergify[bot] Feb 6, 2024
3b5c1da
Merge branch 'master' into staging/execute-dbt
mergify[bot] Feb 6, 2024
833a0a2
Merge branch 'master' into staging/execute-dbt
mergify[bot] Feb 7, 2024
9a2fc02
Merge branch 'master' into staging/execute-dbt
mergify[bot] Feb 7, 2024
e994a7c
Merge branch 'master' into staging/execute-dbt
mergify[bot] Feb 7, 2024
fd8b511
Merge branch 'master' into staging/execute-dbt
mergify[bot] Feb 8, 2024
04e69d0
Merge branch 'master' into staging/execute-dbt
mergify[bot] Feb 8, 2024
19d45d0
Merge branch 'master' into staging/execute-dbt
mergify[bot] Feb 26, 2024
1578b9c
Merge branch 'master' into staging/execute-dbt
mergify[bot] Feb 26, 2024
86ac75b
Merge branch 'master' into staging/execute-dbt
mergify[bot] Feb 28, 2024
9ca5acd
Merge branch 'master' into staging/execute-dbt
mergify[bot] Feb 28, 2024
2374f9a
Merge branch 'master' into staging/execute-dbt
mergify[bot] Mar 1, 2024
43b9596
Merge branch 'master' into staging/execute-dbt
mergify[bot] Mar 1, 2024
10758a4
Merge branch 'master' into staging/execute-dbt
mergify[bot] Mar 4, 2024
f92eee4
Merge branch 'master' into staging/execute-dbt
mergify[bot] Mar 4, 2024
971d933
Merge branch 'master' into staging/execute-dbt
mergify[bot] Mar 15, 2024
afc7c0c
Merge branch 'master' into staging/execute-dbt
mergify[bot] Mar 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions pipelines/rj_sms/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import google.oauth2.id_token
import google.auth.transport.requests
from azure.storage.blob import BlobServiceClient
from dbt.cli.main import dbtRunner, dbtRunnerResult
import git
from prefect import task
from pipelines.utils.utils import (
log,
Expand Down Expand Up @@ -700,3 +702,35 @@ def upload_to_datalake(

except Exception as e:
log(f"An error occurred: {e}", level="error")

@task
def execute_dbt(
command: str,
model: str = ''
):
"""
Download repository and execute commands in DBT.

Args:
command (str): Command to be executed by DBT. Can be "run" or "build".
model (str): Name of model. Can be empty.
"""
# Repository download
repo_url = "https://github.com/prefeitura-rio/queries-rj-sms.git"
path = "pipelines/rj_sms/github/queries-rj-sms/"
try:
if os.path.exists(path):
shutil.rmtree(path, ignore_errors=True)
repo = git.Repo.clone_from(repo_url, path)
log(f"Cloned repository in {path}")
#Execute DBT
dbt = dbtRunner()
if not model:
cli_args = [command, "--profiles-dir", path, "--project-dir", path]
else:
cli_args = [command, "--profiles-dir", path, "--project-dir", path, "--models", model]
res: dbtRunnerResult = dbt.invoke(cli_args)
for r in res.result:
log(f"{r.node.name}: {r.status}")
except git.GitCommandError as e:
log(f"Error when cloning repository: {e}")
Loading