Create a new task and persist.
(self, description: str, parent_id: Optional[str] = None)
| 52 | self._load() |
| 53 | |
| 54 | def create_task(self, description: str, parent_id: Optional[str] = None) -> Task: |
| 55 | """Create a new task and persist.""" |
| 56 | with self._lock: |
| 57 | self._counter += 1 |
| 58 | task_id = f"task_{self._counter:03d}" |
| 59 | now = datetime.now(timezone.utc).isoformat() |
| 60 | task = Task( |
| 61 | id=task_id, |
| 62 | description=description, |
| 63 | parent_id=parent_id, |
| 64 | created_at=now, |
| 65 | updated_at=now, |
| 66 | ) |
| 67 | self._tasks[task_id] = task |
| 68 | self._revision_log.append( |
| 69 | { |
| 70 | "timestamp": now, |
| 71 | "action": "created", |
| 72 | "task_id": task_id, |
| 73 | "description": description, |
| 74 | } |
| 75 | ) |
| 76 | self._persist() |
| 77 | return task |
| 78 | |
| 79 | def update_task(self, task_id: str, **kwargs) -> Task: |
| 80 | """Update task fields and persist. Accepts any Task field as kwarg.""" |
no test coverage detected