Background Tasks That Run Themselves

Contributors

Michael Scharf
Cief Architect
Estimated Implementation Time
1-2 hours
Key Libraries Used
  • @operaide/aktor
LLM Providers & Models
  • None
External Services
  • None
TAGS
Background Processing

Introduction

Orders sit in a queue, the system checks for work every few seconds, and processes items one by one until the queue is empty — then waits for more. A built-in control panel lets you start, stop, and monitor processing in real time with a live progress bar. Background work that runs fast when busy and idles efficiently when done.

Business Impact

Challenge

Background tasks like order processing, message queues, or batch jobs need reliable, self-regulating execution without manual intervention.

Solution

A Polling Reaktor continuously checks for pending work, processes items immediately when available, and idles on an interval when the queue is empty.

Outcome

Hands-free queue processing that adapts to workload — fast when busy, efficient when idle.

What It Does

  • Automatic Queue Processing — The system checks for pending orders every few seconds. When orders exist, it processes them one by one without delay. When the queue is empty, it falls back to a periodic check — no manual intervention needed.
  • Self-Regulating Speed — Processing adapts to workload automatically. Busy queues are handled as fast as possible; empty queues consume no resources. The system scales its own pace without configuration.
  • Built-In Control Panel — A web interface lets you start, stop, and monitor processing in real time. See remaining orders with a progress bar, check the current state, and reset the queue — all from one screen.
  • Queue Status & Management — Queue state is available as an API, so external systems can query progress or trigger resets programmatically alongside the built-in UI.

How It Works

  • Polling Reaktor RegistrationregisterPollingReaktor creates a timer-based Reaktor with a configurable interval (5 seconds) and autoStart: false. The platform manages the execution lifecycle — start, stop, and timing are handled via built-in REST endpoints.
  • Conditional Flow with aktorIfElse — The core logic is a single aktorIfElse: if orders exist (aktorHasOrders), process one (aktorProcessOrder); otherwise return false to signal idle. The boolean return value directly controls whether the next execution is immediate or delayed.
  • Sync and Async AktorsaktorHasOrders is a synchronous createAktorFunction (simple array check), while aktorProcessOrder is an async createAktorFunctionAsync (simulates processing time). Both patterns coexist in the same graph.
  • Helper Reaktors as API EndpointsregisterReaktorDefinition creates two additional endpoints: one for queue status queries, one for resetting the queue. These are plain Reaktors that return data — no polling, no timer — used by the UI for real-time monitoring.
  • Integrated Custom UI — The public/ directory ships a control panel built with plain JavaScript and Bootstrap. It uses window.getOperaideAuthToken() for authentication and auto-refreshes every two seconds when the processor is running.

Reaktor Architecture

The Polling Coffee Queue app registers three endpoints. The polling Reaktor is the core: its createReaktor returns an aktorIfElse that checks for orders and either processes one (returning true for immediate re-execution) or signals idle (false for interval wait). Two helper Reaktors provide queue status and reset functionality as standard REST endpoints. The custom UI in public/ ties them together — calling the polling control endpoints (start/stop/status) and the helper Reaktors (queue status/reset) to provide a real-time dashboard. The entire app is a single TypeScript file plus the UI assets.

Why Operaide

Ready to Ship AI

That Works?

See how Operaide helps teams ship reliable AI applications faster. From prototype to production—with complete control and European sovereignty.

More Than Chat. The AI-Native Enterprise

Browse our repository of AI applications built with Operaide. All available in the Operaide platform’s app store as templates for you to get a headstart when implementing your custom AI solutions.