fasttask_manager
Manager for fasttask
Installation
pip install fasttask_manager
Usage
Create a Manager
Synchronous Manager:
from fasttask_manager import Manager
m = Manager("127.0.0.1", port=8080)
Asynchronous Manager:
import asyncio
from fasttask_manager import AsyncManager
async def main():
am = AsyncManager("127.0.0.1", port=8080)
# use await
result = await am.run(params)
Run a task
result = m.run(params)
Create a task and check result later
result_id = m.create_task(params)
# do something...
result = m.check(result_id)
Create a task and wait for result
result = m.create_and_wait_result(params)
Large results (offloaded to object storage)
当 FastTask 配置了 RESULT_TYPE=S3/AUTO 且结果较大时,/check 返回的 result
不再是结果本身,而是对象存储引用(result_type 为 "s3",含预签名下载地址)。
Manager 会自动处理这种情况,调用方拿到的始终是真实结果:
# create_and_wait_result 默认自动下载外置结果
result = m.create_and_wait_result(task_name, params)
# check 需要显式开启;默认原样返回带 result_type 的完整响应
resp = m.check(task_name, result_id) # 原始响应
resp = m.check(task_name, result_id, resolve_result=True) # 自动下载后返回真实结果
# 也可以显式下载(传响应或直接传预签名地址)
result = m.download_result(resp) # 解析 JSON 并返回
m.download_result(resp, local_path="result.json") # 流式落盘,返回文件路径
异步版本用法相同(await 即可):
result = await am.create_and_wait_result(task_name, params)
result = await am.check(task_name, result_id, resolve_result=True)
result = await am.download_result(resp, local_path="result.json")
注:预签名地址自带鉴权,下载时不会携带 Basic 凭据(否则会破坏签名)。
结果形态严格按服务端的 result_type 处理,不做静默兜底:
json/text:直接返回result内容(内联结果与错误/状态文本保持原行为)s3:取引用里的下载地址并下载解析;引用格式不符、缺下载地址、下载失败均直接报错- 未知的
result_type、响应不是对象:直接报错(客户端与服务端版本不匹配) - 服务端未返回
result_type(旧版本):打印 warning 提醒尽快升级,并按内联结果处理
Upload a file
file_name = m.upload("/path/to/file.txt")
Download a file
m.download("file.txt", "/path/to/save.txt")
Revoke a task
m.revoke(result_id)
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
| host | str | - | Server host |
| protocol | str | "http" | HTTP protocol |
| port | int | 80 | Server port |
| tries | int | 5 | Max retry attempts |
| delay | int | 3 | Retry delay (seconds) |
| logger | Logger | None | Custom logger |
| log_prefix | str | "" | Log prefix |
| auth_user | str | "" | Basic auth username |
| auth_passwd | str | "" | Basic auth password |
| url_base_path | str | "" | URL base path |
| req_timeout | int | 30 | Request timeout (seconds) |
| simple_error_log | bool | True | Simple error logging |
| verify_ssl | bool | False | Verify SSL certificate |
Architecture
BaseManager (shared initialization and utilities)
├── Manager (synchronous implementation)
│ ├── _req: uses requests library
│ └── _wait: uses time.sleep
└── AsyncManager (asynchronous implementation)
├── _req: uses httpx async client
└── _wait: uses asyncio.sleep
Metadata
Release files for fasttask-manager 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fasttask_manager-0.6.1.tar.gz | 13.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fasttask_manager-0.6.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.8 kB
Release files / fasttask_manager-0.6.1.tar.gz
| Download URL | fasttask_manager-0.6.1.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e7d049d073a5d2c15f7ecf6c765ec99bd4fb11526c923309a72de1d727873e9f
|
|
BLAKE2b-256 checksum How to use checksums |
4a52f4e079121f888fd3b80496f0d0589607d53fc5c0a7687550c6be025541f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / fasttask_manager-0.6.1-py3-none-any.whl
| Download URL | fasttask_manager-0.6.1-py3-none-any.whl |
|---|---|
| Size | 16.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c73ccb964fe8b6c3356332b5e653d654d3016838a6d98f1d95c5a68aa8e0649
|
|
BLAKE2b-256 checksum How to use checksums |
43e34b60fe89ba2e3a41eca3d789e719fe0325b7c1c6675a328c59226a2dc0fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|