Scripting Guidelines
Scripting Guidelines
Activate Scripts can be written in C#, VB.NET or Powershell. This article outlines general guidelines for the implementation of Scripts to run in an Activate environment.
Execution Times
The Activate Job engine executes Activate workflows and executes the Activate scripts as part of this workflow. The Job engine executes a limited number of processes at any one time. This is generally Number of CPU * 8 processes. This means on a single CPU machine 8 jobs can be executed at any once time. However, as a means of limited a specific task from taking over the server, only 50% of the available threads can be running a Task at any one time
Activate scripts are generally intended to run in a 'short' period of time. Scripts that take a long period of time can prevent over processes from running. In general, avoid Thread.Sleep() functions and blocking in the script as much as possible. Instead Activate Scripts should use the Activate Job Retry functionality.
Best Practices
- Scripts should generaly take less than 1 minute.
- Longer running scripts may cause performance issues.
- Use JobWorkFlow.Result.Retry for things that need to retry
Logging
Most Activate scripts execute in the context of a Job. All Job.LogXXX functions log output to the Activate database. Each Log Entry as a Message and Detail associated with it.
The following functions are available:-
- Job.LogTrace(message, details) - This will log trace entries to the database. These will be deleted automatically after 90 days.
- Job.LogAudit(message, details) - This will log an audit entry that is permanent. These are never deleted.
- Job.LogError(message, details) - This will log an error log entry. This can be used to log an error but still continue the script.
Best Practices
- Limit Log entries in production databases.
- Large amount of logging is expensive on performance and disk space in the SQL Database.
- Use LogTrace for temporary logging
- Remove debug logging in Production scripts
Exception Handling
Activate uses .NET exceptions to detect errors in scripts. Catching and logging the error in the script will prevent the job from failing. This is sometimes desired but must be used carefully.