Tasks to production
Hi guys,
Would like to replace our scheduled Tasks to instead run in a production, so basically the same code running in OnTask () to be instead called in a Business Service (I guess) and use the Interval filed to specify the iteration, so with adapter would be suitable in this case, and I noticed the Schedule filed as well but not sure how to use it?
.png)
Thanks
Comments
In these cases I use Ens.InboudAdapter with a very high call interval so it runs only once when the BS is enabled (START action in schedule definition)
And under which class is it available, Or do I have to create my own class that Extends Ens.BusinessService and copy my code from task scheduler under OnProcessInput? and in this case I won't be needing pInput & pOutput.
Method OnProcessInput(pInput As %CharacterStream, Output pOutput As %CharacterStream) As %Status
.png)
Yes, you need to create your own class that Extends Ens.BusinessService that use Ens.InboundAdapter and and copy or call my code from OnProcessInput() method.
You can ignore pInput & pOutput arguments.
Thanks
To give an example of where I have done something similar:
I have a Service that will check if the active mirror has changed since the last poll, and will trigger a message to the "Ens.Alert" component in the production if it has changed.
To do this, I have a service with the following code:
Class Demo.Monitoring.SystemMonitor Extends Ens.BusinessService
{
Method OnProcessInput(pInput As%RegisteredObject, Output pOutput As%RegisteredObject, ByRef pHint As%String) As%Status
{
Set tsc = ..CheckMirroring()
Quit tsc
}
Method CheckMirroring() As%Status
{
Set triggered = 0//Get the current serverSet CurrServer = $PIECE($SYSTEM,":")
/**Check Global exists, and create it if it does not.(Should really only ever happen once on deployment, but this is a failsafe)**/Set GBLCHK = $DATA(^$GLOBAL("^zMirrorName"))
If GBLCHK = 0{
Set^zMirrorName = CurrServer
Quit$$$OK//No need to evaluate on first run
}
If^zMirrorName = CurrServer {
/*Do not Alert*/Quit$$$OK
}
Else {
/*Alert*/Set AlertMessage = "The currently active server has changed since the last check, suggesting a mirror fail over."Set AlertMessage = AlertMessage_" The previous server was "_^zMirrorName_" and the current server is "_CurrServer_"."Set^zMirrorName = CurrServer
Set req=##class(Ens.AlertRequest).%New()
Set req.SourceConfigName = "System Monitor"Set req.AlertText = AlertMessage
Set req.AlertTime = $ZDATETIME($HOROLOG,3)_".000"Set tSC = ..SendRequestSync("Ens.Alert", req)
Quit tSC
}
}
}Then, from within my production, I then have the service that is using this class configured with "CallInterval" set to the desired frequency of running:
.png)
Thanks Julian👍
BTW, if I'm implementing my own class that extends Ens.BusinessService what's the use of the InboudAdapter, because the code will execute regardless?
.png)