Application
Définit une classe de base abstraite (ABC) pour représenter une Application exécutable et une énumération Status pour suivre l’état actuel d’une Application.
L’énumération Status contient les différents statuts qu’une application peut avoir, tels que RUNNING, WAITING, ERROR, et SUCCESS.
La classe Application est une classe de base abstraite (ne peut pas être instanciée directement). Elle fournit un modèle pour créer d’autres classes qui sont considérées comme des Applications, ce qui signifie qu’elles doivent implémenter les méthodes spécifiées dans cette classe abstraite. Cette classe met en place la journalisation et initialise diverses propriétés telles que les APIs, la fréquence d’exécution, et le statut.
La méthode api() récupère une instance API à partir de la liste privée _apis en fonction de son nom de classe.
La méthode run() est utilisée pour exécuter l’application. Elle définit le statut comme RUNNING et essaie ensuite d’appeler la méthode abstraite job(). Si une exception se produit pendant ce processus, elle enregistre l’erreur et définit le statut comme ERROR. Si le mode de débogage est activé, elle relève à nouveau l’exception.
La méthode shutdown() est un espace réservé qui peut être remplacé par des implémentations de sous-classe si l’Application a besoin de libérer des ressources ou d’effectuer des actions de nettoyage lorsqu’elle est arrêtée. Si elle n’est pas remplacée, elle ne fait rien.
Ce script utilise également les bibliothèques schedule et logging pour la planification des tâches et la création de journaux d’application, respectivement.
This module contains the Application Interface of the core module. All applications must implement this interface if they want to be run by the runner.
- class application.Application
Bases :
ABCApplication Interface of the core module. All applications must implement this interface if they want to be run by the runner.
An application can use one or more APIs to work. The APIs are stored in a list. The frequency of the application is stored in a schedule.Job.
The job method is the method that is called by the runner. It must be implemented by the application. This method must contain all the work of the application.
- Variables:
_apis – The list of APIs used by the application.
frequency – The frequency of the application.
- See:
- See:
schedule.Job
- _abc_impl = <_abc_data object>
- api(name)
This method returns the API with the given name.
- Paramètres:
name – The name of the API.
- Renvoie:
The API object corresponding to the given name.
- Lève:
ValueError – If the API with the given name does not exist.
- property debug: bool
This property returns the debug mode of the application.
- Renvoie:
The debug mode of the application as a boolean value.
- property health_check
This property returns the health check of the application.
- Renvoie:
The health check of the application
- Type renvoyé:
- Raises:
None
- abstract job() Status
The runner calls this method. It must contain all the work of the application. It must update the status of the application (RUNNING, ERROR, SUCCESS).
- Renvoie:
None
- run()
The runner calls this method. It loads the APIs, sets the frequency and schedules the job.
This method must not be overridden. :return: None
- set_status(value: Status)
This method sets the status of the application.
- Paramètres:
value – The status value to be set.
Must be of type Status. :return: None
- shutdown()
The runner calls this method when the application is stopped. It must stop all the work of the application.
- Renvoie:
None