AWS Thinkbox Discussion Forums

Script to set a job as Pending if a dependecy is not Complete

Hi guys;
I’m writing a script to check if a parent job is 100% complete, and if not complete put it on “Pending state”.

I need two input data, the current job id and the dependency id.

Current job id, can be retrieved with:
def main( deadlinePlugin ):
task_id = deadlinePlugin.GetCurrentTaskId()

But, how can I get the dependencie(s) already set in the job?

Can anynone help me?

Thanks!

I must be missing something here, because what you’re describing sounds like the default dependency behavior to me.

Could you explain what the default pending->queued scheduler isn’t providing for you? The script you’re attempting to write should be quite simple to achieve, but where, when and how to run it is possibly a bit more complex.

Hi Daniel;

I have 3 jobs set this way:
Job 1 → Job 2 (depends from 1) - Job3 (depends from 3)
Job1 (Export ASS files)
Job2 (Renders to EXR)
Job3 (Deletes ASS files)

I noticed that if someone suspend Job3 and later resumes it, the job starts ignoring if the Job2 is finished.
I know the correct way of “resume” a dependency enabled task is “mark job as pending”, but I want to avoid mistakes. In this case Job3 is going to delete ass files, so a mistake will make the render fail.

Gotcha, that makes sense.

Slightly adjacent to your current request, you could neatly solve this through a post-job script for Job2 that cleans up the frames. There’s still room for error there, as with most of these auto-cleanup scenarios – like if a user wants to re-run a frame, or a job.

If you still want to keep the cleanup as an actual job and write a script for this, I would recommend an event plugin. The plugin can listen for whatever job-state you think best captures your scenario: Event Plugins — Deadline 10.1.23.6 documentation

Perhaps OnJobReleased or OnJobStarted callbacks? Then, depending on the status of the job’s dependencies you can take appropriate action (eg. place the job back in a pending state if required).

As for traversing dependencies, unless I’m misunderstanding something, you’re actually after the Job object itself, not each Task.

Here’s a Monitor (Job) script you can mess around with that I hope illustrates dependency retrieval:

from Deadline.Scripting import RepositoryUtils, MonitorUtils
from Deadline.Jobs import Job


def __main__(*args):
	selected_jobs = MonitorUtils.GetSelectedJobs()

	for job in selected_jobs:
		dependencies = traverse_dependencies(job)
		print('Dependencies for job {}:\n- {}'.format(
			job,
			'\n- '.join([x.JobName for x in dependencies])
		))


def traverse_dependencies(job): # type: (Job) -> list[Job]
	_dependencies = [] # type: list[Job]

	def recurse(job_ids, flush_cache=False): # type: (list[str], bool) -> None
		if not job_ids:
			return

		# NOTE: Only flush `GetJobs` cache the first time we call it
		# Anything else seems to take you straight to crashville

		_jobs = RepositoryUtils.GetJobs(job_ids, flush_cache)
		_dependencies.extend(_jobs)

		for _job in _jobs:
			recurse(_job.JobDependencyIDs, False)

	recurse([job.JobId], True)
	return _dependencies

Cheers

Privacy | Site terms | Cookie preferences