SuffolkLITLab / ALKiln

Integrated automated end-to-end testing with docassemble, puppeteer, and cucumber.
https://assemblyline.suffolklitlab.org/docs/alkiln/intro
MIT License
14 stars 4 forks source link

Internal: Use `health_status` to check if server is up #767

Open plocket opened 11 months ago

plocket commented 11 months ago

Use a server_url.com/health_check?ready=1 type of thing instead of making get_user_id() do double duty. That API call isn't really designed for that anyway.

BryceStevenWilley commented 11 months ago

Confirming that you mean get_dev_id, and that it would just be changed for is_server_responding, right? https://github.com/SuffolkLITLab/ALKiln/blob/f6237b510eca937afba7d0fe858646bcaf007246/lib/docassemble/docassemble_api_interface.js#L137

Slight suggestion to use server_url.com/health_status?ready=1 instead, which is already in JSON. It'll look something like this:

{
  "ok": true,
  "server_start_time": 1696040337.5918229,
  "version": "1.4.67"
}
plocket commented 11 months ago

Yes and sounds good 👍

plocket commented 9 months ago

Note: We still need get_dev_id() for the playground interview url address and we might add some setup code for playground installs to specifically check that they have given the right API key so we don't go through (potentially) reloading the server and everything before then discovering the API key is invalid.

Moving on, the code would look similar to this, just with health_status:

// node -e 'require("./lib/docassemble/docassemble_api_REST.js").health_check()'
da.health_check = async function ( timeout ) {
  try {
    return await axios.get(
      `${ session_vars.get_da_server_url() }/health_check?ready=1`,
      { timeout }
    );
  } catch ( error ) {
    let response = error.response || { data: null }
    throw { ...error.toJSON(), data: response.data };
  }
};  // Ends da.health_check()