How can we call an automation script which is normal, from this type of script
[AutomationEntryPoint(AutomationEntryPointType.Types.OnApiTrigger)]
For eg.
/// <param name="requestData"></param>
[AutomationEntryPoint(AutomationEntryPointType.Types.OnApiTrigger)]
public ApiTriggerOutput CreateEventMonitoringService(IEngine engine, ApiTriggerInput requestData)
{
InitializeEngine(engine);
var subScript = _engine.PrepareSubScript("Sky_Refresh_Service_Background_1");
subScript.SelectScriptParam("jsonData", JsonConvert.SerializeObject(requestData));
subScript.Synchronous = false;
subScript.StartScript();
var jsonData = DeserializeRequestData(requestData.RawBody);
var serviceParams = new List<ServiceInfoParams>();
will this code work, like it will send the info to other service
and also, in the script which I am calling , I am adding it in scheduler to call after every one minute wherein I am using this variable
private static Dictionary<string, RequestBody> servicesInfo = new Dictionary<string, RequestBody>();
So, want to know when from scheduler this script will start will it reinitalize this dictionary to 0?
As from API script I am sending the data to this another script which will be called on scheduler after every 1 min
Hi Apurva,
From what I can tell, the code you shared should work in general. I do want to share some tips however:
- I see that the 'ApiTriggerInput' request data is being serialized to JSON so it can be passed to the subscript. I would advice against serializing types that are not under your control. It is safer to first map the data in the input object to an object based on a class that you created. That way, you have full control on the data that is being sent to the subscript and can guarantee that it is actually serializable and will remain so after updates.
- If this API script doesn't need to do anything else than triggering the 'Sky_Refresh_Service_Background_1' script, you could look into adding this 'CreateEventMonitoringService' entrypoint method to that script instead. This way, you don't need to start other scripts and you have access to the code inside that refresh script. It is possible to have a script with multiple entrypoints, one being the normal 'Run' method and one being the 'OnApiTrigger' entrypoint.
On the question with the static field. I believe that the static dictionary will remain initialized and maintain the same data throughout script executions. Do however note that this could lead to memory leaks if the items in the dictionary never get removed. (Either because there is no remove logic, or the flow that should remove an item was interrupted now and then, resulting in the items being stuck forever.)