Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
protogrid:agents [2020-04-22 11:50] – [Execution] 178.197.228.105 | protogrid:agents [2021-06-06 22:40] – [Execution] 185.110.184.205 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Agents ====== | ====== Agents ====== | ||
- | |||
Agents run periodically and execute code specified by the user. | Agents run periodically and execute code specified by the user. | ||
Line 6: | Line 5: | ||
===== Setup ===== | ===== Setup ===== | ||
- | |||
To set up an agent, there are two necessary steps: | To set up an agent, there are two necessary steps: | ||
* Under Design -> Code, create an Agent Library and add your code to the // | * Under Design -> Code, create an Agent Library and add your code to the // | ||
- | * Under Design -> Proto, select the Proto you want to use and add corresponding the Agent Library | + | * Under Design -> Proto, select the Proto you want to use and add corresponding the Agent Library |
==== Example ==== | ==== Example ==== | ||
Line 18: | Line 16: | ||
- 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. | ||
- The value in your Text Field should have been replaced by //Frist abgelaufen.// | - The value in your Text Field should have been replaced by //Frist abgelaufen.// | ||
+ | |||
<code javascript> | <code javascript> | ||
function agent_library() { | function agent_library() { | ||
- | var defkey_status_field = "3b47a5fe-894d-4580-bc0c-563aa83d9a02"; // TODO change this value | + | var defkey_status_field = '3b47a5fe-894d-4580-bc0c-563aa83d9a02'; |
+ | var cardkey_parameter_deadline_reached = ' | ||
+ | var defkey_message_deadline_reached = ' | ||
- | function | + | |
- | //sets the value of a single-value field given by field_key | + | // We recommend to use await / async syntax: https:// |
- | | + | // * card [object]: |
- | | + | // * cookie [string]: |
- | card.design_elements[i]['value'] = value; | + | // * axios [object]: |
- | break; | + | // * baseurl [string]: Contains the base url needed for API requests |
- | } | + | // * appname [string]: Contains the application name |
+ | // most URLs needed for API calls are structured like baseurl + ' | ||
+ | // return value: A boolean. If set to true, it will save the current card | ||
+ | async function on_schedule(card, | ||
+ | // Here is an example for an authenticated axios GET request: | ||
+ | | ||
+ | | ||
+ | ' | ||
+ | ' | ||
+ | } | ||
+ | | ||
+ | console.log('axios GET request finished'); | ||
+ | |||
+ | var loaded_card | ||
+ | var loaded_message = loaded_card.get_value(defkey_message_deadline_reached, | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | console.error(e); | ||
+ | return false; | ||
} | } | ||
- | return card; | ||
- | } | ||
- | | ||
- | function on_schedule(card, | ||
- | card = set_value(card, | ||
- | return card; | ||
} | } | ||
- | | + | |
return { | return { | ||
- | set_value: set_value, | ||
on_schedule: | on_schedule: | ||
}; | }; | ||
} | } | ||
+ | |||
</ | </ | ||
===== Execution ====== | ===== Execution ====== | ||
+ | Agents are by default checked every hour (this can be modified for your environment, | ||
+ | |||
+ | 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 // | ||
+ | |||
+ | The // | ||
- | Agents are checked every hour. 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 | + | ===== Best Practices for Calculation Code ====== |
+ | In the following, we have compiled some recommendations based on our experience for high stability, performance, | ||
+ | - It is recommended to use [[protogrid: | ||
+ | - Note: Use multi column indexind views at all only if the free combination of several filters | ||
+ | | ||
+ | - Procedure if the calculation code requires a " | ||
+ | - If editing or deleting a Card in the user interface subsequently to calculation has to be prevented, this can be done in both cases by restricting the editing rights ([[protogrid: | ||
+ | - Read/load as few specific/ | ||
+ | - Analogous to the previous point, write as few specific/single cards as possible. Whenever possible, save several cards together. You can use the Endpoint [[protogrid: |