- This topic has 10 replies, 2 voices, and was last updated 3 years, 5 months ago by
Leonardo Bernardini.
-
Posted in: Api usage
-
27th April 2022 at 2:42 pm #34492
Hi,
I am currently trying to modify a template to completely abort a render when a specific error is detected. I used onCheckLogLine function to return a MTemplateError with a kTemplateErrorAbortRender action and it works pretty well. Unfortunately it only abort current chunk and I would like to cancel the whole job. What is the best way to do it ? I’ve tried to send a pause job action using MClientAPI.JobActionPause(session, job.getJobId()) or job.setPaused(True) before returning the abort action, but it does not seem to do anything (for both methods).
Here is the code for the function I used (inside template) :
def onCheckLogLine(self, job, chunk, clientTemplatePreferences, line, lineNum, warnings, errors, silencedWarnings, silencedErrors):
if line.find(“PROC ERR”) != -1:
session = MClientAPI.InitializeSession()
MClientAPI.JobActionPause(session, job.getJobId())
# abort render when detecting PROC ERROR in log
error = MTemplateAPI.MTemplateError(1, “ABORT RENDER”, MTemplateAPI.MTemplateError.kTemplateErrorTypeError)
error.addErrorAction(MTemplateAPI.MTemplateError.kTemplateErrorAbortRender)
return error
return MTemplateAPI.MTemplateError()Any help on how to do this would be appreciated.
Regards
Romain from TNZPV28th April 2022 at 3:20 pm #34494well you’re mixing contexts , the MClientAPI is not available during a call of the MTemplateAPI, the onCheckLogLine is called in the render client context, and the API available there is the MInstanceAPI. So what you can actually do is to use the MInstanceAPI to send a message to the Dispatcher :
MInstanceAPI.sendMessage(0,0,”ABORTJOB: YOURJOBID”);
Be aware that you can target a specific template so instance of using 0,0 you should use something like 0,num , where num is the ID of the template you’re changing.
In the same template, implement the handling on the Dispatcher side of the message:
def onCustomNodeMessage(self,nodeId,message):
print(“Got message: “+message)There you need to grab out the job id and the message, and then at this point, switch context again and use the MDispatcherAPI to pause the job:
err, job = MDispatcherAPI.jobGet(2)
job.setPaused(true)
MDispatcherAPI.jobUpdate(2)The last command updates the job attributes across all the console.
You should have all the points to solve your question 😉
29th April 2022 at 10:30 am #34495Hi Leonardo,
Thank you for your answer. Your explanations were pretty clear, but unfortunately, I didn’t manage to make it work. Maybe there is something I misundertood.
In my onCheckLogLine function, I called MInstanceAPI.sendMessage(0, self.getID(), “ABORTJOB: {}”.format(job.getJobId()))
Then I declared in my template a function onCustomNodeMessage, containing the following lines :print(“Dispatcher received a custom message from node ID ” + str(nodeId) + “:” + message)
job_id = message.split(‘: ‘)[-1]
err, job = MDispatcherAPI.jobGet(job_id)
job.setPaused(True)
MDispatcherAPI.jobUpdate(job_id)It did not pause the job, and I haven’t found the print message in instance log (and chunk log seems to be empty when render is aborted). Did I miss something or the function onCustomNodeMessage have not been called ? Muster isn’t very talkative. Is there a place where script error in template are send ?
Regards
2nd May 2022 at 8:33 am #34500to better debug Python, please use an evaluation version of Muster and start them as console application.
Then go into the Logs section of both the renderclient and Dispatcher, and set python output to stdout/stderr so you can watch your print statements4th May 2022 at 3:27 pm #34501Hello Leonardo,
Thanks for your answer. I tried to redirect python logs to job logs using Logs section of both the renderclient and Dispatcher, but unfortunately it did not appears in chunks logs (I didn’t used evaluation version because the error I want to detect is linked to a lot of pipe-related stuff).
Regards
4th May 2022 at 4:53 pm #34502no it won’t appear in the log. You should start the dispatcher and at least one renderclient as CONSOLE APPLICATION, otherwise there’s another option to have the output into the log, but it’s not flushed realtime and it’s somewhat nasty to handle.
5th May 2022 at 12:15 pm #34503Alright, I managed to have the template python log as you explained, thanks. It looks like the onCustomNodeMessage function is not called, but I don’t know why. I tried to call it using the following line :
MInstanceAPI.sendMessage(0, self.getID(), “ABORTJOB: {}”.format(job.getJobId()))
I also tried to use MInstanceAPI.sendMessage(instance_id, self.getID(), “ABORTJOB: {}”.format(job.getJobId())), with instance_id being the id of the client rendering the chunk, but it did not work either. But the kTemplateErrorAbortRender action send just after the send message is correctly evaluated. Did it prevent the onCustomNodeMessage being evaluated as well ?
Here is the whole code :
`def onCustomNodeMessage(self, nodeId, message):
print(“Dispatcher received a custom message from node ID ” + str(nodeId) + “:” + message)
import MDispatcherAPI
job_id = message.split(‘: ‘)[-1]err, job = MDispatcherAPI.jobGet(job_id)
job.setPaused(True)
MDispatcherAPI.jobUpdate(job_id)def onCheckLogLine(self, job, chunk, clientTemplatePreferences, line, lineNum, warnings, errors, silencedWarnings, silencedErrors):
if line.find(“PROC ERR”) != -1:
import MInstanceAPI
MInstanceAPI.sendMessage(0, self.getID(), “ABORTJOB: {}”.format(job.getJobId()))# abort render when detecting PROC ERROR in log
error = MTemplateAPI.MTemplateError(1, “ABORT RENDER”, MTemplateAPI.MTemplateError.kTemplateErrorTypeError)
error.addErrorAction(MTemplateAPI.MTemplateError.kTemplateErrorAbortRender)
return error
return MTemplateAPI.MTemplateError()`
5th May 2022 at 2:54 pm #34504try to send to 0,0 and get it into the global template 0
6th May 2022 at 1:10 pm #34506I tried to move onCustomNodeMessage function into Global template 0 and to send 0,0 with sendMessage but it didn’t work either.
6th May 2022 at 1:34 pm #34507Oh ! I figured it out ! The line job_id = message.split(‘: ‘)[-1] was returning a string, but jobGet was looking for an integer, and I wasn’t looking at the proper place to find dispatcher-side error, so I hadn’t saw the real issue. It works like a charm, now. Thank you for your help !
-
You must be logged in to reply to this topic.