aris purnomo
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # DOCUMENTATION AIRFLOW <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ8FTpOXKsKFbmwZS28VI4JbAvi2cWgUlWQjJMw0yd1p9ikpMVJsHKsa_1v-5imPz0cHKE&usqp=CAU" height=70px/> ###### tags: `Documentation` `Airflow` [TOC] ## Apa Itu Airflow? :::info **Apache Airflow** is an open-source workflow management platform for data engineering pipelines. It started at Airbnb in October 2014 as a solution to manage the company's increasingly complex workflows ::: ### Dependencies **Operating system** Airflow is being developed and tested on Linux, with Debian and RedHat being the main platforms. **Python** Airflow is written in Python 3 and requires Python 3.5 or higher. **redis** The redis database is required by Airflow as a communication broker between tasks. It is also used as the default broker for the Celery queuing system, but could be replaced with any other supported Celery broker. **PostgreSQL** Airflow makes use of PostgreSQL for storing persistent data during a workflow run that can be accessed by all tasks. ### Cakupan Airflow :::info ::: #### Workflow **Sequential** <img src="https://australiansynchrotron.github.io/lightflow/img/example_sequential.svg" width="70%" style="margin-bottom: 20px;" /> >The sequential workflow pattern is one of the most basic patterns. A number of tasks are executed in order, starting with the first task. >In this example, a counter is stored in value and initialized in task_1. Each task increments the counter, prints its value and passes it on to the next task. **Parallel** <img src="https://australiansynchrotron.github.io/lightflow/img/example_parallel.svg" width="70%" style="margin-bottom: 20px;" /> >Airflow runs tasks that can be executed in parallel at the same time. >This example starts with the branch_task that fans out into three simple tasks. Once all three tasks have completed running, the join_task is executed. **Data Flow** <img src="https://australiansynchrotron.github.io/lightflow/img/example_dataflow.svg" width="70%" style="margin-bottom: 20px;" /> >Almost arbitrary data can flow between tasks. If multiple tasks send data to the same task downstream, the data can be labeled with an alias in order for the downstream task to be able to pick the right dataset. >In this example, the put_task stores 5 into value and passes it on to the print_task_1, square_task, multiply_task and subtract_task. The square_task squares the value, prints it and passes it on to the multiply_task. The input to the multiply_task are two datasets. Since multiplication is a commutative operation, the multiply_task will simply multiply both datasets regardless of their order. The result of the multiplication is passed on to the subtract_task. Since the order of the input for the subtract_task matters, the data passed from the put_task is given the alias first, while the data from the multiply_task is labelled second. **Sub DAG** <img src="https://australiansynchrotron.github.io/lightflow/img/example_subdag.svg" width="70%" style="margin-bottom: 20px;" /> >Lightflow allows for more than one DAG to be defined in a workflow and for tasks to queue new DAGs. This allows for dynamically changing workflows. >In this example two DAGs are defined. The main_dag that is executed at the start of the workflow and the sub_dag that is started dynamically. The call_dag_task of the main_dag starts 5 sub_dag instances by sending a request to the signal system. For illustration purposes a numpy array is being sent with the request. **Data Store** <img src="https://australiansynchrotron.github.io/lightflow/img/example_store.svg" width="70%" style="margin-bottom: 20px;" /> >Data that should be kept during a workflow run can be saved into the persistent data store. This data is deleted as soon as the workflow run ends, but is available to all tasks during the lifetime of the workflow. >The data store provides methods to store and retrieve single values or append values to a list. This can even be done asynchronously from different tasks at the same time. The key under which the data is being stored supports a hierarchical structure using a dot notation. >This example workflow stores different types of data in the persistent data store and modifies them. Trigger Scheduler ### Konektifitas :::info ::: Python Bash SSH FTP/SFTP PostgreSQL SQL Server ## Cara Kerja Airflow :::info ::: ```sequence Title: Inquiry Bulk Data Cekrekening.id \n participant CEKREKENING.ID participant PROXY participant OCP participant AIRFLOW participant FDS participant EXTDWH FDS->AIRFLOW: Register \nJob Scheduler AIRFLOW->CEKREKENING.ID: Inquiry Data Rekening AIRFLOW-->OCP: Call API OCP-->PROXY: Tunnel PROXY-->CEKREKENING.ID: Passing Request CEKREKENING.ID->AIRFLOW: Response result CEKREKENING.ID-->PROXY: Passing Response PROXY-->OCP: Receive OCP-->AIRFLOW: By Pass AIRFLOW->FDS: OK AIRFLOW-->EXTDWH: Store Result AIRFLOW->FDS: NOK AIRFLOW-->KILL: Skip ``` ## Use Case :::info ::: ### Create DAG ```sequence Title: Inquiry Bulk Data Cekrekening.id \n participant CEKREKENING.ID participant PROXY participant OCP participant AIRFLOW participant FDS participant EXTDWH FDS->AIRFLOW: Register \nJob Scheduler AIRFLOW->CEKREKENING.ID: Inquiry Data Rekening AIRFLOW-->OCP: Call API OCP-->PROXY: Tunnel PROXY-->CEKREKENING.ID: Passing Request CEKREKENING.ID->AIRFLOW: Response result CEKREKENING.ID-->PROXY: Passing Response PROXY-->OCP: Receive OCP-->AIRFLOW: By Pass AIRFLOW->FDS: OK AIRFLOW-->EXTDWH: Store Result AIRFLOW->FDS: NOK AIRFLOW-->KILL: Skip ``` Running DAG Monitoring DAG ```sequence Title: Penarikan Data Tracking participant ONMOBILE participant FIREBASE participant GOOGLE ANALYTICS participant BIG QUERY participant AIRFLOW participant EXTDWH participant BIG DATA ONMOBILE->FIREBASE: FIREBASE-->GOOGLE ANALYTICS: GOOGLE ANALYTICS->AIRFLOW: Using API GOOGLE ANALYTICS-->BIG QUERY: Scheduler \nBy Google BIG QUERY->AIRFLOW: Direct Connect AIRFLOW->EXTDWH: Store PostgreSQL AIRFLOW->BIG DATA: Store Big Data ``` ``` import os from airflow import DAG from bigdata.core.replication.BaseDags import create_custom_dags from datetime import datetime, timezone, timedelta FILE_PATH = os.path.dirname(os.path.realpath(__file__)) WORKFLOW_NAME = FILE_PATH.split('/')[-1] TAGS = FILE_PATH.split('/')[-3:-1] print("workflow_name: ", WORKFLOW_NAME) kwargs_db = {     "workflow_name": WORKFLOW_NAME,     "connection_id": "mssql_sql_cls",     "chunksize": 1000,     "file_path": FILE_PATH } tags = ["bigdata"] tags.extend(TAGS) today = datetime.today() tz = timezone(timedelta(hours=7)) today = today.astimezone(tz) ds = today.strftime('%Y-%m-%d') config = {     "workflow_name": WORKFLOW_NAME,     "owner": "aris.purnomo",     "t0_name": "x_t0_sqlserver",     "t1_name": "x_t1_dev",     "table_name": "ClsFacilityWOCORecap_TR",     "start_date": "2022-10-19",     "salt_key": "development",     "schedule_interval": "@once",     "tags":tags,     "file_path": FILE_PATH,     "ds": ds,     "kwargs_db": kwargs_db } dags = create_custom_dags(config) globals()[WORKFLOW_NAME] = dags ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully