Example #1
0
    def fetch_latest(cls, project, domain, name):
        """
        This function uses the engine loader to call create a latest hydrated task from Admin.
        :param Text project:
        :param Text domain:
        :param Text name:
        :rtype: SdkTask
        """
        named_task = _common_model.NamedEntityIdentifier(project, domain, name)
        client = _flyte_engine.get_client()
        task_list, _ = client.list_tasks_paginated(
            named_task,
            limit=1,
            sort_by=_admin_common.Sort(
                "created_at", _admin_common.Sort.Direction.DESCENDING),
        )
        admin_task = task_list[0] if task_list else None

        if not admin_task:
            raise _user_exceptions.FlyteEntityNotExistException(
                "Named task {} not found".format(named_task))
        sdk_task = cls.promote_from_model(
            admin_task.closure.compiled_task.template)
        sdk_task._id = admin_task.id
        return sdk_task
Example #2
0
def test_sort():
    o = _common.Sort(key="abc", direction=_common.Sort.Direction.ASCENDING)
    assert o.key == "abc"
    assert o.direction == _common.Sort.Direction.ASCENDING

    o2 = _common.Sort.from_flyte_idl(o.to_flyte_idl())
    assert o2 == o
    assert o2.key == "abc"
    assert o2.direction == _common.Sort.Direction.ASCENDING
Example #3
0
 def fetch_latest_task(self, named_task):
     """
     Fetches the latest task
     :param flytekit.models.common.NamedEntityIdentifier named_task: NamedEntityIdentifier to fetch
     :rtype: flytekit.models.task.Task
     """
     task_list, _ = _FlyteClientManager(
         _platform_config.URL.get(), insecure=_platform_config.INSECURE.get()
     ).client.list_tasks_paginated(
         named_task,
         limit=1,
         sort_by=_common.Sort("created_at", _common.Sort.Direction.DESCENDING),
     )
     return task_list[0] if task_list else None
Example #4
0
def test_fetch_latest_task(mock_client_factory, tasks):
    mock_client = MagicMock()
    mock_client.list_tasks_paginated = MagicMock(return_value=(tasks, 0))
    mock_client_factory.return_value = mock_client

    task = engine.FlyteEngineFactory().fetch_latest_task(_common_models.NamedEntityIdentifier("p", "d", "n"))

    if tasks:
        assert task.id == tasks[0].id
    else:
        assert not task

    mock_client.list_tasks_paginated.assert_called_once_with(
        _common_models.NamedEntityIdentifier("p", "d", "n"),
        limit=1,
        sort_by=_common.Sort("created_at", _common.Sort.Direction.DESCENDING),
    )