fabricatio 0.1.2__py3-none-any.whl → 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fabricatio/actions/__init__.py +5 -0
- fabricatio/actions/transmission.py +16 -0
- fabricatio/models/events.py +3 -1
- fabricatio/models/task.py +40 -20
- {fabricatio-0.1.2.dist-info → fabricatio-0.1.3.dist-info}/METADATA +1 -1
- {fabricatio-0.1.2.dist-info → fabricatio-0.1.3.dist-info}/RECORD +8 -6
- {fabricatio-0.1.2.dist-info → fabricatio-0.1.3.dist-info}/WHEEL +0 -0
- {fabricatio-0.1.2.dist-info → fabricatio-0.1.3.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
from typing import List
|
2
|
+
|
3
|
+
from fabricatio.journal import logger
|
4
|
+
from fabricatio.models.action import Action
|
5
|
+
from fabricatio.models.task import Task
|
6
|
+
|
7
|
+
|
8
|
+
class SendTask(Action):
|
9
|
+
"""Action that sends a task to a user."""
|
10
|
+
|
11
|
+
name: str = "send_task"
|
12
|
+
|
13
|
+
async def _execute(self, send_targets: List[str], send_task: Task, **_) -> None:
|
14
|
+
logger.info(f"Sending task {send_task.name} to {send_targets}")
|
15
|
+
for target in send_targets:
|
16
|
+
await send_task.publish(target)
|
fabricatio/models/events.py
CHANGED
@@ -50,8 +50,10 @@ class Event(BaseModel):
|
|
50
50
|
self.segments.clear()
|
51
51
|
return self
|
52
52
|
|
53
|
-
def concat(self, event: Self) -> Self:
|
53
|
+
def concat(self, event: Self | str) -> Self:
|
54
54
|
"""Concatenate another event to this event."""
|
55
|
+
if isinstance(event, str):
|
56
|
+
event = Event.from_string(event)
|
55
57
|
self.segments.extend(event.segments)
|
56
58
|
return self
|
57
59
|
|
fabricatio/models/task.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""This module defines the Task class, which represents a task with a status and output.
|
1
|
+
"""This module defines the `Task` class, which represents a task with a status and output.
|
2
2
|
|
3
3
|
It includes methods to manage the task's lifecycle, such as starting, finishing, cancelling, and failing the task.
|
4
4
|
"""
|
@@ -12,11 +12,20 @@ from pydantic import Field, PrivateAttr
|
|
12
12
|
from fabricatio.config import configs
|
13
13
|
from fabricatio.core import env
|
14
14
|
from fabricatio.journal import logger
|
15
|
+
from fabricatio.models.events import Event
|
15
16
|
from fabricatio.models.generic import WithBriefing, WithJsonExample
|
16
17
|
|
17
18
|
|
18
19
|
class TaskStatus(Enum):
|
19
|
-
"""
|
20
|
+
"""An enumeration representing the status of a task.
|
21
|
+
|
22
|
+
Attributes:
|
23
|
+
Pending: The task is pending.
|
24
|
+
Running: The task is currently running.
|
25
|
+
Finished: The task has been successfully completed.
|
26
|
+
Failed: The task has failed.
|
27
|
+
Cancelled: The task has been cancelled.
|
28
|
+
"""
|
20
29
|
|
21
30
|
Pending = "pending"
|
22
31
|
Running = "running"
|
@@ -26,13 +35,11 @@ class TaskStatus(Enum):
|
|
26
35
|
|
27
36
|
|
28
37
|
class Task[T](WithBriefing, WithJsonExample):
|
29
|
-
"""
|
38
|
+
"""A class representing a task with a status and output.
|
30
39
|
|
31
40
|
Attributes:
|
32
41
|
name (str): The name of the task.
|
33
42
|
description (str): The description of the task.
|
34
|
-
_output (Queue): The output queue of the task.
|
35
|
-
_status (TaskStatus): The status of the task.
|
36
43
|
goal (str): The goal of the task.
|
37
44
|
"""
|
38
45
|
|
@@ -47,6 +54,7 @@ class Task[T](WithBriefing, WithJsonExample):
|
|
47
54
|
|
48
55
|
_output: Queue = PrivateAttr(default_factory=lambda: Queue(maxsize=1))
|
49
56
|
"""The output queue of the task."""
|
57
|
+
|
50
58
|
_status: TaskStatus = PrivateAttr(default=TaskStatus.Pending)
|
51
59
|
"""The status of the task."""
|
52
60
|
|
@@ -60,7 +68,7 @@ class Task[T](WithBriefing, WithJsonExample):
|
|
60
68
|
description (str): The description of the task.
|
61
69
|
|
62
70
|
Returns:
|
63
|
-
|
71
|
+
Task: A new instance of the `Task` class.
|
64
72
|
"""
|
65
73
|
return cls(name=name, goal=goal, description=description)
|
66
74
|
|
@@ -68,11 +76,11 @@ class Task[T](WithBriefing, WithJsonExample):
|
|
68
76
|
"""Update the goal and description of the task.
|
69
77
|
|
70
78
|
Args:
|
71
|
-
goal (
|
72
|
-
description (
|
79
|
+
goal (str, optional): The new goal of the task.
|
80
|
+
description (str, optional): The new description of the task.
|
73
81
|
|
74
82
|
Returns:
|
75
|
-
|
83
|
+
Task: The updated instance of the `Task` class.
|
76
84
|
"""
|
77
85
|
if goal:
|
78
86
|
self.goal = goal
|
@@ -152,7 +160,7 @@ class Task[T](WithBriefing, WithJsonExample):
|
|
152
160
|
output (T): The output of the task.
|
153
161
|
|
154
162
|
Returns:
|
155
|
-
|
163
|
+
Task: The finished instance of the `Task` class.
|
156
164
|
"""
|
157
165
|
logger.info(f"Finishing task {self.name}")
|
158
166
|
self._status = TaskStatus.Finished
|
@@ -166,7 +174,7 @@ class Task[T](WithBriefing, WithJsonExample):
|
|
166
174
|
"""Mark the task as running.
|
167
175
|
|
168
176
|
Returns:
|
169
|
-
|
177
|
+
Task: The running instance of the `Task` class.
|
170
178
|
"""
|
171
179
|
logger.info(f"Starting task {self.name}")
|
172
180
|
self._status = TaskStatus.Running
|
@@ -177,7 +185,7 @@ class Task[T](WithBriefing, WithJsonExample):
|
|
177
185
|
"""Mark the task as cancelled.
|
178
186
|
|
179
187
|
Returns:
|
180
|
-
|
188
|
+
Task: The cancelled instance of the `Task` class.
|
181
189
|
"""
|
182
190
|
self._status = TaskStatus.Cancelled
|
183
191
|
await env.emit_async(self.cancelled_label, self)
|
@@ -187,31 +195,43 @@ class Task[T](WithBriefing, WithJsonExample):
|
|
187
195
|
"""Mark the task as failed.
|
188
196
|
|
189
197
|
Returns:
|
190
|
-
|
198
|
+
Task: The failed instance of the `Task` class.
|
191
199
|
"""
|
192
200
|
logger.error(f"Task {self.name} failed")
|
193
201
|
self._status = TaskStatus.Failed
|
194
202
|
await env.emit_async(self.failed_label, self)
|
195
203
|
return self
|
196
204
|
|
197
|
-
async def publish(self) -> Self:
|
198
|
-
"""Publish the task
|
205
|
+
async def publish(self, event_namespace: Event | str = "") -> Self:
|
206
|
+
"""Publish the task with an optional event namespace.
|
207
|
+
|
208
|
+
Args:
|
209
|
+
event_namespace (Event | str, optional): The event namespace to use. Defaults to an empty string.
|
199
210
|
|
200
211
|
Returns:
|
201
|
-
|
212
|
+
Task: The published instance of the `Task` class.
|
202
213
|
"""
|
214
|
+
if isinstance(event_namespace, str):
|
215
|
+
event_namespace = Event.from_string(event_namespace)
|
216
|
+
|
203
217
|
logger.info(f"Publishing task {self.name}")
|
204
|
-
await env.emit_async(self.pending_label, self)
|
218
|
+
await env.emit_async(event_namespace.concat(self.pending_label).collapse(), self)
|
205
219
|
return self
|
206
220
|
|
207
|
-
async def delegate(self) -> T:
|
208
|
-
"""Delegate the task
|
221
|
+
async def delegate(self, event_namespace: Event | str = "") -> T:
|
222
|
+
"""Delegate the task with an optional event namespace and return the output.
|
223
|
+
|
224
|
+
Args:
|
225
|
+
event_namespace (Event | str, optional): The event namespace to use. Defaults to an empty string.
|
209
226
|
|
210
227
|
Returns:
|
211
228
|
T: The output of the task.
|
212
229
|
"""
|
230
|
+
if isinstance(event_namespace, str):
|
231
|
+
event_namespace = Event.from_string(event_namespace)
|
232
|
+
|
213
233
|
logger.info(f"Delegating task {self.name}")
|
214
|
-
await env.emit_async(self.pending_label, self)
|
234
|
+
await env.emit_async(event_namespace.concat(self.pending_label).collapse(), self)
|
215
235
|
return await self.get_output()
|
216
236
|
|
217
237
|
@property
|
@@ -4,16 +4,18 @@ fabricatio/core.py,sha256=B6KBIfBRF023HF0UUaUprEkQd6sT7G_pexGXQ9btJnE,5788
|
|
4
4
|
fabricatio/journal.py,sha256=CW9HePtgTiboOyPTExq9GjG5BseZcbc-S6lxDXrpmv0,667
|
5
5
|
fabricatio/parser.py,sha256=On_YUCvOuA0FA_NtDVNJqKp7KEO_sUE89oO_WnkEhQ4,2314
|
6
6
|
fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
+
fabricatio/actions/__init__.py,sha256=n3lwq9FPNtvfLu2L1pX4UkwiPITU7luk-b4aMJyjIC8,109
|
8
|
+
fabricatio/actions/transmission.py,sha256=Azog4ItVk7aASdYzTwzyckzYG2hDFSXctnA7qp-Qlq0,502
|
7
9
|
fabricatio/models/action.py,sha256=M-12dc-nQiNJU6Y9j-dr4Ef3642vRvzHlzxekBepzaU,3358
|
8
|
-
fabricatio/models/events.py,sha256=
|
10
|
+
fabricatio/models/events.py,sha256=PlavKOD94Q9Q9iPoQPkf9HJdznBtzuSUrPtUoVtkQxU,2143
|
9
11
|
fabricatio/models/generic.py,sha256=Sxpx0BO0t85YF5Lwks6F165N6TJsDe7xym28dQG5Mqs,17681
|
10
12
|
fabricatio/models/role.py,sha256=jdabuYRXwgvpYoNwvazygDiZHGGQApUIIKltniu78O8,2151
|
11
|
-
fabricatio/models/task.py,sha256=
|
13
|
+
fabricatio/models/task.py,sha256=8IXT192t5EXVHAdHj45DJNdBhdA2xmh36S_vKyEw6y0,7757
|
12
14
|
fabricatio/models/tool.py,sha256=UkEp1Nzbl5wZX21q_Z2VkpiJmVDSdoGDzINQniO8hSY,3536
|
13
15
|
fabricatio/models/utils.py,sha256=2mgXla9_K3dnRrz6hIKzmltTYPmvDk0MBjjEBkCXTdg,2474
|
14
16
|
fabricatio/toolboxes/__init__.py,sha256=bjefmPd7wBaWhbZzdMPXvrjMTeRzlUh_Dev2PUAc124,158
|
15
17
|
fabricatio/toolboxes/task.py,sha256=xgyPetm2R_HlQwpzE8YPnBN7QOYLd0-T8E6QPZG1PPQ,204
|
16
|
-
fabricatio-0.1.
|
17
|
-
fabricatio-0.1.
|
18
|
-
fabricatio-0.1.
|
19
|
-
fabricatio-0.1.
|
18
|
+
fabricatio-0.1.3.dist-info/METADATA,sha256=pDZPikewIva_s6riDaxhlOmvd92ls_JoS_VqETPwDdM,3797
|
19
|
+
fabricatio-0.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
20
|
+
fabricatio-0.1.3.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
|
21
|
+
fabricatio-0.1.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|