Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
protogrid:agents [2021-12-13 17:32] – [Agents] druprotogrid:agents [2021-12-13 18:20] – [Example] dru
Line 9: Line 9:
 ==== Example ==== ==== Example ====
   - Create a Proto with a DateTime Field and a Text Field. Copy the key of the Text Field.   - Create a Proto with a DateTime Field and a Text Field. Copy the key of the Text Field.
-  - Create a user profile with rights to edit the proto created above. +  - Create a user profile with rights to edit the proto created above but without Environment Administrator rights
-  - Create an Agent Library, specify the user created above as context user and copy the following code. Replace the value of //defkey_status_field// with the key from above.+  - Create an Agent Library, specify the user created above as context user and copy the following code. Replace the value of //fieldkey_status_field// with the key from above
 +  - Create a Proto for parameter values with a Text Field, copy the key of the Text Field and replace //fieldkey_parameter_value// with that key. Create a parameter Card with this Proto, copy the key of that Card and replace //cardkey_parameter_deadline_reached// with that key.
   - Add this Agent Library to your Proto.   - Add this Agent Library to your Proto.
   - Based on this proto, create some cards where the date lies within the next 60 minutes. Wait one hour.   - Based on this proto, create some cards where the date lies within the next 60 minutes. Wait one hour.
Line 17: Line 18:
 <code javascript> <code javascript>
 function agent_library() { function agent_library() {
-    var defkey_status_field = '3b47a5fe-894d-4580-bc0c-563aa83d9a02';+    var fieldkey_status_field = '3b47a5fe-894d-4580-bc0c-563aa83d9a02';
     var cardkey_parameter_deadline_reached = '9e13a5b0-97d5-405e-9f50-8a2f808cf541';     var cardkey_parameter_deadline_reached = '9e13a5b0-97d5-405e-9f50-8a2f808cf541';
-    var defkey_message_deadline_reached = 'a9a8143f-ad68-4df1-d57b-d8df1569c83b';+    var fieldkey_parameter_value = 'a9a8143f-ad68-4df1-d57b-d8df1569c83b';
  
     // Make sure that this function does not return until all operations and JSON-API requests are completed / fulfilled.     // Make sure that this function does not return until all operations and JSON-API requests are completed / fulfilled.
Line 41: Line 42:
  
             var loaded_card = monkey_patch_card(data.result);             var loaded_card = monkey_patch_card(data.result);
-            var loaded_message = loaded_card.get_value(defkey_message_deadline_reached, 'Frist abgelaufen'); +            var loaded_message = loaded_card.get_value(fieldkey_parameter_value, 'Frist abgelaufen'); 
-            card.set_element_value(defkey_status_field, loaded_message);+            card.set_element_value(fieldkey_status_field, loaded_message);
  
             return true;             return true;
Line 59: Line 60:
  
 ===== Execution ====== ===== Execution ======
-Agents are by default checked every hour (this can be modified for your environment, please contact the Protogrid Operations Team). If any DateTime Field on a card has a smaller value than the current time and the Agent has not yet run since that time, the Agent gets triggered and the code in the Agent Library is executed in the context of this card (for Date-Only Fields, the time taken into account is said date, 00:00 GMT). Agents run in the context of a specific user profile. This user's password is automatically reset during the execution process. So this user profile shall only be used for agents and not for physical users. All agent executions are logged in the //agent_log// on the respective card.+Agents are by default checked every hour (this can be modified for your environment, please contact the Protogrid Operations Team). If any DateTime Field on a card has a smaller value than the current time and the Agent has not yet run since that time, the Agent gets triggered and the code in the Agent Library is executed in the context of this card. For Date-Only Fields, the time taken into account is determined by the value of 'Time Offset Value for Periodic Agents' in the Environment Properties (defaults to 03:00 GMT). 
 + 
 +Agents run in the context of a specific user profile which must not have Environment Administrator rights. This user's password is automatically reset during the execution process. So this user profile shall only be used for agents and not for physical users. All agent executions are logged in the //agent_log// on the respective card.
  
 While an agent is running in the context of a specific card, it is also possible to load and save other cards by calling the JSON API endpoints using axios. A valid axios module is given in the //on_schedule// function. Agents have a global runtime limit (usually one hour). If you want to restrict this limit for certain agents, you can do so by entering the desired maximum runtime (in milliseconds) in the Agent card. After reaching the runtime limit, the code will terminate instantly and the next card will be processed. The process will not be started if the time until the next agent check is less than the maximum runtime. While an agent is running in the context of a specific card, it is also possible to load and save other cards by calling the JSON API endpoints using axios. A valid axios module is given in the //on_schedule// function. Agents have a global runtime limit (usually one hour). If you want to restrict this limit for certain agents, you can do so by entering the desired maximum runtime (in milliseconds) in the Agent card. After reaching the runtime limit, the code will terminate instantly and the next card will be processed. The process will not be started if the time until the next agent check is less than the maximum runtime.
Print/export