SIENTIAPDE-1030
Add unit tests for orchestrator activities and workflows - Implement tests for Activities class, covering initialization and prepare_activity method. - Create tests for Couchbase class, including successful and failed query loading. - Add tests for SlotManager class, verifying OPC slot loading and active ingestor retrieval. - Develop tests for TemporalManager class, focusing on schedule loading functionality. - Introduce tests for Orchestrator class, ensuring proper execution of workflow activities. - Establish a new test suite for orchestrator activities and workflows in the tests directory.
This commit is contained in:
876
test.ipynb
Normal file
876
test.ipynb
Normal file
@@ -0,0 +1,876 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "a287fa45",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Initializing Couchbase connection...\n",
|
||||
"Awaiting Couchbase connection...\n",
|
||||
"Couchbase connection ready\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from orchestrator.activities.couchbase import Couchbase\n",
|
||||
"from unittest.mock import MagicMock\n",
|
||||
"logger = MagicMock(info=MagicMock(side_effect=print), debug=MagicMock(side_effect=print))\n",
|
||||
"couchbase = Couchbase(\n",
|
||||
" connection_string=\"couchbase://localhost\",\n",
|
||||
" username=\"sientia\",\n",
|
||||
" password=\"sientia\",\n",
|
||||
" logger=logger,\n",
|
||||
" notification_handler=MagicMock()\n",
|
||||
")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "d9a0f9c4",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Executing couchbase query: %s \n",
|
||||
"SELECT\n",
|
||||
" pipelines.*,\n",
|
||||
" models as model\n",
|
||||
"FROM\n",
|
||||
" `pipelines`\n",
|
||||
"JOIN\n",
|
||||
" `models` ON KEYS pipelines.model_id;\n",
|
||||
"\n",
|
||||
"Fetched %d rows from couchbase 1\n",
|
||||
"Rows: \n",
|
||||
" %s [\n",
|
||||
" {\n",
|
||||
" \"filters\": [\n",
|
||||
" {\n",
|
||||
" \"filter_name\": \"OUT_OF_BOUNDS_FILTER\",\n",
|
||||
" \"policy\": \"DISCARD\"\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"filter_name\": \"NULL_VALUES_FILTER\",\n",
|
||||
" \"policy\": \"DISCARD\"\n",
|
||||
" }\n",
|
||||
" ],\n",
|
||||
" \"frequency\": \"5s\",\n",
|
||||
" \"max_retry_policy\": 1,\n",
|
||||
" \"model\": {\n",
|
||||
" \"name\": \"Demo Model-Demo2\"\n",
|
||||
" },\n",
|
||||
" \"model_id\": \"1\",\n",
|
||||
" \"name\": \"scouter-opcua-pipeline\",\n",
|
||||
" \"read_tags\": [\n",
|
||||
" {\n",
|
||||
" \"aggr_func\": \"avg\",\n",
|
||||
" \"data_range\": [\n",
|
||||
" -100,\n",
|
||||
" 100\n",
|
||||
" ],\n",
|
||||
" \"tag_name\": \"Counter\"\n",
|
||||
" }\n",
|
||||
" ],\n",
|
||||
" \"tag_retention_minutes\": 60,\n",
|
||||
" \"workflow_type\": \"scouter\"\n",
|
||||
" }\n",
|
||||
"]\n",
|
||||
"[{'filters': [{'filter_name': 'OUT_OF_BOUNDS_FILTER', 'policy': 'DISCARD'}, {'filter_name': 'NULL_VALUES_FILTER', 'policy': 'DISCARD'}], 'frequency': '5s', 'max_retry_policy': 1, 'model': {'name': 'Demo Model-Demo2'}, 'model_id': '1', 'name': 'scouter-opcua-pipeline', 'read_tags': [{'aggr_func': 'avg', 'data_range': [-100, 100], 'tag_name': 'Counter'}], 'tag_retention_minutes': 60, 'workflow_type': 'scouter'}]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"query = \"\"\"\n",
|
||||
"SELECT\n",
|
||||
" pipelines.*,\n",
|
||||
" models as model\n",
|
||||
"FROM\n",
|
||||
" `pipelines`\n",
|
||||
"JOIN\n",
|
||||
" `models` ON KEYS pipelines.model_id;\n",
|
||||
"\"\"\"\n",
|
||||
"if __name__ == \"__main__\":\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" result = await couchbase.load_query_from_couchbase({\n",
|
||||
" \"query\": query\n",
|
||||
" })\n",
|
||||
"\n",
|
||||
" print(result)\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "7d01f160",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from temporalio import client\n",
|
||||
"from orchestrator.activities.temporal_manager import TemporalManager\n",
|
||||
"import os\n",
|
||||
"from unittest.mock import MagicMock\n",
|
||||
"\n",
|
||||
"host = \"localhost:7233\"\n",
|
||||
"logger = MagicMock(info=MagicMock(side_effect=print), debug=MagicMock(side_effect=print))\n",
|
||||
"\n",
|
||||
"temporal_client = await client.Client.connect(\n",
|
||||
" target_host=host,\n",
|
||||
" namespace=os.getenv('TEMPORAL_NAMESPACE', 'default')\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"manager = TemporalManager(temporal_client=temporal_client,\n",
|
||||
" logger=logger,\n",
|
||||
" notification_handler=MagicMock())\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 81,
|
||||
"id": "bb750ae6",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"<temporalio.client.ScheduleHandle at 0x76f314e5df90>"
|
||||
]
|
||||
},
|
||||
"execution_count": 81,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import asyncio\n",
|
||||
"from datetime import timedelta\n",
|
||||
"from temporalio.client import (\n",
|
||||
" Client,\n",
|
||||
" Schedule,\n",
|
||||
" ScheduleActionStartWorkflow,\n",
|
||||
" ScheduleIntervalSpec,\n",
|
||||
" ScheduleSpec,\n",
|
||||
")\n",
|
||||
"from temporalio.common import TypedSearchAttributes, SearchAttributeKey, SearchAttributePair\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"customer_id_key = SearchAttributeKey.for_keyword(\"Orchestrated\")\n",
|
||||
"search_attributes = TypedSearchAttributes([\n",
|
||||
" SearchAttributePair(customer_id_key, \"true\")\n",
|
||||
"])\n",
|
||||
"await temporal_client.create_schedule(\n",
|
||||
" \"meu-schedule-id5\",\n",
|
||||
" Schedule(\n",
|
||||
" action=ScheduleActionStartWorkflow(\n",
|
||||
" 'scouter-test2',\n",
|
||||
" {\n",
|
||||
" 'args': {\n",
|
||||
" 'arg1': 'value1'\n",
|
||||
" }\n",
|
||||
" },\n",
|
||||
" id=\"workflow-id-unico\",\n",
|
||||
" task_queue=\"nome-da-task-queue\",\n",
|
||||
" ),\n",
|
||||
" spec=ScheduleSpec(\n",
|
||||
" intervals=[ScheduleIntervalSpec(every=timedelta(minutes=10))]\n",
|
||||
" )\n",
|
||||
" ),\n",
|
||||
" search_attributes=search_attributes,\n",
|
||||
")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 86,
|
||||
"id": "1bd82225",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Getting orchestrated schedules...\n",
|
||||
"Schedule: %s ScheduleListDescription(id='meu-schedule-id5', schedule=ScheduleListSchedule(action=ScheduleListActionStartWorkflow(workflow='scouter-test2'), spec=ScheduleSpec(calendars=[], intervals=[ScheduleIntervalSpec(every=datetime.timedelta(seconds=600), offset=None)], cron_expressions=[], skip=[], start_at=None, end_at=None, jitter=None, time_zone_name=None), state=ScheduleListState(note=None, paused=False)), info=ScheduleListInfo(recent_actions=[], next_action_times=[datetime.datetime(2025, 5, 29, 20, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 10, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 20, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 30, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 40, tzinfo=datetime.timezone.utc)]), typed_search_attributes=TypedSearchAttributes(search_attributes=[SearchAttributePair(key=_SearchAttributeKey(_name='Orchestrated', _indexed_value_type=<SearchAttributeIndexedValueType.TEXT: 1>, _value_type=<class 'str'>), value='true')]), search_attributes={'Orchestrated': ['true']}, data_converter=DataConverter(payload_converter_class=<class 'temporalio.converter.DefaultPayloadConverter'>, payload_codec=None, failure_converter_class=<class 'temporalio.converter.DefaultFailureConverter'>, payload_converter=<temporalio.converter.DefaultPayloadConverter object at 0x76f32ca5cf50>, failure_converter=<temporalio.converter.DefaultFailureConverter object at 0x76f32ca5cf90>), raw_entry=schedule_id: \"meu-schedule-id5\"\n",
|
||||
"search_attributes {\n",
|
||||
" indexed_fields {\n",
|
||||
" key: \"Orchestrated\"\n",
|
||||
" value {\n",
|
||||
" metadata {\n",
|
||||
" key: \"type\"\n",
|
||||
" value: \"Text\"\n",
|
||||
" }\n",
|
||||
" metadata {\n",
|
||||
" key: \"encoding\"\n",
|
||||
" value: \"json/plain\"\n",
|
||||
" }\n",
|
||||
" data: \"\\\"true\\\"\"\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
"info {\n",
|
||||
" spec {\n",
|
||||
" interval {\n",
|
||||
" interval {\n",
|
||||
" seconds: 600\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" workflow_type {\n",
|
||||
" name: \"scouter-test2\"\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548800\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748549400\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748550000\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748550600\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748551200\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
")\n",
|
||||
"Search attributes: %s {'Orchestrated': ['true']}\n",
|
||||
"Schedule: %s ScheduleListDescription(id='meu-schedule-id4', schedule=ScheduleListSchedule(action=ScheduleListActionStartWorkflow(workflow='scouter-test2'), spec=ScheduleSpec(calendars=[], intervals=[ScheduleIntervalSpec(every=datetime.timedelta(seconds=600), offset=None)], cron_expressions=[], skip=[], start_at=None, end_at=None, jitter=None, time_zone_name=None), state=ScheduleListState(note=None, paused=False)), info=ScheduleListInfo(recent_actions=[], next_action_times=[datetime.datetime(2025, 5, 29, 20, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 10, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 20, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 30, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 40, tzinfo=datetime.timezone.utc)]), typed_search_attributes=TypedSearchAttributes(search_attributes=[SearchAttributePair(key=_SearchAttributeKey(_name='Orchestrated', _indexed_value_type=<SearchAttributeIndexedValueType.TEXT: 1>, _value_type=<class 'str'>), value='true')]), search_attributes={'Orchestrated': ['true']}, data_converter=DataConverter(payload_converter_class=<class 'temporalio.converter.DefaultPayloadConverter'>, payload_codec=None, failure_converter_class=<class 'temporalio.converter.DefaultFailureConverter'>, payload_converter=<temporalio.converter.DefaultPayloadConverter object at 0x76f32ca5cf50>, failure_converter=<temporalio.converter.DefaultFailureConverter object at 0x76f32ca5cf90>), raw_entry=schedule_id: \"meu-schedule-id4\"\n",
|
||||
"search_attributes {\n",
|
||||
" indexed_fields {\n",
|
||||
" key: \"Orchestrated\"\n",
|
||||
" value {\n",
|
||||
" metadata {\n",
|
||||
" key: \"type\"\n",
|
||||
" value: \"Text\"\n",
|
||||
" }\n",
|
||||
" metadata {\n",
|
||||
" key: \"encoding\"\n",
|
||||
" value: \"json/plain\"\n",
|
||||
" }\n",
|
||||
" data: \"\\\"true\\\"\"\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
"info {\n",
|
||||
" spec {\n",
|
||||
" interval {\n",
|
||||
" interval {\n",
|
||||
" seconds: 600\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" workflow_type {\n",
|
||||
" name: \"scouter-test2\"\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548800\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748549400\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748550000\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748550600\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748551200\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
")\n",
|
||||
"Search attributes: %s {'Orchestrated': ['true']}\n",
|
||||
"Schedule: %s ScheduleListDescription(id='meu-schedule-id3', schedule=ScheduleListSchedule(action=ScheduleListActionStartWorkflow(workflow='scouter-test2'), spec=ScheduleSpec(calendars=[], intervals=[ScheduleIntervalSpec(every=datetime.timedelta(seconds=600), offset=None)], cron_expressions=[], skip=[], start_at=None, end_at=None, jitter=None, time_zone_name=None), state=ScheduleListState(note=None, paused=False)), info=ScheduleListInfo(recent_actions=[], next_action_times=[datetime.datetime(2025, 5, 29, 20, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 10, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 20, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 30, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 40, tzinfo=datetime.timezone.utc)]), typed_search_attributes=TypedSearchAttributes(search_attributes=[SearchAttributePair(key=_SearchAttributeKey(_name='Orchestrated', _indexed_value_type=<SearchAttributeIndexedValueType.TEXT: 1>, _value_type=<class 'str'>), value='true')]), search_attributes={'Orchestrated': ['true']}, data_converter=DataConverter(payload_converter_class=<class 'temporalio.converter.DefaultPayloadConverter'>, payload_codec=None, failure_converter_class=<class 'temporalio.converter.DefaultFailureConverter'>, payload_converter=<temporalio.converter.DefaultPayloadConverter object at 0x76f32ca5cf50>, failure_converter=<temporalio.converter.DefaultFailureConverter object at 0x76f32ca5cf90>), raw_entry=schedule_id: \"meu-schedule-id3\"\n",
|
||||
"search_attributes {\n",
|
||||
" indexed_fields {\n",
|
||||
" key: \"Orchestrated\"\n",
|
||||
" value {\n",
|
||||
" metadata {\n",
|
||||
" key: \"type\"\n",
|
||||
" value: \"Text\"\n",
|
||||
" }\n",
|
||||
" metadata {\n",
|
||||
" key: \"encoding\"\n",
|
||||
" value: \"json/plain\"\n",
|
||||
" }\n",
|
||||
" data: \"\\\"true\\\"\"\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
"info {\n",
|
||||
" spec {\n",
|
||||
" interval {\n",
|
||||
" interval {\n",
|
||||
" seconds: 600\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" workflow_type {\n",
|
||||
" name: \"scouter-test2\"\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548800\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748549400\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748550000\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748550600\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748551200\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
")\n",
|
||||
"Search attributes: %s {'Orchestrated': ['true']}\n",
|
||||
"Schedule: %s ScheduleListDescription(id='meu-schedule-id2', schedule=ScheduleListSchedule(action=ScheduleListActionStartWorkflow(workflow='scouter-test2'), spec=ScheduleSpec(calendars=[], intervals=[ScheduleIntervalSpec(every=datetime.timedelta(seconds=600), offset=None)], cron_expressions=[], skip=[], start_at=None, end_at=None, jitter=None, time_zone_name=None), state=ScheduleListState(note=None, paused=False)), info=ScheduleListInfo(recent_actions=[ScheduleActionResult(scheduled_at=datetime.datetime(2025, 5, 29, 19, 50, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2025, 5, 29, 19, 50, 0, 37623, tzinfo=datetime.timezone.utc), action=ScheduleActionExecutionStartWorkflow(workflow_id='workflow-id-unico-2025-05-29T19:50:00Z', first_execution_run_id='01971d98-265a-7285-b46f-cf09bcf2d301'))], next_action_times=[datetime.datetime(2025, 5, 29, 20, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 10, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 20, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 30, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 40, tzinfo=datetime.timezone.utc)]), typed_search_attributes=TypedSearchAttributes(search_attributes=[SearchAttributePair(key=_SearchAttributeKey(_name='Orchestrated', _indexed_value_type=<SearchAttributeIndexedValueType.TEXT: 1>, _value_type=<class 'str'>), value='true')]), search_attributes={'Orchestrated': ['true']}, data_converter=DataConverter(payload_converter_class=<class 'temporalio.converter.DefaultPayloadConverter'>, payload_codec=None, failure_converter_class=<class 'temporalio.converter.DefaultFailureConverter'>, payload_converter=<temporalio.converter.DefaultPayloadConverter object at 0x76f32ca5cf50>, failure_converter=<temporalio.converter.DefaultFailureConverter object at 0x76f32ca5cf90>), raw_entry=schedule_id: \"meu-schedule-id2\"\n",
|
||||
"search_attributes {\n",
|
||||
" indexed_fields {\n",
|
||||
" key: \"Orchestrated\"\n",
|
||||
" value {\n",
|
||||
" metadata {\n",
|
||||
" key: \"type\"\n",
|
||||
" value: \"Text\"\n",
|
||||
" }\n",
|
||||
" metadata {\n",
|
||||
" key: \"encoding\"\n",
|
||||
" value: \"json/plain\"\n",
|
||||
" }\n",
|
||||
" data: \"\\\"true\\\"\"\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
"info {\n",
|
||||
" spec {\n",
|
||||
" interval {\n",
|
||||
" interval {\n",
|
||||
" seconds: 600\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" workflow_type {\n",
|
||||
" name: \"scouter-test2\"\n",
|
||||
" }\n",
|
||||
" recent_actions {\n",
|
||||
" schedule_time {\n",
|
||||
" seconds: 1748548200\n",
|
||||
" }\n",
|
||||
" actual_time {\n",
|
||||
" seconds: 1748548200\n",
|
||||
" nanos: 37623285\n",
|
||||
" }\n",
|
||||
" start_workflow_result {\n",
|
||||
" workflow_id: \"workflow-id-unico-2025-05-29T19:50:00Z\"\n",
|
||||
" run_id: \"01971d98-265a-7285-b46f-cf09bcf2d301\"\n",
|
||||
" }\n",
|
||||
" start_workflow_status: WORKFLOW_EXECUTION_STATUS_RUNNING\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548800\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748549400\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748550000\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748550600\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748551200\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
")\n",
|
||||
"Search attributes: %s {'Orchestrated': ['true']}\n",
|
||||
"Schedule: %s ScheduleListDescription(id='meu-schedule-id', schedule=ScheduleListSchedule(action=ScheduleListActionStartWorkflow(workflow='scouter-test'), spec=ScheduleSpec(calendars=[], intervals=[ScheduleIntervalSpec(every=datetime.timedelta(seconds=600), offset=None)], cron_expressions=[], skip=[], start_at=None, end_at=None, jitter=None, time_zone_name=None), state=ScheduleListState(note=None, paused=False)), info=ScheduleListInfo(recent_actions=[ScheduleActionResult(scheduled_at=datetime.datetime(2025, 5, 29, 19, 0, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2025, 5, 29, 19, 0, 0, 37788, tzinfo=datetime.timezone.utc), action=ScheduleActionExecutionStartWorkflow(workflow_id='workflow-id-unico-2025-05-29T19:00:00Z', first_execution_run_id='01971d6a-5fa1-70f8-8371-60ad11587b77'))], next_action_times=[datetime.datetime(2025, 5, 29, 20, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 10, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 20, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 30, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 40, tzinfo=datetime.timezone.utc)]), typed_search_attributes=TypedSearchAttributes(search_attributes=[SearchAttributePair(key=_SearchAttributeKey(_name='Orchestrated', _indexed_value_type=<SearchAttributeIndexedValueType.TEXT: 1>, _value_type=<class 'str'>), value='true')]), search_attributes={'Orchestrated': ['true']}, data_converter=DataConverter(payload_converter_class=<class 'temporalio.converter.DefaultPayloadConverter'>, payload_codec=None, failure_converter_class=<class 'temporalio.converter.DefaultFailureConverter'>, payload_converter=<temporalio.converter.DefaultPayloadConverter object at 0x76f32ca5cf50>, failure_converter=<temporalio.converter.DefaultFailureConverter object at 0x76f32ca5cf90>), raw_entry=schedule_id: \"meu-schedule-id\"\n",
|
||||
"search_attributes {\n",
|
||||
" indexed_fields {\n",
|
||||
" key: \"Orchestrated\"\n",
|
||||
" value {\n",
|
||||
" metadata {\n",
|
||||
" key: \"type\"\n",
|
||||
" value: \"Text\"\n",
|
||||
" }\n",
|
||||
" metadata {\n",
|
||||
" key: \"encoding\"\n",
|
||||
" value: \"json/plain\"\n",
|
||||
" }\n",
|
||||
" data: \"\\\"true\\\"\"\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
"info {\n",
|
||||
" spec {\n",
|
||||
" interval {\n",
|
||||
" interval {\n",
|
||||
" seconds: 600\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" workflow_type {\n",
|
||||
" name: \"scouter-test\"\n",
|
||||
" }\n",
|
||||
" recent_actions {\n",
|
||||
" schedule_time {\n",
|
||||
" seconds: 1748545200\n",
|
||||
" }\n",
|
||||
" actual_time {\n",
|
||||
" seconds: 1748545200\n",
|
||||
" nanos: 37788631\n",
|
||||
" }\n",
|
||||
" start_workflow_result {\n",
|
||||
" workflow_id: \"workflow-id-unico-2025-05-29T19:00:00Z\"\n",
|
||||
" run_id: \"01971d6a-5fa1-70f8-8371-60ad11587b77\"\n",
|
||||
" }\n",
|
||||
" start_workflow_status: WORKFLOW_EXECUTION_STATUS_RUNNING\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548800\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748549400\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748550000\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748550600\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748551200\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
")\n",
|
||||
"Search attributes: %s {'Orchestrated': ['true']}\n",
|
||||
"Schedule: %s ScheduleListDescription(id='laborious_test', schedule=ScheduleListSchedule(action=ScheduleListActionStartWorkflow(workflow='predictions_batch'), spec=ScheduleSpec(calendars=[], intervals=[ScheduleIntervalSpec(every=datetime.timedelta(seconds=60), offset=datetime.timedelta(0))], cron_expressions=[], skip=[], start_at=None, end_at=None, jitter=None, time_zone_name=None), state=ScheduleListState(note=None, paused=False)), info=ScheduleListInfo(recent_actions=[ScheduleActionResult(scheduled_at=datetime.datetime(2025, 5, 29, 19, 53, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2025, 5, 29, 19, 53, 0, 35750, tzinfo=datetime.timezone.utc), action=ScheduleActionExecutionStartWorkflow(workflow_id='laborious_test-2025-05-29T19:53:00Z', first_execution_run_id='01971d9a-e57f-700b-953b-bdb3b05810e2')), ScheduleActionResult(scheduled_at=datetime.datetime(2025, 5, 29, 19, 54, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2025, 5, 29, 19, 54, 0, 35780, tzinfo=datetime.timezone.utc), action=ScheduleActionExecutionStartWorkflow(workflow_id='laborious_test-2025-05-29T19:54:00Z', first_execution_run_id='01971d9b-cfde-7f39-8b38-b7e62fee1f82')), ScheduleActionResult(scheduled_at=datetime.datetime(2025, 5, 29, 19, 55, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2025, 5, 29, 19, 55, 0, 34329, tzinfo=datetime.timezone.utc), action=ScheduleActionExecutionStartWorkflow(workflow_id='laborious_test-2025-05-29T19:55:00Z', first_execution_run_id='01971d9c-ba3c-7d27-9db7-72759ebabc76')), ScheduleActionResult(scheduled_at=datetime.datetime(2025, 5, 29, 19, 56, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2025, 5, 29, 19, 56, 0, 49214, tzinfo=datetime.timezone.utc), action=ScheduleActionExecutionStartWorkflow(workflow_id='laborious_test-2025-05-29T19:56:00Z', first_execution_run_id='01971d9d-a4a9-7b55-a77b-fd450e768ccf')), ScheduleActionResult(scheduled_at=datetime.datetime(2025, 5, 29, 19, 57, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2025, 5, 29, 19, 57, 0, 36109, tzinfo=datetime.timezone.utc), action=ScheduleActionExecutionStartWorkflow(workflow_id='laborious_test-2025-05-29T19:57:00Z', first_execution_run_id='01971d9e-8eff-7608-9b10-0ed1875df9fe'))], next_action_times=[datetime.datetime(2025, 5, 29, 19, 58, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 19, 59, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 1, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 20, 2, tzinfo=datetime.timezone.utc)]), typed_search_attributes=TypedSearchAttributes(search_attributes=[]), search_attributes={}, data_converter=DataConverter(payload_converter_class=<class 'temporalio.converter.DefaultPayloadConverter'>, payload_codec=None, failure_converter_class=<class 'temporalio.converter.DefaultFailureConverter'>, payload_converter=<temporalio.converter.DefaultPayloadConverter object at 0x76f32ca5cf50>, failure_converter=<temporalio.converter.DefaultFailureConverter object at 0x76f32ca5cf90>), raw_entry=schedule_id: \"laborious_test\"\n",
|
||||
"info {\n",
|
||||
" spec {\n",
|
||||
" interval {\n",
|
||||
" interval {\n",
|
||||
" seconds: 60\n",
|
||||
" }\n",
|
||||
" phase {\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" workflow_type {\n",
|
||||
" name: \"predictions_batch\"\n",
|
||||
" }\n",
|
||||
" recent_actions {\n",
|
||||
" schedule_time {\n",
|
||||
" seconds: 1748548380\n",
|
||||
" }\n",
|
||||
" actual_time {\n",
|
||||
" seconds: 1748548380\n",
|
||||
" nanos: 35750962\n",
|
||||
" }\n",
|
||||
" start_workflow_result {\n",
|
||||
" workflow_id: \"laborious_test-2025-05-29T19:53:00Z\"\n",
|
||||
" run_id: \"01971d9a-e57f-700b-953b-bdb3b05810e2\"\n",
|
||||
" }\n",
|
||||
" start_workflow_status: WORKFLOW_EXECUTION_STATUS_COMPLETED\n",
|
||||
" }\n",
|
||||
" recent_actions {\n",
|
||||
" schedule_time {\n",
|
||||
" seconds: 1748548440\n",
|
||||
" }\n",
|
||||
" actual_time {\n",
|
||||
" seconds: 1748548440\n",
|
||||
" nanos: 35780414\n",
|
||||
" }\n",
|
||||
" start_workflow_result {\n",
|
||||
" workflow_id: \"laborious_test-2025-05-29T19:54:00Z\"\n",
|
||||
" run_id: \"01971d9b-cfde-7f39-8b38-b7e62fee1f82\"\n",
|
||||
" }\n",
|
||||
" start_workflow_status: WORKFLOW_EXECUTION_STATUS_COMPLETED\n",
|
||||
" }\n",
|
||||
" recent_actions {\n",
|
||||
" schedule_time {\n",
|
||||
" seconds: 1748548500\n",
|
||||
" }\n",
|
||||
" actual_time {\n",
|
||||
" seconds: 1748548500\n",
|
||||
" nanos: 34329717\n",
|
||||
" }\n",
|
||||
" start_workflow_result {\n",
|
||||
" workflow_id: \"laborious_test-2025-05-29T19:55:00Z\"\n",
|
||||
" run_id: \"01971d9c-ba3c-7d27-9db7-72759ebabc76\"\n",
|
||||
" }\n",
|
||||
" start_workflow_status: WORKFLOW_EXECUTION_STATUS_COMPLETED\n",
|
||||
" }\n",
|
||||
" recent_actions {\n",
|
||||
" schedule_time {\n",
|
||||
" seconds: 1748548560\n",
|
||||
" }\n",
|
||||
" actual_time {\n",
|
||||
" seconds: 1748548560\n",
|
||||
" nanos: 49214684\n",
|
||||
" }\n",
|
||||
" start_workflow_result {\n",
|
||||
" workflow_id: \"laborious_test-2025-05-29T19:56:00Z\"\n",
|
||||
" run_id: \"01971d9d-a4a9-7b55-a77b-fd450e768ccf\"\n",
|
||||
" }\n",
|
||||
" start_workflow_status: WORKFLOW_EXECUTION_STATUS_COMPLETED\n",
|
||||
" }\n",
|
||||
" recent_actions {\n",
|
||||
" schedule_time {\n",
|
||||
" seconds: 1748548620\n",
|
||||
" }\n",
|
||||
" actual_time {\n",
|
||||
" seconds: 1748548620\n",
|
||||
" nanos: 36109875\n",
|
||||
" }\n",
|
||||
" start_workflow_result {\n",
|
||||
" workflow_id: \"laborious_test-2025-05-29T19:57:00Z\"\n",
|
||||
" run_id: \"01971d9e-8eff-7608-9b10-0ed1875df9fe\"\n",
|
||||
" }\n",
|
||||
" start_workflow_status: WORKFLOW_EXECUTION_STATUS_RUNNING\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548680\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548740\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548800\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548860\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548920\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
")\n",
|
||||
"Search attributes: %s {}\n",
|
||||
"Schedule: %s ScheduleListDescription(id='scouter-opcua-pipeline', schedule=ScheduleListSchedule(action=ScheduleListActionStartWorkflow(workflow='scouter'), spec=ScheduleSpec(calendars=[], intervals=[ScheduleIntervalSpec(every=datetime.timedelta(seconds=30), offset=datetime.timedelta(0))], cron_expressions=[], skip=[], start_at=None, end_at=None, jitter=None, time_zone_name=None), state=ScheduleListState(note=None, paused=False)), info=ScheduleListInfo(recent_actions=[ScheduleActionResult(scheduled_at=datetime.datetime(2025, 5, 29, 19, 55, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2025, 5, 29, 19, 55, 0, 26130, tzinfo=datetime.timezone.utc), action=ScheduleActionExecutionStartWorkflow(workflow_id='scouter-opcua-pipeline-2025-05-29T19:55:00Z', first_execution_run_id='01971d9c-ba35-7b2a-b596-effe9939c7c7')), ScheduleActionResult(scheduled_at=datetime.datetime(2025, 5, 29, 19, 55, 30, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2025, 5, 29, 19, 55, 30, 26550, tzinfo=datetime.timezone.utc), action=ScheduleActionExecutionStartWorkflow(workflow_id='scouter-opcua-pipeline-2025-05-29T19:55:30Z', first_execution_run_id='01971d9d-2f66-7012-bd77-e5809b8c4c7a')), ScheduleActionResult(scheduled_at=datetime.datetime(2025, 5, 29, 19, 56, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2025, 5, 29, 19, 56, 0, 39848, tzinfo=datetime.timezone.utc), action=ScheduleActionExecutionStartWorkflow(workflow_id='scouter-opcua-pipeline-2025-05-29T19:56:00Z', first_execution_run_id='01971d9d-a4a1-7ba9-9205-21f157fe6e54')), ScheduleActionResult(scheduled_at=datetime.datetime(2025, 5, 29, 19, 56, 30, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2025, 5, 29, 19, 56, 30, 39791, tzinfo=datetime.timezone.utc), action=ScheduleActionExecutionStartWorkflow(workflow_id='scouter-opcua-pipeline-2025-05-29T19:56:30Z', first_execution_run_id='01971d9e-19d2-7358-96d3-261e203faaa7')), ScheduleActionResult(scheduled_at=datetime.datetime(2025, 5, 29, 19, 57, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2025, 5, 29, 19, 57, 0, 28221, tzinfo=datetime.timezone.utc), action=ScheduleActionExecutionStartWorkflow(workflow_id='scouter-opcua-pipeline-2025-05-29T19:57:00Z', first_execution_run_id='01971d9e-8ef8-72af-a903-1391b5e06c2f'))], next_action_times=[datetime.datetime(2025, 5, 29, 19, 57, 30, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 19, 58, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 19, 58, 30, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 19, 59, tzinfo=datetime.timezone.utc), datetime.datetime(2025, 5, 29, 19, 59, 30, tzinfo=datetime.timezone.utc)]), typed_search_attributes=TypedSearchAttributes(search_attributes=[]), search_attributes={}, data_converter=DataConverter(payload_converter_class=<class 'temporalio.converter.DefaultPayloadConverter'>, payload_codec=None, failure_converter_class=<class 'temporalio.converter.DefaultFailureConverter'>, payload_converter=<temporalio.converter.DefaultPayloadConverter object at 0x76f32ca5cf50>, failure_converter=<temporalio.converter.DefaultFailureConverter object at 0x76f32ca5cf90>), raw_entry=schedule_id: \"scouter-opcua-pipeline\"\n",
|
||||
"info {\n",
|
||||
" spec {\n",
|
||||
" interval {\n",
|
||||
" interval {\n",
|
||||
" seconds: 30\n",
|
||||
" }\n",
|
||||
" phase {\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" workflow_type {\n",
|
||||
" name: \"scouter\"\n",
|
||||
" }\n",
|
||||
" recent_actions {\n",
|
||||
" schedule_time {\n",
|
||||
" seconds: 1748548500\n",
|
||||
" }\n",
|
||||
" actual_time {\n",
|
||||
" seconds: 1748548500\n",
|
||||
" nanos: 26130839\n",
|
||||
" }\n",
|
||||
" start_workflow_result {\n",
|
||||
" workflow_id: \"scouter-opcua-pipeline-2025-05-29T19:55:00Z\"\n",
|
||||
" run_id: \"01971d9c-ba35-7b2a-b596-effe9939c7c7\"\n",
|
||||
" }\n",
|
||||
" start_workflow_status: WORKFLOW_EXECUTION_STATUS_COMPLETED\n",
|
||||
" }\n",
|
||||
" recent_actions {\n",
|
||||
" schedule_time {\n",
|
||||
" seconds: 1748548530\n",
|
||||
" }\n",
|
||||
" actual_time {\n",
|
||||
" seconds: 1748548530\n",
|
||||
" nanos: 26550164\n",
|
||||
" }\n",
|
||||
" start_workflow_result {\n",
|
||||
" workflow_id: \"scouter-opcua-pipeline-2025-05-29T19:55:30Z\"\n",
|
||||
" run_id: \"01971d9d-2f66-7012-bd77-e5809b8c4c7a\"\n",
|
||||
" }\n",
|
||||
" start_workflow_status: WORKFLOW_EXECUTION_STATUS_COMPLETED\n",
|
||||
" }\n",
|
||||
" recent_actions {\n",
|
||||
" schedule_time {\n",
|
||||
" seconds: 1748548560\n",
|
||||
" }\n",
|
||||
" actual_time {\n",
|
||||
" seconds: 1748548560\n",
|
||||
" nanos: 39848794\n",
|
||||
" }\n",
|
||||
" start_workflow_result {\n",
|
||||
" workflow_id: \"scouter-opcua-pipeline-2025-05-29T19:56:00Z\"\n",
|
||||
" run_id: \"01971d9d-a4a1-7ba9-9205-21f157fe6e54\"\n",
|
||||
" }\n",
|
||||
" start_workflow_status: WORKFLOW_EXECUTION_STATUS_COMPLETED\n",
|
||||
" }\n",
|
||||
" recent_actions {\n",
|
||||
" schedule_time {\n",
|
||||
" seconds: 1748548590\n",
|
||||
" }\n",
|
||||
" actual_time {\n",
|
||||
" seconds: 1748548590\n",
|
||||
" nanos: 39791709\n",
|
||||
" }\n",
|
||||
" start_workflow_result {\n",
|
||||
" workflow_id: \"scouter-opcua-pipeline-2025-05-29T19:56:30Z\"\n",
|
||||
" run_id: \"01971d9e-19d2-7358-96d3-261e203faaa7\"\n",
|
||||
" }\n",
|
||||
" start_workflow_status: WORKFLOW_EXECUTION_STATUS_COMPLETED\n",
|
||||
" }\n",
|
||||
" recent_actions {\n",
|
||||
" schedule_time {\n",
|
||||
" seconds: 1748548620\n",
|
||||
" }\n",
|
||||
" actual_time {\n",
|
||||
" seconds: 1748548620\n",
|
||||
" nanos: 28221068\n",
|
||||
" }\n",
|
||||
" start_workflow_result {\n",
|
||||
" workflow_id: \"scouter-opcua-pipeline-2025-05-29T19:57:00Z\"\n",
|
||||
" run_id: \"01971d9e-8ef8-72af-a903-1391b5e06c2f\"\n",
|
||||
" }\n",
|
||||
" start_workflow_status: WORKFLOW_EXECUTION_STATUS_RUNNING\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548650\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548680\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548710\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548740\n",
|
||||
" }\n",
|
||||
" future_action_times {\n",
|
||||
" seconds: 1748548770\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
")\n",
|
||||
"Search attributes: %s {}\n",
|
||||
"Found %d orchestrated schedules 5\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"schedules = await manager.load_schedule({})"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 87,
|
||||
"id": "a4c777dd",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from google.protobuf.json_format import MessageToDict\n",
|
||||
"import base64\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"schedules_config = {}\n",
|
||||
"for schedule in schedules:\n",
|
||||
" id = schedule.id\n",
|
||||
"\n",
|
||||
" handle = temporal_client.get_schedule_handle(id)\n",
|
||||
"\n",
|
||||
" desc = await handle.describe()\n",
|
||||
"\n",
|
||||
" for arg in desc.schedule.action.args:\n",
|
||||
" data = MessageToDict(arg)['data']\n",
|
||||
" data = base64.b64decode(data).decode('utf-8')\n",
|
||||
"\n",
|
||||
" frequency = desc.schedule.spec.intervals[0].every.seconds\n",
|
||||
"\n",
|
||||
" schedules_config[id] = {\n",
|
||||
" 'frequency': frequency,\n",
|
||||
" 'data': json.loads(data),\n",
|
||||
" 'handle': handle\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" \n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 88,
|
||||
"id": "988d1718",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'meu-schedule-id5': {'frequency': 600,\n",
|
||||
" 'data': {'args': {'arg1': 'value1'}},\n",
|
||||
" 'handle': <temporalio.client.ScheduleHandle at 0x76f30f5828d0>},\n",
|
||||
" 'meu-schedule-id4': {'frequency': 600,\n",
|
||||
" 'data': {},\n",
|
||||
" 'handle': <temporalio.client.ScheduleHandle at 0x76f30f5cf4d0>},\n",
|
||||
" 'meu-schedule-id3': {'frequency': 600,\n",
|
||||
" 'data': {},\n",
|
||||
" 'handle': <temporalio.client.ScheduleHandle at 0x76f3141f13d0>},\n",
|
||||
" 'meu-schedule-id2': {'frequency': 600,\n",
|
||||
" 'data': {},\n",
|
||||
" 'handle': <temporalio.client.ScheduleHandle at 0x76f30f64c710>},\n",
|
||||
" 'meu-schedule-id': {'frequency': 600,\n",
|
||||
" 'data': {},\n",
|
||||
" 'handle': <temporalio.client.ScheduleHandle at 0x76f31417c350>}}"
|
||||
]
|
||||
},
|
||||
"execution_count": 88,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"schedules_config"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 85,
|
||||
"id": "c12f5e75",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"meu-schedule-id5 {'frequency': 600, 'data': {'args': {'arg1': 'value1'}}, 'handle': <temporalio.client.ScheduleHandle object at 0x76f30f5ce590>}\n",
|
||||
"meu-schedule-id4 {'frequency': 1200, 'data': {'args': {'arg1': 'value1'}}, 'handle': <temporalio.client.ScheduleHandle object at 0x76f30f723910>}\n",
|
||||
"meu-schedule-id4\n",
|
||||
"meu-schedule-id3 {'frequency': 600, 'data': {}, 'handle': <temporalio.client.ScheduleHandle object at 0x76f30f64fe50>}\n",
|
||||
"meu-schedule-id2 {'frequency': 600, 'data': {}, 'handle': <temporalio.client.ScheduleHandle object at 0x76f31417b9d0>}\n",
|
||||
"meu-schedule-id {'frequency': 600, 'data': {}, 'handle': <temporalio.client.ScheduleHandle object at 0x76f30f64dad0>}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from temporalio.client import Client, ScheduleUpdateInput, ScheduleUpdate, ScheduleSpec\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"for id, schedule in schedules_config.items():\n",
|
||||
" print(id, schedule)\n",
|
||||
" \n",
|
||||
" if schedule['frequency'] != 600:\n",
|
||||
" print(id)\n",
|
||||
"\n",
|
||||
" handle = schedule['handle']\n",
|
||||
" \n",
|
||||
" async def update_schedule(input: ScheduleUpdateInput) -> ScheduleUpdate:\n",
|
||||
" schedule_action = input.description.schedule.action\n",
|
||||
" \n",
|
||||
" if hasattr(schedule_action, 'args'):\n",
|
||||
" schedule_action.args = [{}]\n",
|
||||
" \n",
|
||||
" # Atualiza o intervalo de execução\n",
|
||||
" input.description.schedule.spec.intervals = [\n",
|
||||
" ScheduleIntervalSpec(every=timedelta(minutes=10))\n",
|
||||
" ]\n",
|
||||
" \n",
|
||||
" return ScheduleUpdate(schedule=input.description.schedule)\n",
|
||||
"\n",
|
||||
" await handle.update(update_schedule)\n",
|
||||
" \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "87eb10c8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from redis import Redis\n",
|
||||
"\n",
|
||||
"redis = Redis(host='localhost', port=6379)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "fe4ad9dc",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Chave: slot:opc_tags:2, Valor: {\n",
|
||||
"\"slot2\": \"value\"\n",
|
||||
"}\n",
|
||||
"Chave: slot:opc_tags:1, Valor: {\n",
|
||||
"\"slot1\": \"value\"\n",
|
||||
"}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"matching_keys = redis.keys(\"slot:opc_tags:*\")\n",
|
||||
"\n",
|
||||
"if matching_keys:\n",
|
||||
" decoded_keys = [key.decode('utf-8') for key in matching_keys]\n",
|
||||
" values = redis.mget(decoded_keys)\n",
|
||||
"\n",
|
||||
" items = {}\n",
|
||||
" for i, key in enumerate(decoded_keys):\n",
|
||||
" value = values[i]\n",
|
||||
" if value is not None:\n",
|
||||
" try:\n",
|
||||
" items[key] = value.decode('utf-8')\n",
|
||||
" except (UnicodeDecodeError, AttributeError):\n",
|
||||
" items[key] = value\n",
|
||||
" else:\n",
|
||||
" items[key] = None\n",
|
||||
"\n",
|
||||
" for key, value in items.items():\n",
|
||||
" print(f\"Chave: {key}, Valor: {value}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "87a9dc89",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "venv",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user