Skip to main content

Handler Overview

TaskDaemon handlers are containerized programs that process tasks. They communicate via a simple JSON protocol over stdin/stdout, making it possible to write handlers in any programming language.

How Handlers Work

  1. TaskDaemon sends a JSON task to the handler’s stdin
  2. Handler processes the task
  3. Handler writes a JSON result to stdout
  4. TaskDaemon captures the result

Protocol

Input (stdin)

Output (stdout)

Success:
Error (retryable):
Error (permanent):

Official SDKs

We provide SDKs that handle the protocol for you:

Python

pip install taskdaemon

Node.js

npm install @taskdaemon/handler

Go

go get github.com/taskdaemon/handler-go

Rust

cargo add taskdaemon-handler

C++

Header-only library

Java

Maven/Gradle package

C#

NuGet package

Raw Protocol

Any language

Handler Requirements

1

Read JSON from stdin

Handler must continuously read line-delimited JSON from stdin
2

Process the task

Parse the task data and perform the work
3

Write JSON to stdout

Output a single JSON line with status and result
4

Flush output

Ensure stdout is flushed after each response
Print statements are safe. TaskDaemon automatically skips non-JSON lines in handler output, so print() statements for debugging won’t break the protocol. However, for production use, logging to stderr is recommended.

Logging to stderr

For production handlers, log to stderr instead of stdout to keep logs separate from the JSON protocol:

Minimal Example

Here’s the simplest possible handler in Python:

Dockerfile

Handlers must be packaged as Docker images. Make sure to install the SDK from the package manager:
Always use unbuffered output (-u flag in Python, flush=True, etc.) to ensure responses are sent immediately.

Configuration

Register handlers in handlers.toml:
See handlers.toml configuration for all options.