# Host The automatic variable [\$Host]() is of type [PSHost]() and represents the current host application for PowerShell which in context of powerJobs this can be either the *JobHandler* or your *powershell IDE*. The object also provides access to all the []() that can be used by the Cmdlets [](), []() and [](). ## Syntax ```{code-block} PowerShell :linenos: $Host.Applications['Application Name'] ``` :::{seealso} For the complete list of properties and methods and for more informations see: [PSHost Class](). ::: Following properties are always available : | Type | Name | Description | Access type | | --------------------------------------------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | | String | Name | An identification for the PowerShell hosting application.
Within powerJobs Processor jobs this should be *'powerJobs JobHandler Extension'.* | read-only | | IDictionary)> | Applications | A dictionary of registered applications.
A list of default applications can be found [here](). | read-only | | PSObject | PrivateData | Each Host can provide private data that is editable. For example the property [ErrorBackgroundColor]() that is available in several PowerShell IDEs for changing the background color of error messages.
The powerJobs Processor Host allows extending the way how Vault users are notified about [Terminating Errors]() using the ``OnTerminatingError`` property.| read-write | ## Remarks Same as for the PowerShell IDE even the powerJobs Processor Host displays the written output to the user in a designated [Trace Window]().\ The format of the output provided by the [Write-Host]() cmdlet can be customized within the according [Logging]() sections. In addition to the **Applications** property available on the \$Host variable, the [coolOrange.Applications.psm1]() module provides additionally functions to simplify the access: - `Get-Application` can be used to retrieve an application by name, e.g.: ```{code-block} PowerShell :linenos: $inventor = Get-Application 'Inventor' ``` - `Test-ApplicationInstalled` can be used to check whether the required application is installed on the Job Processor machine: ```powershell if(-not Test-ApplicationInstalled 'Inventor') { throw("Inventor is not installed on this machine!") } ``` ### Automatic Restart PowerJobs Processor handles the starting and stopping of the registered applications due these cases: - timer interval - limit of close documents **Timer interval:**\ Each application has as timer interval, by default this setting is set to **30 minutes**.\ This settings can be changed in the [Setup_job.ps1]() file for a specific application: ```{code-block} PowerShell :linenos: $inventor = Get-Application 'Inventor' $inventor.RestartOptions.Interval = [timespan]::FromSeconds(60) ``` The **timer starts** with the configured interval, when the first [open-document]() call is made.\ When the timer expires and the application is not busy (has no open documents), the application will be restarted immediately. Otherwise the restart for the application will be reserved.\ This means that on the next Open-Document call that uses this application, it will be restarted. Watch out, again: only if the application has no open documents! **Limit of close documents:**\ Each application has a limit of close documents, the default value is set to **10**.\ This settings can be changed in the [Setup_job.ps1]() file for a specific application: ```{code-block} PowerShell :linenos: $inventor = Get-Application 'Inventor' $inventor.RestartOptions.DocumentCloseCounts = 10 ``` Every time a document gets closed this documentCloseCount increments as long as it reaches the configured limit. Then, the restart of this application will be reserved.\ This means on the next []() call that uses this application, it will be restarted. Only if the applications has no open documents! Otherwise the restart remains reserved as long as a restart is allowed. The restarts will be reserved, in order to not restart itself and close the open documents.\ This could cause issues, when opening many documents one after another and the timer expires, or the closeCounter is reached. ### Error Notifications By default the powerJobs Processor host is configured to notify [about failing jobs]() by writing exception details to the Job Queue Result as well as to the Trace Window and logfile. The way how Vault users are notified about [terminating errors]() in job scripts can be extended using the **PrivateData** property and its `OnTerminatingError` property that provides all the relevant error details: ```{code-block} PowerShell :linenos: $global:Host.PrivateData.OnTerminatingError = [System.Delegate]::Combine([Action[System.Management.Automation.RuntimeException]] { param($terminatingError) show-inspector 'terminatingError' }, $global:Host.PrivateData.OnTerminatingError) ```