Esempio n. 1
0
File: ops.py Progetto: keyz/dagster
def fivetran_sync_op(context):
    """
    Executes a Fivetran sync for a given ``connector_id``, and polls until that sync
    completes, raising an error if it is unsuccessful. It outputs a FivetranOutput which contains
    the details of the Fivetran connector after the sync successfully completes, as well as details
    about which tables the sync updates.

    It requires the use of the :py:class:`~dagster_fivetran.fivetran_resource`, which allows it to
    communicate with the Fivetran API.

    Examples:

    .. code-block:: python

        from dagster import job
        from dagster_fivetran import fivetran_resource, fivetran_sync_op

        my_fivetran_resource = fivetran_resource.configured(
            {
                "api_key": {"env": "FIVETRAN_API_KEY"},
                "api_secret": {"env": "FIVETRAN_API_SECRET"},
            }
        )

        sync_foobar = fivetran_sync_op.configured({"connector_id": "foobar"}, name="sync_foobar")

        @job(resource_defs={"fivetran": my_fivetran_resource})
        def my_simple_fivetran_job():
            sync_foobar()

        @job(resource_defs={"fivetran": my_fivetran_resource})
        def my_composed_fivetran_job():
            final_foobar_state = sync_foobar(start_after=some_op())
            other_op(final_foobar_state)
    """

    fivetran_output = context.resources.fivetran.sync_and_poll(
        connector_id=context.op_config["connector_id"],
        poll_interval=context.op_config["poll_interval"],
        poll_timeout=context.op_config["poll_timeout"],
    )
    if context.op_config["yield_materializations"]:
        yield from generate_materializations(
            fivetran_output,
            asset_key_prefix=context.op_config["asset_key_prefix"])
    yield Output(fivetran_output)
Esempio n. 2
0
 def _assets(context):
     fivetran_output = context.resources.fivetran.sync_and_poll(
         connector_id=connector_id,
         poll_interval=poll_interval,
         poll_timeout=poll_timeout,
     )
     for materialization in generate_materializations(fivetran_output,
                                                      asset_key_prefix=[]):
         # scan through all tables actually created, if it was expected then emit an Output.
         # otherwise, emit a runtime AssetMaterialization
         if materialization.asset_key in asset_keys:
             yield Output(
                 value=None,
                 output_name="_".join(materialization.asset_key.path),
                 metadata_entries=materialization.metadata_entries,
             )
         else:
             yield materialization