Files
calendar/packages/features/tasker/internal-tasker.ts
T
Keith WilliamsGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1739114490 perf: separate task creation from processing to eliminate compilation overhead (#23485)
* refactor: separate task creation from processing to eliminate compilation overhead

- Create TaskProcessor class to handle task processing logic
- Move processQueue and cleanup methods to TaskProcessor
- Remove task handler imports from InternalTasker creation path
- Eliminate 2.5-3s compilation overhead by only loading task handlers during processing
- Maintain existing tasker.create() API for all callers
- Use composition pattern for clean separation of concerns

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

refactor: completely separate TaskProcessor from InternalTasker

- Remove processQueue() and cleanup() methods from Tasker interface
- Eliminate TaskProcessor dependency from InternalTasker class
- Update API endpoints (cron.ts, cleanup.ts) to use TaskProcessor directly
- Update README documentation to show correct TaskProcessor usage
- Complete separation ensures task creation no longer imports task handlers
- Eliminates 2.5-3s compilation overhead while preserving all functionality

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

* Moved the cleanup method back to internal tasker

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2025-09-01 07:08:06 +00:00

32 lines
1.2 KiB
TypeScript

import { Task } from "./repository";
import type { TaskTypes } from "./tasker";
import { type TaskerCreate, type Tasker } from "./tasker";
/**
* This is the default internal Tasker that uses the Task repository to create tasks.
* It doesn't have any external dependencies and is suitable for most use cases.
* To use a different Tasker, you can create a new class that implements the Tasker interface.
* Then, you can use the TaskerFactory to select the new Tasker.
*/
export class InternalTasker implements Tasker {
create: TaskerCreate = async (type, payload, options = {}): Promise<string> => {
const payloadString = typeof payload === "string" ? payload : JSON.stringify(payload);
return Task.create(type, payloadString, options);
};
async cleanup(): Promise<void> {
const count = await Task.cleanup();
console.info(`Cleaned up ${count} tasks`);
}
async cancel(id: string): Promise<string> {
const task = await Task.cancel(id);
return task.id;
}
async cancelWithReference(referenceUid: string, type: TaskTypes): Promise<string | null> {
const task = await Task.cancelWithReference(referenceUid, type);
return task?.id ?? null;
}
}