User bio
404 bio not found
Member since Dec 7, 2016
Replies:

Yes, it's possible. For this you need to create class of the task. I used it to create server-monitoring sheduled task, that send me eamil. For example, i have class, that contains parameters of futured monitoring tasks (like task-name, period, timestart, timefinish, activity, description and so on), and contain method to create task:

Method generateTask(ByRef out)
{
#define crlf $c(13,10)
#define quote $C(34)
err = ""
try {
className = ..#taskPath_"."_##this.Name
##class(%ClassDefinition).%ExistsId(className){
ObjClass = ##class(%Dictionary.ClassDefinition).%OpenId(className) ; Если такая задача есть - открываем и чистим
ObjClass.Parameters.Clear(),ObjClass.Properties.Clear(),ObjClass.Methods.Clear()
}
else {
ObjClass = ##class(%Dictionary.ClassDefinition).%New(className) ; иначе создаем новую
}
ObjClass.Super = "%SYS.Task.Definition"   Param = ##class(%Dictionary.ParameterDefinition).%New(ObjClass.Name_":TaskName") ; Параметр: имя задачи
Param.Default = ##this.Name
Param.Description = "Имя задачи"
ObjClass.Parameters.Insert(Param) Prop = ##class(%Dictionary.PropertyDefinition).%New(ObjClass.Name_":Active") ; Свойство: активность
Prop.Type ="%Boolean"
Prop.Description = "Флаг активности задачи"
Prop.Required = 1
ObjClass.Properties.Insert(Prop) Prop = ##class(%Dictionary.PropertyDefinition).%New(ObjClass.Name_":Email") ; Свойство: Почтовые адреса для рассылки
Prop.Type = "%String"
Prop.Description = "Почтовые адреса для рассылки"
Prop.Parameters.SetAt(200,"MAXLEN")
ObjClass.Properties.Insert(Prop)
 
  Prop = ##class(%Dictionary.PropertyDefinition).%New(ObjClass.Name_":MethodName") ; Свойство: Метод для запуска
Prop.Type = "%String"
Prop.Description = "Метод Cache из класса для запуска"
ObjClass.Properties.Insert(Prop) Prop = ##class(%Dictionary.PropertyDefinition).%New(ObjClass.Name_":ClassName") ; Свойство: Класс Cache с методом для запуска
Prop.Type = "%String"
Prop.Description = "Класс Cache с методом для запуска"
ObjClass.Properties.Insert(Prop) Prop = ##class(%Dictionary.PropertyDefinition).%New(ObjClass.Name_":Params") ; Свойство: Параметры запускаемого метода
Prop.Type = "%String"
Prop.Description = "Параметры запускаемого метода"
ObjClass.Properties.Insert(Prop) method = ##class(%Dictionary.MethodDefinition).%New(className_":OnTask") ; Метод. Основной метод задачи
method.Name = "OnTask"
method.ReturnType = "%Status"
code = ##class(%Stream.TmpCharacter).%New()
code.Rewind()
code.Write(" #define quote $C(34)"_$$$crlf)
code.Write(" q:'..Active $$$OK"_$$$crlf)
code.Write(" s st=$$$OK"_$$$crlf)
code.Write(" try {"_$$$crlf)
code.Write(" s err="""""_$$$crlf)
code.Write(" s msg="""""_$$$crlf)
code.Write(" ;формирование параметров выполнения метода:_____"_$$$crlf)
code.Write(" s jstring=""{"""_$$$crlf)
code.Write(" for i=1:1:$l(..Params,""~"") {"_$$$crlf)
code.Write(" s buf=$p(..Params,""~"",i)"_$$$crlf)
code.Write(" i i<$l(..Params,""~""){"_$$$crlf)
code.Write(" s:buf'="""" jstring=jstring_$$$quote_($p(buf,""="",1))_$$$quote_"":""_$p(buf,""="",2)_"","" "_$$$crlf)
code.Write(" }else{"_$$$crlf)
code.Write(" s:buf'="""" jstring=jstring_$$$quote_($p(buf,""="",1))_$$$quote_"":""_$p(buf,""="",2)"_$$$crlf)
code.Write(" }"_$$$crlf)
code.Write(" }"_$$$crlf)
code.Write(" s jstring=jstring_""}"""_$$$crlf)
code.Write(" s in={}.%FromJSON(jstring)"_$$$crlf)
code.Write(" s out={""error"":"""",""message"":"""",""subject"":""""}"_$$$crlf)
code.Write(" d $CLASSMETHOD(..ClassName,..MethodName,.in,.out)"_$$$crlf)
code.Write(" ;отправка письма:________________________________"_$$$crlf)
code.Write(" i ..Email'="""" {"_$$$crlf)
code.Write(" s mailIn={}"_$$$crlf)
code.Write(" s mailIn.subject= """""_$$$crlf)
code.Write(" s mailIn.to = ..Email"_$$$crlf)
code.Write(" s mailIn.message= ""<h3>Статус выполнения задачи по расписанию ""_..#TaskName_"" : ""_$Case(out.error,"""":""Выполнено"",$$$OK:""Выполнено"",:""Выполнено с ошибками"")_"" </h3>"""_$$$crlf)
code.Write(" s:(out.message'="""") mailIn.message=mailIn.message_""Результат: </br>""_out.message"_$$$crlf)
code.Write(" s mailIn.message= mailIn.message_""Класс: ""_..ClassName_"", метод: ""_..MethodName_""</br>"""_$$$crlf)
code.Write(" s:((out.error'="""")&(out.error'=$$$OK)) mailIn.message=mailIn.message_""Ошибка: ""_out.error_""</br>"""_$$$crlf)
code.Write(" s:(out.subject'="""") mailIn.subject=out.subject"_$$$crlf)
code.Write(" s:(out.from'="""") mailIn.from=out.from"_$$$crlf)
code.Write(" s mailIn.isHTML = 1"_$$$crlf)
code.Write(" s mailIn.attach = """""_$$$crlf)
code.Write(" d ##class(Lib.Util.Email).Send(.mailIn,.out)"_$$$crlf)
code.Write(" }"_$$$crlf)
code.Write(" } // try"_$$$crlf)
code.Write(" catch {s err=$ze}"_$$$crlf)
code.Write(" if err'="""" {s st=$$$ERROR($$$GeneralError,err)}"_$$$crlf)
code.Write(" q st"_$$$crlf)
method.Implementation=code
ObjClass.Methods.Insert(method) ObjClass.%Save() status = $system.OBJ.Compile(className,"UBR-D",.errlog,1)
s:$System.Status.IsError(status) err=$SYSTEM.Status.GetErrorText(status)
}
catch exp {
err = ..ErrorDetect(.exp)
}
out.error = err
q
}
Open Exchange applications:
Certifications & Credly badges:
Aleksandr has no Certifications & Credly badges yet.
Global Masters badges:
Followers:
Aleksandr has no followers yet.
Following:
Aleksandr has not followed anybody yet.