Good practices for developing custom software in Athento

Tabla de contenidos

IMPORTANT: Most of the good practices recommended for developing on Athento are standard software engineering practices. Having staff trained in this discipline is essential to build and maintain quality custom code.

IMPORTANT: Athento reserves the right to remove from the platform any custom code that does not meet minimum quality, efficiency and security criteria. In that case, Athento will first report the required improvements or fixes and will grant a period of 60 calendar days to make them before disabling that code.

General good practices

  1. Use resources optimally, as in any information system. For example:
    • Design forms with a reasonable number of fields. Having more than 200 fields is usually considered an anomaly in a form. For more information, see: What is the maximum number of fields allowed in a document in Athento? (in Spanish)
    • When you configure a choice field, define the list of values as a Dictionary instead of setting the options directly in the field.
    • More than 1,000 items per queue is not considered good design. For more details, see: Queues (in Spanish).
    • Standardize the names of spaces, forms and fields so they can be reused without affecting previous configurations.
  2. Use descriptive names for operations, so users can easily tell what each one does.
  3. As a reference, operations should take less than 3 seconds to run.
  4. Keep in mind that extraction operations depend on the number of pages of the document they run on, so times may vary.
  5. Write performance-efficient code. Therefore, make sure:
    • The database queries made by the custom code are optimal.
    • The code has complexity orders close to constant order.
    • The same criterion is applied to memory consumption.
  6. Writing unit tests for operations helps ensure the quality of custom code.

Good practices for the development cycle

The development cycle of custom software for Athento usually includes GIT repositories and development done from a local environment or from a server dedicated to development.

As good practices, we recommend:

  • Do not develop directly in production environments.
  • Do not make changes directly in production environments (except hotfixes).
  • Keep the code in a version control system (GIT).
  • Restrict code deployment to qualified staff only.

Good practices for source code

  1. Apply PEP8.
  2. As a reference, each operation should not take more than 5 seconds to run. This threshold must be assessed in context. For example, if the operation will run on thousands of documents per hour, it should take less time.
  3. Functions or methods should not exceed 30 lines.
  4. Handle exceptions in operations.
  5. For bulk updates, use Django’s “bulk update” option. https://docs.djangoproject.com/en/4.1/ref/models/querysets/#bulk-update
  6. Do not use str on an object to then compare the result with an object name or similar. The str implementation may change at any time. Compare the value of the relevant attribute instead.

Good practices for creating operations

  1. During testing, using logs makes debugging easier.
  2. Make sure the execution time is below 10 seconds, ideally below 5 seconds.

Good practices for creating commands

  1. If the command iterates over a list of documents, do it in a defined order (for example, by id).
  2. If a large volume of items will be processed, paginate the result.
  3. Include parameters to set start and end items. This allows running the command in parallel for given sets of items.
  4. Use the CronExecution entity to keep traceability of the command execution.
  5. Include a –test_uuid parameter to run the command on a specific document.
  6. To join two querysets with many results (thousands), flatten the results by getting the ids of the items, operate on those ids with set and list entities, and get the results from the resulting ids.
  7. Avoid generating reports with information that has not changed. We recommend reporting what changed during the day and working on it in a BI system. Avoid commands that export “the whole year” or “the whole month”.
  8. For report generation, export the most recent information.
  9. Exporting reports every 30 minutes with volumes of around 50,000 records and 180 days of history is not recommended.
    • For exports every 30 minutes or every hour, the history limit should be 1 day and a maximum of 1,000 records.
    • To export 50,000 records with 180 days of history, the export must be scheduled in a window that does not affect operations (for example, overnight) and only once a day.
  10. In any case, Athento recommends analyzing the data in a dedicated BI tool.
  11. Keep the code clean: do not leave unnecessary “print” statements in production, do not leave “set_feature” calls used for debugging, etc.
  12. When commands handle a large volume of items, run them at times that do not affect users’ work (for example, outside working hours or at the end of the day).
  13. If the command must act on thousands of items, during testing run it first on a small set (dozens of documents) to validate the result. You can limit the number of items with a slice or by filtering items created in the last few hours.

Good practices for using parameters

Athento offers several levels for parameterizing the configuration:

  1. Operations accept parameters.
  2. Commands accept parameters, which can be included when configuring them from advanced administration in “Crontab Config”.
  3. From advanced administration, you can create parameters in the “Config property”, “Config secret property” and “Config file property” tables.
  4. From advanced administration, you can change some parameters in “Config settings”.
  5. At server level, you can use the local_settings.py file.

Good practices for lifecycles

It is normal for processes to evolve and, with them, to need to adjust or change lifecycles, for example. Athento recommends:

  1. Check that states and transitions contain only alphanumeric characters. + info (in Spanish)
  2. Standardize the names of lifecycle states and transitions so they can be reused without affecting previous configurations.
  3. If you are going to migrate a lifecycle, do not delete the original states until the migration of the documents’ states has been completed.
  4. For data integrity, if a lifecycle state is “removed”, the corresponding mapping or migration must be carried out so that documents created before the change keep an assigned lifecycle state.

Good practices for UAT environments

UAT environments are used for testing. Therefore, we recommend the following:

  1. These environments usually have more limited resources. For that reason, do not load UAT environments with millions of documents or heavy configurations (thousands of fields in forms, thousands of items in queues, hundreds of automations, etc.).
  2. For security reasons, do not use real data in UAT environments.
  3. Backups are usually not guaranteed in UAT environments. Do not store data that requires a backup.

Variable abbreviations

In some cases, it can be useful to define abbreviations for frequently used variables. The abbreviations recommended by Athento are:

fil or doc # For a variable holding a File instance
mt or mtd # For a variable holding a Metadata instance
mtt # For a variable holding a MetadataType instance
dt # For a variable holding a DocumentType instance
s # For a variable holding a Serie instance

You may be interested in How to deploy custom code on a dedicated instance? (in Spanish)