Asynchronous task execution and callbacks

In addition to supporting synchronous requests, Mu also has a job queueing system that accepts asynchronous job submissions. When an asynchronous job is submitted (using the POST /jobs/async request), it is not executed right away. Instead, the job goes into a server queue to be executed later, and a job identifier is immediately returned to the client as a response. This identifier can then be used later to query for the status of the submitted job (using GET /jobs, e. g., GET /jobs/55130d0917d07ff825f1ce1b).

Moreover, the user may specify a callback request along with a job submission, which will be carried out immediately after the job finishes execution. The callback is described as a general HTTP request by the user, as described in the input example below. The request format also accepts a body field for setting the HTTP body, but if left blank Mu will automatically set the job response body to the callback body.

After submitting a job, its status may be queried with the GET /jobs/<id> request, which will always return one of the following states:

  1. "status": "queued": Job is queued for execution (but hasn't been executed yet);
  2. "status": "dequeued": Job is currently being executed by Mu;
  3. "status": "success": Job finished successfully;
  4. "status": "failure": Job failed to execute.

  • Endpoint: POST http://mu3.hp-mu.com/jobs/async
  • Authorization: BASIC bXVscHA6eGhDdGNxNW9U
  • Accept-type: application/json
  • Content-type: application/json
  • Input schema sample: (For embedding two background watermarks to pages 1 and 2 of a PDF file with strength value 10, 75dpi resolution and 0.1% gray background tinting.)
{
    "workflow": [
        {
            "task": "EmbedBackgroundWatermark",
            "inputs": {
                "lpp_access_token": "N2Roemw3aHVvZjFpdWgzanQwdjIyMDJjZHFwdW00bHU6cmljYXJkby5waWNjb2xpQGhwLmNvbToxNDI3MzEwODcyOTY2OjE0MjczMTQ0NzI5NjY6ZGVmYXVsdDo6VitsaDB1Mnpyakw5QXJyZUJMV2xOanNXRWZLM2Q3ZmY2Zk5xaEJSeFJWTk4xWHRRZFlCSlpINzlxZjk4N2Z5YkxvQVA2YUpBd3hja2Nkd3U2aFg2VXU3YTBOUW9oRzZKblpwUk1OM25QM0Mwc09kcHpoU3dabzdNcWZvN2xqMk8xT3lsRkxGckhzVzV0VmduTFVDb3IxUmdaNzE3QXJlTWQ3YytyZHQzbWFRPQ==",
                "pdf": "http://127.0.0.1:9999/wallart.pdf",
                "resolution": 200,
                "strength": 10,
                "background_tint": "10%",
                "embedded_pairs": [
                    {
                        "page_num": 1,
                        "trigger_watermark_url": "https://watermark.livepaperapi.com/watermark/v1/triggers/rUsCSIjcTq2tJcVHLSLm2w/image"
                    }
                ]
            }
        }
    ],
    "onfinish": {
        "task": "HttpRequest",
        "inputs": {
            "url": "http://127.0.0.1:8080/tests/callback",
            "method": "POST",
            "headers": {
                "Authorization": "Basic ZZZZZ"
            }
        }
    }
}
  • Output schema sample: (This response can be equivalently obtained with GET /jobs/55130d0917d07ff825f1ce1b in this example.)
{
    "id": "55130d0917d07ff825f1ce1b",
    "receivedAt": 1427311881068,
    "status": "queued",
    "workflow": [
        {
            "task": "EmbedBackgroundWatermark",
            "inputs": {
                "lpp_access_token": "N2Roemw3aHVvZjFpdWgzanQwdjIyMDJjZHFwdW00bHU6cmljYXJkby5waWNjb2xpQGhwLmNvbToxNDI3MzEwODcyOTY2OjE0MjczMTQ0NzI5NjY6ZGVmYXVsdDo6VitsaDB1Mnpyakw5QXJyZUJMV2xOanNXRWZLM2Q3ZmY2Zk5xaEJSeFJWTk4xWHRRZFlCSlpINzlxZjk4N2Z5YkxvQVA2YUpBd3hja2Nkd3U2aFg2VXU3YTBOUW9oRzZKblpwUk1OM25QM0Mwc09kcHpoU3dabzdNcWZvN2xqMk8xT3lsRkxGckhzVzV0VmduTFVDb3IxUmdaNzE3QXJlTWQ3YytyZHQzbWFRPQ==",
                "pdf": "http://127.0.0.1:9999/wallart.pdf",
                "resolution": 200,
                "strength": 10,
                "background_tint": "10%",
                "embedded_pairs": [
                    {
                        "page_num": 1,
                        "trigger_watermark_url": "https://watermark.livepaperapi.com/watermark/v1/triggers/rUsCSIjcTq2tJcVHLSLm2w/image"
                    }
                ]
            }
        }
    ],
    "onfinish": {
        "task": "HttpRequest",
        "inputs": {
            "url": "http://127.0.0.1:8080/tests/callback",
            "method": "POST",
            "headers": {
                "Authorization": "Basic ZZZZZ"
            },
        }
    }
}