Deadline API - job deletion

Hi all! I’m pretty new to the deadline API, up to now I never strayed too much further than custom job submissions. But recently I delved a little and I’ve been wondering if it’s possible to, when submitting a job, delete pre-existing jobs. What I would like to achieve is simple on paper: delete any jobs that are pre-existing and belong to the same job batch.

Automated deletion of anything makes me a little queasy, but it would be very useful for us for certain types of job submissions. Does anyone know if this is possible and how best it might be implemented?

Thanks!

This shouldn’t be too tricky:

Whether you want to run this from your submitter or make an Event plugin that catches OnJobSubmitted is just a matter of preference. Personally I’d probably use an event, so the client doesn’t need to wait for the RepositoryUtils query while submitting.

An event would also save you from calling something like deadlinecommand.exe -ExecuteScriptNoGui <your script> (or using standalone/REST api, if that’s your flavor) since you’re already in the Deadline context.

1 Like

Hey Daniel! This is fantastic, thanks for taking the time, much appreciated.
Jan.

Got this working pretty easy thanks to your advice Daniel. For anyone else interested, in the end I implemented this as a script called by deadlinecommand.exe and wrapped it into my submission script.

Script below. Beware, it deletes stuff from your job queue. Use at your own risk.

from Deadline.Scripting import *

def __main__( *args ):

    #use a list to store jobs for deletion
    deleteTheseJobs = []

    #find all jobs currently in the queue that share the same batch name
    jobs = RepositoryUtils.GetJobs(True)
    for job in jobs:
        if job.JobBatchName == args[0]:
            deleteTheseJobs.append(job)    

    #for safety check there's less than 20 jobs to delete
    if len(deleteTheseJobs) < 20:
        for job in deleteTheseJobs:
            print('DELETING: '+job.JobName)
            RepositoryUtils.DeleteJob(job)
    else:
        print('ABORT! FLAGGED '+str(len(deleteTheseJobs))+' JOBS FOR DELETION')

call via deadlinecommand.exe…

def dlClean(batchName):
    args = ['/path/to/deadlinecommand.exe', '-ExecuteScriptNoGui', '/path/to/dlCleanBatch.py', batchName]
    subprocess.call(args)
1 Like

Happy to hear it worked out :slight_smile:

Privacy | Site terms | Cookie preferences