# Royal Render plugin
#
# Information: RR reads the first comment block to get the settings for this plugin.
#
# These lines are just information lines for you and have no effect.  They are *not* required
# rrPluginName:		Hello Event
# rrPluginAuthor:	Holger Schoenberger
# rrPluginVersion:	1.0
# rrPluginType:		Job Event Plugin
# rrRRversion:		8.2.00
#
#
# Your finished script has to be copied into the folder [RR]\plugins64\server_events\
#
#
# These settings are important for server event plugins and have to be set.
# They tell the rrServer when this plugin should be executed. 
# A "1" activates the plugin for this execution step. Everything beside "1" disables it.
# 
#
#
# ____________________________ ERROR EVENTS TO HANDLE: ____________________________
#
# eCrashed:                       1
# eOutputdirNotFound:   
# eNoFreeSpaceLeft: 
# eFileserverTimeDifference:    
# eNoFrameRendered:             
# eSeqDivAdjusted:              
# eToManyCrashes:               
# eSceneNotFound:               
# eRenderAppNotFound:           
# eExecuteError:
# eClientNoLocalDriveSpaceLeft:
# eUNCMapFailed:
# eNoRenderLicense:
# eClientRenderCrashed:
# eSendToOften:
# eClientLowSysMem:     1
# eClientRenderCrashedPermanently: 
# eClientRenderFroze: 
# eRenderAppWrongVersion: 
# eClientNoRenderTimeIssue:
# eDoublePostExecution: 
# eAbortFrameTime: 
# eClientFoundLogError: 
# eToManyLimitsReached: 
# eCrashedKSOLogError: 
# eOutputdirNotFound_CacheServer: 
#        
#        
# ____________________________ LOG EVENTS TO HANDLE: ____________________________
#      
# lAbortedReservedClients:
# lEnable:                      1
# lDisable:                     1
# lDisableAbort:
# lApprove:
# lDisApprove:
# lDelete:
# lAbort:
# lCheck:
# lReset:
# lResetNDelete:                1
# lChangeClientAssignment:

# lClientRenderSuccessful:
# lClientRenderSuccessfulNoFrames:
# lClientRenderAborted:
# lClientRenderAbortedLowMem:
# lClientRenderAbortedFrozen:
# lClientRenderError:
# lClientRenderAbortedHighCpu:
# lClientRenderAbortedWorkinghours:
# lClientRenderAbortedProcessFound:
# lClientRenderAbortedReservedClient:
# lClientRenderAbortedHighPriorityJob:
# lClientRenderAbortedrrControl:
# lClientRenderAbortedAveraging:
# lClientRenderAbortedLicenseBlock:
# lClientRenderAbortedLocalMachine:
# lClientRenderAbortedDisabled:

# lAutoDeleteAfterDays:
# lFramesDeleted:
# lAllFramesAssigned:
# lSeqDivAdjusted:
# lReceiveJob:
# lChangeSettings:
# lDeleteFinished:
# lDeleteDisabled:
# lClearErrormessages:
# lmarkFinished:
# lDeassignClients:
# lEmitChange:
# lAbortedFrameTime:
# lAbortLowPriority:
# lClientSegmentLessThanXs:
# lClearErrormessagesEnable:
# lFirstCheck:

# lDisableManyCrashes:
# lDisableNoFrames:
# lDisableNoOutputDir:
# lDisableUNCFailed:
# lDisableNoDriveSpace:
# lDisableManyLimitsReached:
# lDisable3TimesMoreSend:

# lClientAssignmentLost:
# lClientAssignmentWrong:
# lClientKSOClose:
# lChangeSettingsSequence:
# lWaitForFinished:
# lAutoDeleteMaxReached:
# lCrashedKSOLogError:
# lSetStatePostRenderScript:
# lSetStateFinishedScript:
# lReassignDeassigned:



#-----------------------------------------------------------------------------------------------

rrGlobal.writeLog2(rrGlobal.logLvL.info,  "*****************************Event Plugin*****************************")

job= rrEvent.getJob()
rrGlobal.writeLog2(rrGlobal.logLvL.info,  "Event Plugin: I am job " +job.sceneName)
    
if (rrEvent.logCount()>0):
    firstLogEvent= rrEvent.logItem(0)
    rrGlobal.writeLog2(rrGlobal.logLvL.info,  "Event Plugin: First Log Message: " +firstLogEvent.logString())
    
rrGlobal.writeLog2(rrGlobal.logLvL.info,  "Event Plugin: All Events of this job that fit this plugin config in the last ~45s: ")
rrGlobal.writeLog2(rrGlobal.logLvL.info,  rrEvent.allEvents())

IDmain= job.IDmain()
IDcomplete= job.m_ID
IDstr= job.IDstr
rrGlobal.writeLog2(rrGlobal.logLvL.info,  "Event Plugin: This job "+str(IDstr)+" "+str(IDcomplete)+" has the main ID: "+str(IDmain))


rrGlobal.writeLog2(rrGlobal.logLvL.info,     "Event Plugin: List all jobs: ")
jobCount = rrEvent.jobAll_count()
jobSiblingList= []
for i in range(jobCount):
    selectedJob = rrEvent.jobAll_get(i)
    rrGlobal.writeLog2(rrGlobal.logLvL.info, "              "+selectedJob.IDstr())
    if (IDmain==selectedJob.IDmain()):
        jobSiblingList.append(selectedJob.ID)
    
rrGlobal.writeLog2(rrGlobal.logLvL.info,  "Event Plugin: Found " +str(len(jobSiblingList))+ " sibling jobs (including this job). Dis-approving these jobs now.")
rrEvent.jobSendCommand(jobSiblingList, rrJob._LogMessage.lDisApprove,0)    
    

rrGlobal.writeLog2(rrGlobal.logLvL.info,    "Event Plugin: List all clients: ")
nrClients= rrEvent.clientAll_count()
for ic in range(0, nrClients):
    loopClient= rrEvent.clientAll_get(ic)
    rrGlobal.writeLog2(rrGlobal.logLvL.info,"              "+loopClient.name()  )
    
rrGlobal.writeLog2(rrGlobal.logLvL.info,  "*****************************")    
    















