Starting Situation
- Jobs might want to add events.
- A number of events might be available with JobScheduler and should be removed.
Use Cases
Add events from a job
The PowerShell CLI can be used by jobs to submit events. Usually separate job steps or monitor scripts are used as e.g. with
- the JITL job JobSchedulerSubmitEventJob
- the JITL monitor JobSchedulerSubmitEventMonitor
Instead of additional job steps or monitor scripts the Add-JobSchedulerEvent
cmdlet can be used to create events directly within a job:
<?xml version="1.0" encoding="ISO-8859-1"?> <job order="yes" stop_on_error="no"> <script language="powershell"> <![CDATA[ Import-Module JobScheduler Add-JobSchedulerEvent -EventClass $spooler_task.order().job_chain().name() -EventId "started_$($spooler_job.name())" echo "job: $($spooler_job.name())" Add-JobSchedulerEvent -EventClass $spooler_task.order().job_chain().name() -EventId "completed_$($spooler_job.name())" ]]> </script> <run_time /> </job>
Explanations
- The job creates two events that signal start and completion of the job.
- A common event class is used that is assigned the path of the job chain
- Individual event ids are assigned that are created from the job name
- All communication with the JobScheduler Supervisor or Master takes place by internal commands, no additional HTTP/HTTPS connection is used.
Manage events from the command line
The PowerShell CLI can be used to create, retrieve and remove events
# add an arbitrary event $event = Add-JobSchedulerEvent -EventClass daily_closing -EventId 12345678 # wait for the event service to process the request Start-Sleep -Seconds 3 # check the list of events $events = Get-JobSchedulerEvent $events # remove the newly created event $event | Remove-JobSchedulerEvent # think twice before removing all events Get-JobSchedulerEvent | Remove-JobSchedulerEvent
Explantions
- The
Add-JobSchedulerEvent
cmdlet returns an event object that can be used for later pipelining - Event processing occurs asynchroneously, therefore newly created events might take some seconds to be available for retrieval..
- The
Get-JobSchedulerEvent
cmdlet retrieves an array of event objects that are available with JobScheduler. - A previously created event object can be pipelined to the
Remove-JobSchedulerEvent
cmdlet. - In a more general sense all events as returned from
Get-JobSchedulerEvent
can be pipelined to theRemove-JobSchedulerEvent
cmdlet.