Statuses

Statuses keep track of the completion of an action when an event is received.

About Event Statuses

A status keep track of the success or failure of an action realized by an app. It gives feedback to the user to see if his action has been correctly executed.

If an action is declared by the App for a specific event, the app also receives a "statusId" in the message.

It is the responsibility of the registered App to update the status using Sirius GraphQL API.

Updating a status

Using the ID received in a status, it is possible to update the status using the GraphQL API.

mutation (
$statusId: ID!
$conclusion: StatusConclusion!
$output: UpdateStatusOutputInput!
) {
updateStatus(
input: {
id: $statusId
status: completed
conclusion: $conclusion
output: $output
}
) {
id
}
}

This mutation is a good start to update a status, several things:

  • The status "completed" means that the status is in a final state.
  • In this final state, the conclusion could indicate "success", "failure" or "timed_out".
  • The output ({ title: string, summary: string }) gives you opportunity to describe the state of the status.

Example of event handling with status update

const app = require("express");
const axios = require("axios");
const UpdateStatusMutation = `
mutation(
$statusId: ID!
$conclusion: StatusConclusion!
$output: UpdateStatusOutputInput!
) {
updateStatus(
input: {
id: $statusId
status: completed
conclusion: $conclusion
output: $output
}
) {
id
}
}
`;
app.post("/webhook", express.json(), async (req, res, next) => {
// Get status ID in headers
const statusId = req.headers["x-sirius-status-id"];
switch (req.headers["x-sirius-event"]) {
case "live": {
try {
// do something with live event..
// note, it is better to do it asynchronously
if (statusId) {
await axios.post("https://lemonde.sirius.press/api/public/graphql", {
headers: {
Authorization: "Bearer <token>",
},
data: {
query: UpdateStatusMutation,
variables: {
statusId,
conclusion: "success",
output: { title: "Live saved" },
},
},
});
}
} catch (error) {
// Update status
if (statusId) {
await axios.post("https://lemonde.sirius.press/api/public/graphql", {
headers: {
Authorization: "Bearer <token>",
},
data: {
query: UpdateStatusMutation,
variables: {
statusId,
conclusion: "failure",
output: {
title: "Error while saving live",
summary: error.message,
},
},
},
});
}
}
}
default: {
res.send("OK");
}
}
});
Edit this page on GitHub