Skip to content

CIS import scheduling

After migration to Wagtail the intention was that the CIS inport commands (chained together in tate/art/management/commands/import_cis_contents.py) would be scheduled to run weekly via an Azure Function. The set up is as follows:

  • The 'StartCisImport' Azure Funtion in the aztate-prd-ew-dg-wgtail-fnc-app01 function app is set up to use a timer trigger
  • This corresponds to the invocation in the tate-wagtail codebase under functions/StartCisImport
  • The actual scheduling is specified in functions/StartCisImport/function.js as "schedule": "0 0 1-8 * * Tuesday" which equates to running the import_cis_content.py command every hour from 01.00 - 08.00 every Tuesday.

The StartCisImport Azure Function works exactly as it should and is undoubtedly a reilable sheduling mechanism but it's become apparent that the import_cis_content django command is not running successfully when triggered by the StartCisImport Azure Function.

Azure Functions use an HTTP request to trigger something. The CIS import command that should respond to the trigger sits on the app server with the rest of the site code. The Azure Function HTTP request to trigger the command is therefore handled by the Gunicorn HTTP server like any other client request.

Following triggering by StartCisImport, import_cis_content starts correctly but consistently fails after around 25 seconds with a Gunicorn aborted worker error.

The Gunicorn error seems to tie in with the Gunicorn timeout setting of 25 seconds used in our config.

This issue requires dedicated investigation. Here are some pointers/suggestions that may assist with this: - Running the import_cis_content command manually (i.e not via an Azure Function) is fine with no issues
- Increasing Guniron's timeout value is not viable as the import_cis_content command takes hours to run. - The timeout setting is relevant when a client request hasn't received a response. The import_cis_content command does not return an HTTP response. Ensuring it does (perhaps when triggered by the Azure Function only) could be the key to this. - The import_cis_content command uses a 'sync worker' but it could be that an 'async worker' is more appropriate. See https://docs.gunicorn.org/en/stable/design.html#choosing-a-worker-type