Hello,
I am trying to implement a few custom events. A coworker already wrote a script that handled the OnJobSubmitted event. First I decided to write a separate script to handle the OnJobFailed event (for structure reasons). The event was handled just fine, but suddenly errors started showing up in deadline like this:
Event Error (OnJobSubmitted): Object reference not set to an instance of an object.
This was for the event plugin that I wrote, which is weird because in my entire script I never added or touched the OnJobSubmitted event. I wrote an extra eventhandler for OnJobSubmitted wich just passed the event and then I started getting the same error for (for example) the OnJobStarted event.
So when I couldn’t fix that, I decided, because my coworkers script ran just fine and he didn’t add any additional event as well, to add my code to his plugin and make sure that there were now 2 eventhandlers in his code.
The plugin did what it should do, but now errors showed up in deadline for my coworkers plugin for the OnJobStarted, OnJobFinished and OnJobError events. My coworkers script didn’t show this errors before.
Can some one help me? If you need my code for this:
###############################################################
# Imports
###############################################################
from Deadline.Events import *
from Deadline.Scripting import *
import os
import json
import datetime
def GetDeadlineEventListener():
''' Return an instance of the event listener '''
plugin_listener = PluginListener()
return plugin_listener
def CleanupDeadlineEventListener(eventListener):
''' Free items set by Python as they can leak with Python.net '''
eventListener.Cleanup()
class PluginListener(DeadlineEventListener):
def __init__(self):
self.OnJobFailedCallback += self.OnJobFailed
def Cleanup(self):
del self.OnJobFailedCallback
def OnJobFailed(self, job):
current_dir = RepositoryUtils.GetRootDirectory()
path_output_json = os.path.normpath(
os.path.join(current_dir,
'custom/events/Auto-Assign/Failed-Log.json'))
# read data
data_file = None
try:
data_file = open(path_output_json, 'r')
data = json.load(data_file)
except ValueError:
data = []
finally:
if data_file:
data_file.close()
# generate data
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
batch = job.JobBatchName
tags = job.JobExtraInfo8
name = job.JobName
limits = list(job.JobLimitGroups)
print('read attr complete')
new_entry = dict(
Timestamp=timestamp,
Batch=batch,
Tags=tags,
Name=name,
Limits=limits
)
data.append(new_entry)
# write
data_file = open(path_output_json, 'w')
try:
json.dump(data, data_file, indent=4)
finally:
data_file.close()