Initilizing once, upon app start

Signed-off-by: Rahman Mousavian <rahman.mousavian@oracle.com>
This commit is contained in:
Rahman Mousavian 2021-10-26 02:38:41 +11:00
parent 9df59c75cd
commit fb11263c3e
No known key found for this signature in database
GPG Key ID: 642A43DBBC74CCCC
1 changed files with 12 additions and 12 deletions

View File

@ -70,6 +70,18 @@ func init() {
func NewScheduledTask() (Collector, error) {
const subsystem = "scheduled_task"
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
if err != nil {
code := err.(*ole.OleError).Code()
if code != ole.S_OK && code != S_FALSE {
return nil, err
}
}
defer ole.CoUninitialize()
return &ScheduledTaskCollector{
LastResult: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "last_result"),
@ -165,18 +177,6 @@ const SCHEDULED_TASK_PROGRAM_ID = "Schedule.Service.1"
const S_FALSE = 0x00000001
func getScheduledTasks() (scheduledTasks ScheduledTasks, err error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
if err != nil {
code := err.(*ole.OleError).Code()
if code != ole.S_OK && code != S_FALSE {
return scheduledTasks, err
}
}
defer ole.CoUninitialize()
schedClassID, err := ole.ClassIDFrom(SCHEDULED_TASK_PROGRAM_ID)
if err != nil {
return scheduledTasks, err