Question
· Aug 1

Task running but not executing the code

Hi guys,

Stange problem that I'm facing, when running the below code is inside system task scheduled to run every 5 mins it execute till check("gg")=3, stops at While Rs.Next() and you might thing that's because there no records but yest there records because If I run the same task from the terminal it run fine and process all records, also if I copy the whole code into a classMethod and run the classmethod from the terminal it run fine as well, its only if it runs through the scheduling process or by click run in SMP that runs till check point 3 and doesn't go any further !?   

^check("gg",0)=1_"|"_$J_"|"_$ZU(61)_"|"_$zt($P($h,",",2))
$$$DebugLog("GetJobs","getJobs start onTask "_$G(^STOPGNJ, 0),"")
Quit:$G(^STOPGNJ, 0) $$$OK
Set ^STOPGNJ=1
^check("gg")=1
try{
Set SQL = "Select top 1000 tl.ID,tl.SensorId,tl.SensorType, tl.Loc as Loc from "_
" MSDS_Common.ScheduleTaskList tl"_
" left join MSDS_Common.ScheduleTaskListHistory th on th.ScheduleTask = tl.ID"_
" where %Internal(tl.ScheduledTask)='O' and %Internal(tl.Status)='A' and (%Internal(tl.State)='S' or %Internal(tl.State)='Q')"_
" group by tl.id "_
" order by tl.id desc"

^check("gg2018")=SQL
^check("gg")=2

Set Rs=##class(%ResultSet).%New()
Do Rs.Prepare(SQL)
Do Rs.Execute()
^check("gg")=3
While Rs.Next(){
^check("gg")=4
Set ID=Rs.Get("ID")
Set SensorTag=Rs.Get("SensorId")
Set SensorType=Rs.Get("SensorType")
  Continue:$G(ID,"")="" Continue:$ZCVT(SensorType,"U")="TPROBE" Continue:$G(^StoreJob(ID),"")'="" //Continue:TryCount>=5 //&SQL(SELECT count(*) Set ^StoreJob(ID)=SensorTag_"||"_$zdt($zts,3)
}
}
Catch
{
$$$DebugLog("PushNQL","Exception happened in getjobs task: "_$ZERROR,"")
Stream=##class(%GlobalCharacterStream).%New()
Stream.WriteLine("Something went wrong, error in Get_New_Jobs task, Please have a look.")
Stream.WriteLine("Error Message : "_$ZERROR)
Stream.WriteLine("Error Code : "_$ECODE)
Stream.WriteLine("")
Stream.WriteLine("Thanks,")
Stream.WriteLine("SX3 Support")
MailStatus=##class(SX3.Production.HTTP.GetRequest).SendErrorMail(Stream)
Set ^STOPGNJ=0 } Set ^STOPGNJ=0
 

Thanks

Product version: Ensemble 2018.1
Discussion (5)2
Log in or sign up to continue

Glad you got an answer to your main question. To answer your other question about how to check a status, the Execute and Prepare methods of the %ResultSet class return a %Status. Where you have do Rs.Prepare(SQL) and do Rs.Execute(), you could use:

set sc = Rs.Prepare(SQL)
if $$$ISERR(sc) {$$$ThrowStatus(sc)}
set sc = Rs.Execute()
if $$$ISERR(sc) {$$$ThrowStatus(sc)}

Then if there was an error doing either of those things, it would get passed off to your catch block. In your case, there would've been an error indicating your permissions issue.