TaskAgent is a Go 1.24 module that polls Feishu Bitable queues, keeps Android capture devices busy, persists outcomes to Feishu/SQLite, and triggers piracy-specific workflows. It is designed to be embedded inside existing schedulers/agents so you only need to provide device implementations plus business-side runners.
Feishu Task Table ──> tasks.Source (pkg/tasksource/feishu)
│ │
▼ ▼
DeviceProvider ──> internal/agent/{device,scheduler} ──> JobRunner (your code)
│ │ │
▼ ▼ ▼
Device recorder lifecycle callbacks Storage + webhook/piracy packages
- internal/agent (
device,scheduler,lifecycle,tasks): encapsulates device discovery, recorder sync, task polling, and lifecycle callbacks.pool.DevicePoolAgentis now a thin façade over these modules so downstream API surface stays stable. - pkg/tasksource/feishu: Feishu-backed implementation of the
tasks.Sourceinterface, re-exported viapool.NewFeishuTaskClient. - feishu package: wraps Bitable APIs, exposes schema structs (
TaskFields,ResultFields,DeviceFields) plus rate-limited result writers (FEISHU_REPORT_RPS). - providers/adb: default ADB-backed device provider; swap in custom providers without touching the pool.
- pkg/devrecorder & pkg/storage: optional Feishu device heartbeats and SQLite-first capture storage with async reporting.
- cmd/piracy / pkg/piracy: piracy detection CLI, webhook worker, backfill helpers, and group-task automation with shared helpers under
pkg/piracy/types,pkg/feishu/fields, etc.
pool.go,devicemetainfo.go,internal/agent/**: scheduling core, device registry, lifecycle plumbing, and unit coverage.pkg/tasksource/feishu: Feishu task polling client + table mirror; re-exported frompoolfor backward compatibility.feishu/: API client, schema definitions, spreadsheet helpers, rate limiter, and README.pkg/piracy/,pkg/piracy/types,pkg/feishu/fields,cmd/piracy/: CLI entry points plus detection/webhook logic with shared helpers.pkg/storage/,pkg/devrecorder/: SQLite + Feishu sinks and device recorder helpers.docs/: deep dives (Feishu API usage, piracy group tasks, webhook worker, result storage).
- Clone & download modules
git clone [email protected]:httprunner/TaskAgent.git cd TaskAgent go mod download
- Provide credentials – Create a
.env(loaded viainternal/envload) with at leastFEISHU_APP_ID,FEISHU_APP_SECRET,TASK_BITABLE_URL, and any recorder/storage URLs. Seedocs/ENVIRONMENT.mdfor the full matrix. - Validate toolchain – Run the standard gate before making changes:
go fmt ./... go vet ./... go test ./... # Optional: live API validation (requires production tables) FEISHU_LIVE_TEST=1 go test ./feishu -run Live
- Implement a JobRunner – supply how tasks execute once TaskAgent hands you a device serial + payload:
Add
package main import ( "context" "log" "os" "time" pool "github.com/httprunner/TaskAgent" "github.com/httprunner/TaskAgent/pkg/feishu" ) type CaptureRunner struct{} func (CaptureRunner) RunJob(ctx context.Context, req pool.JobRequest) error { for _, task := range req.Tasks { if req.Lifecycle != nil && req.Lifecycle.OnTaskStarted != nil { req.Lifecycle.OnTaskStarted(task) } // TODO: execute capture logic with task.Payload / req.DeviceSerial if req.Lifecycle != nil && req.Lifecycle.OnTaskResult != nil { req.Lifecycle.OnTaskResult(task, nil) } } return nil } func main() { cfg := pool.Config{ PollInterval: 30 * time.Second, MaxTasksPerJob: 2, BitableURL: os.Getenv(feishu.EnvTaskBitableURL), AgentVersion: "capture-agent", } runner := CaptureRunner{} agent, err := pool.NewDevicePoolAgent(cfg, runner) if err != nil { log.Fatal(err) } ctx, cancel := context.WithCancel(context.Background()) defer cancel() if err := agent.Start(ctx, "capture-app"); err != nil { log.Fatal(err) } }
DeviceRecorder(Feishu tables) or custom providers as needed; leave URLs empty to disable recorder writes.
- Implement
pool.DeviceProviderif you are not using the bundled ADB provider. - Implement
pool.JobRunnerto translate Feishu payloads into device-specific actions. - Optionally wire a
TaskManageralternative if tasks are not Feishu-backed. - Configure device & task recorders (
DEVICE_BITABLE_URL,DEVICE_TASK_BITABLE_URL) to observe fleet health and dispatch history.
- Detect:
go run ./cmd/piracy detect --result-filter='{"conjunction":"and","conditions":[...]}' --output-csv result.csv - Auto workflow:
go run ./cmd/piracy auto --task-url "$TASK_BITABLE_URL" --result-url "$RESULT_BITABLE_URL" - Webhook worker:
go run ./cmd/piracy webhook-worker --app kwai --task-url "$TASK_BITABLE_URL"The CLI reuses the same Feishu/SQLite helpers as the agent; seedocs/webhook-worker.mdanddocs/piracy-group-tasks.mdfor behavior details.
pkg/storagewrites every capture to SQLite (TRACKING_STORAGE_DB_PATH) and optionally Feishu (RESULT_STORAGE_ENABLE_FEISHU=1).- Async reporter knobs (
RESULT_REPORT_*,FEISHU_REPORT_RPS) keep uploads within Feishu rate-limits. pkg/devrecordermirrors device state (DeviceSerial,Status,RunningTask, etc.) to Feishu tables; override column names viaDEVICE_FIELD_*env vars.- Consult
docs/result-storage.mdfor schema diagrams and failure playbooks.
- Credentials & Feishu endpoints:
FEISHU_APP_ID,FEISHU_APP_SECRET,FEISHU_TENANT_KEY,FEISHU_BASE_URL. - Task/result/device tables:
TASK_BITABLE_URL,RESULT_BITABLE_URL,DEVICE_BITABLE_URL,DEVICE_TASK_BITABLE_URL. - Field overrides:
TASK_FIELD_*,RESULT_FIELD_*,DRAMA_FIELD_*,DEVICE_FIELD_*,DEVICE_TASK_FIELD_*. - Storage knobs:
TRACKING_STORAGE_DISABLE_JSONL,TRACKING_STORAGE_DB_PATH,RESULT_STORAGE_ENABLE_FEISHU,RESULT_SQLITE_TABLE,DRAMA_SQLITE_TABLE. - Reporter throttles:
RESULT_REPORT_POLL_INTERVAL,RESULT_REPORT_BATCH,RESULT_REPORT_HTTP_TIMEOUT,FEISHU_REPORT_RPS. Refer todocs/ENVIRONMENT.mdfor the authoritative table describing defaults, requirements, and consuming packages.
pending/failed (Feishu filter)
│ FetchAvailableTasks
▼
dispatched ──> TaskLifecycle.OnTaskStarted (Status=running, recorder updates)
│
▼
running ──> TaskLifecycle.OnTaskResult (success/failed)
│
▼
OnTasksCompleted → Feishu updates + recorder cleanup
FeishuTaskClient fetches tasks in prioritized bands (个人页搜索 before 综合页搜索, same-day before backlog, failed before untouched) and only fills the shortfall to MaxTasksPerJob. See pkg/tasksource/feishu/client.go for the full prioritization table.
- Missing tasks – verify
TASK_BITABLE_URLpoints to a view with Status=pending/failed, App matches theStartargument, and the service account has permission to read. - Recorder errors – leave
DEVICE_BITABLE_URL/DEVICE_TASK_BITABLE_URLempty to disable, or double-check field overrides align with your schema. - Result uploads throttled – increase
RESULT_REPORT_BATCH, relaxRESULT_REPORT_POLL_INTERVAL, or scaleFEISHU_REPORT_RPSto avoid 99991400 responses. - Webhook retries – inspect
Webhookcolumn (pending/failed/error) and runcmd/piracy webhook-workerwith the same App filter; seedocs/webhook-worker.mdfor retry semantics.
docs/ENVIRONMENT.md– comprehensive list of configuration keys.docs/result-storage.md– SQLite + async reporter internals.docs/piracy-group-tasks.md– how group child tasks and webhooks are derived.docs/webhook-worker.md– webhook lifecycle and CLI usage.docs/feishu-api-summary.md– Bitable API reference for this repo.AGENTS.md– contributor workflow and coding standards.