Usage of variables inside the background task configuration
Referencing environment variables inside the background task configuration is useful when exact configuration value varies from server to server and therefore cannot be single-sourced. Environment variables are resolved at the moment backgroud task service is being initialized with the actual values set on that specific server.
Normally background task gets its parameters from the background task configuration. This way the background task parameters are defined in a single place and can be easily accessed by the task regardless of which server or service executes it.
However, sometimes it is not easy (or even possible) to provide a value that would work on every server. The typical case is the file path, which may differ from one server to another. For example, PUBLICATIONEXPORT event type needs to know the export location, which can be a different folder depending which server picks up the task.
To solve this problem, background task configuration allows referencing environment variables. Environment variable can be provided as a value of any element or attribute.
PUBLICATIONEXPORT references %ISHPROJECTDATAPATH% in the value of exportlocation and exportspeclocation parameters.
<handler eventType="PUBLICATIONEXPORT">
<scheduler executeSynchronously="false" />
<authorization type="authenticationContext" />
<execution timeout="01:00:00" recoveryGracePeriod="00:10:00" isolationLevel="Process" useSingleThreadApartment="true" />
<activator>
<comIEventHandler projectName="IshPluginsIso" className="cout">
<configuration>
<parameters>
<parameter name="exportlocation" type="value">%ISHPROJECTDATAPATH%\ExportService\Data\DataExports</parameter>
<parameter name="exportspeclocation" type="value">%ISHPROJECTDATAPATH%\ExportService\Data\WatchFolder</parameter>
<parameter name="separatelng" type="value">yes</parameter>
<parameter name="requestedmetadata" type="ishfields">
<ishfields>
<ishfield name="FSTATUS" level="lng" />
</ishfields>
</parameter>
<parameter name="raiseevent" type="value">ZIPFILES</parameter>
<parameter name="filenameprefix" type="ishfields">
<ishfields>
<ishfield name="FTITLE" level="logical" />
</ishfields>
</parameter>
</parameters>
</configuration>
</comIEventHandler>
</activator>
<errorHandler maximumRetries="0" />
</handler>
When the background task service is being initialized, every environment variable is replaced with the actual value.
The easy way to set the environment variables for the lifetime of the background task service is to add them to the background task service configuration file. The file is located on the Content Manager server: \Infoshare\App\BackgroundTask\Bin\BackgroundTask.exe.config
Variables are configured in the variables element within the section trisoft.infoShare.backgroundTask. Background task service will read these values during initialization and use them to set the actual environment variables.
Providing the environment variable values for PUBLICATIONEXPORT in the background task service configuration file.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="trisoft.infoShare.backgroundTask" type="Trisoft.InfoShare.BackgroundTask.BackgroundTaskConfigurationSection, Trisoft.InfoShare.BackgroundTask, Version=11.0.0.0, Culture=neutral, PublicKeyToken=555d9fcb450e0935"/>
<!-- Other <section> and <sectionGroup> elements. -->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<trisoft.infoShare.backgroundTask>
<variables>
<!-- Value cannot be an empty string! -->
<add key="ISHPROJECTAPPPATH" value="C:\InfoShare\App" />
<add key="ISHPROJECTDATAPATH" value="C:\InfoShare\Data" />
</variables>
</trisoft.infoShare.backgroundTask>
</configuration>