AiAsyncPocessor - Generic asynchronous AI task processing

AiAsyncPocessor - Generic asynchronous AI task processing

v1.0.0

Asynchronous AI task processing infrastructure for Magento 2

AiAsyncProcessor decouples slow, external AI API calls (e.g. OpenAI requests made by other WebtechSolutions modules) from the synchronous HTTP request/response cycle. Instead of blocking checkout, admin actions, or any other customer-facing request while waiting on an AI response, modules publish a task to a RabbitMQ queue and return immediately. A background consumer picks up the task, executes it, and handles retries and permanent failures automatically.

This module has no admin UI and no configuration screen — it is a piece of shared backend infrastructure other modules build on top of.

Why This Exists

Modules like WebtechSolutions_MageInsightPro perform real-time fraud scoring on every order by calling OpenAI synchronously inside a sales_order_place_after observer. On Magento Cloud (and any PHP-FPM deployment with a limited worker pool), a slow or rate-limited AI API call directly threatens checkout throughput — a single stuck request holds a worker until the external call times out.

AiAsyncProcessor removes that risk: the observer publishes a small message and returns in milliseconds. The actual AI call happens in a separate consumer process, off the request path entirely.

Key Features

  • Generic task queue — any module can publish an AI task without adding new queue infrastructure of its own
  • Extensible task handler registry — new task types are registered via di.xml array merge, no changes to this module required
  • Automatic retry — transient failures (thrown exceptions) are retried up to a configurable limit before being given up on
  • Dead Letter Queue (DLQ) — tasks that exceed the retry limit are routed to ai.task.process.dlq via RabbitMQ's native x-dead-letter-exchange, so no message is silently lost
  • Structured logging — every attempt, retry, and DLQ routing decision is logged to a dedicated channel (var/log/support_ai_async.log)
  • Optional DLQ visibility consumer — drains the dead letter queue into the log for manual inspection

Requirements

  • Magento 2.4.x
  • PHP 8.1+
  • Magento_MessageQueue (core module)
  • RabbitMQ / AMQP connection configured in app/etc/env.php

1.0.0

Added

  • Initial release: WebtechSolutions_AiAsyncProcessor module
  • Generic asynchronous task processing infrastructure for AI-related operations, built on RabbitMQ/AMQP, so slow external AI calls no longer block customer-facing requests
  • Extensible task handler registry: new AI task types can be added by other modules without modifying this module
  • Automatic retry on transient failures, with failed tasks routed to a dedicated error queue after repeated failures
  • Structured logging of all task processing attempts and failures to a dedicated log channel