Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ temp/
coverage.xml

setup.py
/extension
2 changes: 2 additions & 0 deletions connect/eaas/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class TaskPayload:
output: Optional[str] = None
correlation_id: Optional[str] = None
reply_to: Optional[str] = None
runtime: Optional[float] = 0.0


@dataclasses.dataclass
Expand All @@ -82,6 +83,7 @@ class CapabilitiesPayload:
schedulables: Optional[list] = None
readme_url: Optional[str] = None
changelog_url: Optional[str] = None
runner_version: Optional[str] = None


@dataclasses.dataclass
Expand Down
5 changes: 3 additions & 2 deletions connect/eaas/managers/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ async def build_response(self, task_data, future):
timeout=self.config.get_timeout('background'),
)
result_message.result = result.status
elapsed = time.monotonic() - begin_ts
result_message.runtime = time.monotonic() - begin_ts
logger.info(
f'background task {task_data.task_id} result: {result.status}, tooks: {elapsed}',
f'background task {task_data.task_id} result: {result.status}, tooks:'
f' {result_message.runtime}',
)
if result.status in (ResultType.SKIP, ResultType.FAIL):
result_message.output = result.output
Expand Down
5 changes: 3 additions & 2 deletions connect/eaas/managers/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ async def build_response(self, task_data, future):
result_message.result = result.status
result_message.data = result.data
result_message.output = result.output
elapsed = time.monotonic() - begin_ts
result_message.runtime = time.monotonic() - begin_ts
logger.info(
f'interactive task {task_data.task_id} result: {result.status}, tooks: {elapsed}',
f'interactive task {task_data.task_id} result: {result.status}, tooks:'
f' {result_message.runtime}',
)
except Exception as e:
self.log_exception(task_data, e)
Expand Down
7 changes: 7 additions & 0 deletions connect/eaas/managers/scheduled.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import asyncio
import dataclasses
import logging
import time
import traceback

from connect.eaas.dataclasses import (
Expand Down Expand Up @@ -39,12 +40,18 @@ async def build_response(self, task_data, future):
result = None
result_message = TaskPayload(**dataclasses.asdict(task_data))
try:
begin_ts = time.monotonic()
result = await asyncio.wait_for(
future,
timeout=self.config.get_timeout('scheduled'),
)
result_message.result = result.status
result_message.output = result.output
result_message.runtime = time.monotonic() - begin_ts
logger.info(
f'interactive task {task_data.task_id} result: {result.status}, tooks:'
f' {result_message.runtime}',
)
except Exception as e:
self.log_exception(task_data, e)
result_message.result = ResultType.RETRY
Expand Down
3 changes: 2 additions & 1 deletion connect/eaas/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
StopBackoffError,
)
from connect.eaas.handler import ExtensionHandler
from connect.eaas.helpers import to_ordinal
from connect.eaas.helpers import get_version, to_ordinal
from connect.eaas.managers import (
BackgroundTasksManager,
InteractiveTasksManager,
Expand Down Expand Up @@ -196,6 +196,7 @@ def get_capabilities(self):
self.handler.schedulables,
self.handler.readme,
self.handler.changelog,
get_version(),
),
),
)
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ def config_payload():

@pytest.fixture
def task_payload():
def _task_payload(task_category, task_type, object_id):
def _task_payload(task_category, task_type, object_id, runtime=0.0):
return {
'task_id': 'TQ-000',
'task_category': task_category,
'task_type': task_type,
'object_id': object_id,
'runtime': runtime,
}
return _task_payload
14 changes: 13 additions & 1 deletion tests/managers/test_background.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import time

import pytest

Expand Down Expand Up @@ -40,6 +41,9 @@ async def test_sync(mocker, extension_cls, task_type, config_payload):
)
mocker.patch('connect.eaas.handler.get_extension_class')
mocker.patch('connect.eaas.handler.get_extension_type')
mocked_time = mocker.patch('connect.eaas.managers.background.time')
mocked_time.sleep = time.sleep
mocked_time.monotonic.side_effect = (1.0, 2.0)
handler = ExtensionHandler(config)
handler.extension_class = extension_cls(TASK_TYPE_EXT_METHOD_MAP[task_type])
handler.extension_type = 'sync'
Expand All @@ -53,6 +57,7 @@ async def test_sync(mocker, extension_cls, task_type, config_payload):
TaskCategory.BACKGROUND,
task_type,
'PR-000',
runtime=1.0,
)

await manager.submit(task)
Expand All @@ -78,6 +83,9 @@ async def test_async(mocker, extension_cls, task_type, config_payload):
)
mocker.patch('connect.eaas.handler.get_extension_class')
mocker.patch('connect.eaas.handler.get_extension_type')
mocked_time = mocker.patch('connect.eaas.managers.background.time')
mocked_time.sleep = time.sleep
mocked_time.monotonic.side_effect = (1.0, 2.0)
handler = ExtensionHandler(config)
handler.extension_class = extension_cls(TASK_TYPE_EXT_METHOD_MAP[task_type], async_impl=True)
handler.extension_type = 'async'
Expand All @@ -91,6 +99,7 @@ async def test_async(mocker, extension_cls, task_type, config_payload):
TaskCategory.BACKGROUND,
task_type,
'PR-000',
runtime=1.0,
)

await manager.submit(task)
Expand Down Expand Up @@ -970,11 +979,14 @@ async def test_build_response_exception(mocker, task_payload):
async def test_send_skip_response(mocker, task_payload):
config = ConfigHelper()
mocked_put = mocker.AsyncMock()
mocked_time = mocker.patch('connect.eaas.managers.background.time')
mocked_time.sleep = time.sleep
mocked_time.monotonic.side_effect = (1.0, 2.0)
manager = BackgroundTasksManager(config, None, mocked_put)

task = TaskPayload(
**task_payload(
TaskCategory.BACKGROUND, TaskType.PART_USAGE_FILE_REQUEST_PROCESSING, 'UFC-000',
TaskCategory.BACKGROUND, TaskType.PART_USAGE_FILE_REQUEST_PROCESSING, 'UFC-000', 1.0,
),
)

Expand Down
17 changes: 17 additions & 0 deletions tests/managers/test_interactive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import time

import pytest

Expand Down Expand Up @@ -43,6 +44,9 @@ async def test_validation_sync(mocker, extension_cls, task_type, config_payload)
)
mocker.patch('connect.eaas.handler.get_extension_class')
mocker.patch('connect.eaas.handler.get_extension_type')
mocked_time = mocker.patch('connect.eaas.managers.interactive.time')
mocked_time.sleep = time.sleep
mocked_time.monotonic.side_effect = (1.0, 2.0)
handler = ExtensionHandler(config)

task_response_data = {'task': 'data', 'valid': True}
Expand All @@ -61,6 +65,7 @@ async def test_validation_sync(mocker, extension_cls, task_type, config_payload)
TaskCategory.INTERACTIVE,
task_type,
'ID-000',
runtime=1.0,
)

task.data = {'task': 'data'}
Expand Down Expand Up @@ -89,6 +94,9 @@ async def test_validation_async(mocker, extension_cls, task_type, config_payload
)
mocker.patch('connect.eaas.handler.get_extension_class')
mocker.patch('connect.eaas.handler.get_extension_type')
mocked_time = mocker.patch('connect.eaas.managers.interactive.time')
mocked_time.sleep = time.sleep
mocked_time.monotonic.side_effect = (1.0, 2.0)
handler = ExtensionHandler(config)

task_response_data = {'task': 'data', 'valid': True}
Expand All @@ -108,6 +116,7 @@ async def test_validation_async(mocker, extension_cls, task_type, config_payload
TaskCategory.INTERACTIVE,
task_type,
'ID-000',
runtime=1.0,
)

task.data = {'task': 'data'}
Expand Down Expand Up @@ -145,6 +154,9 @@ async def test_others_sync(mocker, extension_cls, task_type, result, config_payl
)
mocker.patch('connect.eaas.handler.get_extension_class')
mocker.patch('connect.eaas.handler.get_extension_type')
mocked_time = mocker.patch('connect.eaas.managers.interactive.time')
mocked_time.sleep = time.sleep
mocked_time.monotonic.side_effect = (1.0, 2.0)
handler = ExtensionHandler(config)

handler.extension_class = extension_cls(
Expand All @@ -161,6 +173,7 @@ async def test_others_sync(mocker, extension_cls, task_type, result, config_payl
TaskCategory.INTERACTIVE,
task_type,
'ID-000',
runtime=1.0,
)

task.data = {'task': 'data'}
Expand Down Expand Up @@ -202,6 +215,9 @@ async def test_others_async(mocker, extension_cls, task_type, result, config_pay
)
mocker.patch('connect.eaas.handler.get_extension_class')
mocker.patch('connect.eaas.handler.get_extension_type')
mocked_time = mocker.patch('connect.eaas.managers.interactive.time')
mocked_time.sleep = time.sleep
mocked_time.monotonic.side_effect = (1.0, 2.0)
handler = ExtensionHandler(config)

handler.extension_class = extension_cls(
Expand All @@ -219,6 +235,7 @@ async def test_others_async(mocker, extension_cls, task_type, result, config_pay
TaskCategory.INTERACTIVE,
task_type,
'ID-000',
runtime=1.0,
)

task.data = {'task': 'data'}
Expand Down
9 changes: 9 additions & 0 deletions tests/managers/test_scheduled.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import time

import pytest

Expand All @@ -24,6 +25,9 @@ async def test_sync(mocker, extension_cls, config_payload):
config.update_dynamic_config(ConfigurationPayload(**config_payload))
mocker.patch('connect.eaas.handler.get_extension_class')
mocker.patch('connect.eaas.handler.get_extension_type')
mocked_time = mocker.patch('connect.eaas.managers.scheduled.time')
mocked_time.sleep = time.sleep
mocked_time.monotonic.side_effect = (1.0, 2.0)
handler = ExtensionHandler(config)
handler.extension_class = extension_cls(
'my_sync_schedulable_method',
Expand All @@ -42,6 +46,7 @@ async def test_sync(mocker, extension_cls, config_payload):
TaskCategory.SCHEDULED,
TaskType.SCHEDULED_EXECUTION,
'EFS-000',
runtime=1.0,
)

await manager.submit(task)
Expand All @@ -58,6 +63,9 @@ async def test_async(mocker, extension_cls, config_payload):
config.update_dynamic_config(ConfigurationPayload(**config_payload))
mocker.patch('connect.eaas.handler.get_extension_class')
mocker.patch('connect.eaas.handler.get_extension_type')
mocked_time = mocker.patch('connect.eaas.managers.scheduled.time')
mocked_time.sleep = time.sleep
mocked_time.monotonic.side_effect = (1.0, 2.0)
handler = ExtensionHandler(config)
handler.extension_class = extension_cls(
'my_async_schedulable_method',
Expand All @@ -77,6 +85,7 @@ async def test_async(mocker, extension_cls, config_payload):
TaskCategory.SCHEDULED,
TaskType.SCHEDULED_EXECUTION,
'EFS-000',
runtime=1.0,
)

await manager.submit(task)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_parse_task_message():
'output': 'output',
'correlation_id': 'correlation_id',
'reply_to': 'reply_to',
'runtime': 2.2,
},
}

Expand All @@ -61,6 +62,7 @@ def test_parse_capabilities_message():
'schedulables': [],
'readme_url': 'https://read.me',
'changelog_url': 'https://change.log',
'runner_version': '1.1',
},
}

Expand Down Expand Up @@ -108,6 +110,7 @@ def test_parse_capabilities_message_with_vars():
'schedulables': None,
'readme_url': 'https://read.me',
'changelog_url': 'https://change.log',
'runner_version': None,
},
}

Expand Down Expand Up @@ -138,6 +141,7 @@ def test_parse_capabilities_message_with_schedulables():
],
'readme_url': 'https://read.me',
'changelog_url': 'https://change.log',
'runner_version': '1.2',
},
}

Expand Down
Loading