Skip to content

Commit b25521c

Browse files
committed
fix(python): fix max_duration conversion and disable bytecode cache in dev
1 parent f47a578 commit b25521c

File tree

8 files changed

+26
-5
lines changed

8 files changed

+26
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"clean:node_modules": "find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +",
3737
"clean:python": "find . -name '*.pyc' -delete && find . -name '__pycache__' -type d -exec rm -rf '{}' + 2>/dev/null || true",
3838
"clean:all": "pnpm run clean && pnpm run clean:python",
39+
"rebuild:cli": "pnpm run clean:python && pnpm run build --filter trigger.dev",
3940
"typecheck": "turbo run typecheck",
4041
"test:e2e": "playwright test",
4142
"test:e2e:ui": "playwright test --ui",

packages/cli-v3/src/entryPoints/python/managed-index-worker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ def collect_task_metadata() -> List[Dict[str, Any]]:
9999
if task_meta.queue:
100100
task_dict["queue"] = task_meta.queue.model_dump()
101101
if task_meta.maxDuration is not None:
102+
# Already in milliseconds from task decorator
102103
task_dict["maxDuration"] = task_meta.maxDuration
104+
logger.debug(f"Task {task_id} maxDuration: {task_meta.maxDuration}ms")
103105

104106
tasks.append(task_dict)
105107
logger.debug(f"Collected task: {task_id}")

packages/cli-v3/src/indexing/indexWorkerManifest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export async function indexWorkerManifest({
5050
TRIGGER_BUILD_MANIFEST_PATH: buildManifestPath,
5151
NODE_OPTIONS: nodeOptions,
5252
TRIGGER_INDEXING: "1",
53+
PYTHONDONTWRITEBYTECODE: "1", // Disable .pyc files in dev to avoid stale cache
5354
},
5455
execPath: execPathForRuntime(runtime),
5556
});

packages/cli-v3/src/ipc/grpcServer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,13 @@ export class GrpcWorkerServer extends EventEmitter {
140140
...(logMessage.exception && { exception: logMessage.exception }),
141141
};
142142

143+
// Normalize log level to number (protobuf sends enum as string name)
144+
const level = typeof logMessage.level === 'string'
145+
? LogLevel[logMessage.level as keyof typeof LogLevel]
146+
: logMessage.level;
147+
143148
// Route to appropriate log level
144-
switch (logMessage.level) {
149+
switch (level) {
145150
case LogLevel.DEBUG:
146151
logger.debug('Python worker', logData);
147152
break;
@@ -158,7 +163,7 @@ export class GrpcWorkerServer extends EventEmitter {
158163
}
159164
break;
160165
default:
161-
logger.info('Python worker', logData);
166+
logger.warn('Python worker (unknown log level)', { ...logData, receivedLevel: logMessage.level });
162167
}
163168
}
164169

packages/cli-v3/src/python/pythonProcess.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class PythonProcess {
5454
...process.env,
5555
...this.options.env,
5656
PYTHONUNBUFFERED: "1",
57+
PYTHONDONTWRITEBYTECODE: "1", // Disable .pyc files in dev to avoid stale cache
5758
TRIGGER_GRPC_ADDRESS: grpcAddress,
5859
},
5960
stdio: ["pipe", "pipe", "pipe"],

packages/cli-v3/src/python/pythonTaskRunner.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,17 @@ export class PythonTaskRunner {
113113

114114
// Wait for completion or failure
115115
const result = await new Promise<TaskRunExecutionResult>((resolve, reject) => {
116+
// execution.run.maxDuration is in SECONDS from the platform, convert to milliseconds
117+
const maxDurationMs = execution.run.maxDuration
118+
? execution.run.maxDuration * 1000
119+
: 300000;
120+
logger.debug(`Setting task timeout to ${maxDurationMs}ms (${maxDurationMs/1000}s)`, {
121+
maxDuration: execution.run.maxDuration,
122+
runId: execution.run.id,
123+
});
116124
const timeout = setTimeout(() => {
117125
reject(new Error("Task execution timeout"));
118-
}, execution.run.maxDuration ?? 300000);
126+
}, maxDurationMs);
119127

120128
grpcServer.on("TASK_RUN_COMPLETED", (message: any) => {
121129
clearTimeout(timeout);

packages/python-sdk/trigger_sdk/task.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,14 @@ async def my_task(payload):
8888
retry_config = RetryConfig(**retry) if isinstance(retry, dict) else retry
8989
queue_config = QueueConfig(**queue) if isinstance(queue, dict) else queue
9090

91+
# Convert max_duration from seconds to milliseconds (TypeScript expects ms)
92+
max_duration_ms = max_duration * 1000 if max_duration is not None else None
93+
9194
config = TaskConfig(
9295
id=id,
9396
retry=retry_config,
9497
queue=queue_config,
95-
maxDuration=max_duration,
98+
maxDuration=max_duration_ms,
9699
)
97100

98101
def decorator(fn: Callable[..., Any]) -> Task:

packages/python-sdk/trigger_sdk/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TaskConfig(BaseModel):
2424
id: str
2525
retry: Optional[RetryConfig] = None
2626
queue: Optional[QueueConfig] = None
27-
maxDuration: Optional[int] = None # seconds
27+
maxDuration: Optional[int] = None # milliseconds (converted from seconds in decorator)
2828

2929

3030
class TaskMetadata(BaseModel):

0 commit comments

Comments
 (0)