Giter Site home page Giter Site logo

airflow_course's Introduction

Sample code for Harry's Airflow online trainng course

You can find the videos on youtube or bilibili.

I am working on adding below things:

  1. the slide pdf files(done)
  2. another video about creating custom operators
  3. docker-compose with CeleryExecutors.

airflow_course's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

airflow_course's Issues

[Question] `dbt deps`命令安排在哪个阶段

Harry 老师:

我在airflow中集成dbt的过程比较顺利,但在关于dbt deps命令的安排上有些困惑。
我的airflow部署在k8s中,采用deploydags分离的策略,无论是web, scheduler, 还是worder,都通过gitDAG仓库定时同步到容器中,dags目录挂载模式是emptyDir。与你的airflow_course类似,我的dagsdbt project在同一个仓库中,方便开发。

下面是我的自定义Operator代码片段:

@cached(cache=TTLCache(maxsize=1, ttl=60))
def get_finance_dbt_env_task()-> dict[str, str]:
    ...
class FinanceDbtOperator(BashOperator):
    def __init__(self, task_id: str, bash_command: str, **kwargs):
        _dbt_env = get_finance_dbt_env_task()
        kwargs['cwd'] = _dbt_env['DBT_PROJECT_DIR']
        kwargs['env'] = _dbt_env
        kwargs['append_env'] = True
        if 'queue' not in kwargs:
            kwargs['queue'] = 'kubernetes'
        super().__init__(task_id = task_id, bash_command = bash_command, **kwargs)

调用时仅需:

_dbt_task = FinanceDbtOperator(
    task_id='dbt_run',
    bash_command="dbt run --models 'dw.dim_stock'",
)

每运行一个task实例,都对应启动一个pod,拉取到干净的dbt项目文件后,都需要运行一次dbt deps以安装项目必要的包。
我实践或思考了一些方法:

方案 优点 缺点
FinanceDbtOperator调整为'dbt deps\n' + bash_command 省事儿 每次运行任务都自动重复一遍,产生大量spin up阶段的消耗
将包含dagsdbt项目的dags目录持久化 资源消耗低 仍然难以判断应何时运行dbt depspackages.yml是否发生更改)。反复运行dbt deps时,由于挂载了持久化卷,所以资源占用不大,但仍然需要花费数秒时间
dbt deps移动到airflow deploy阶段 资源消耗低 dags仓库中的依赖项变更需要运维人员的干预,且难以应对多个dbt项目
dbt项目构建独立的镜像 运行时资源消耗低,且能够应对多个dbt项目的依赖冲突 需要构建复杂的CI/CD管道,让airflow中的DAGdbt项目的镜像协同运作
dbt_packages.gitignore中移除,所有依赖包都纳入代码仓库 资源消耗低,容易协同 很脏的一种做法

想要了解,在你们的airflowdbt集成的实践中,是如何安排dbt deps的执行时机的呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.