Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cycle Detection #160

Merged

Conversation

rclough
Copy link
Collaborator

@rclough rclough commented Jul 16, 2015

This pull request is to add the verify() method to the Job class, which verifies that there are no cycles in the job, include cross-job cycles.

Included are a few unit tests, including one really complex job where I tried to combine every possible way of linking jobs, verify them, and then add a loop at the end and make sure it can detect a loop deep in.

If you think of any edge cases you want me to cover, let me know!

""" Checks for the existence of a method or list of methods """
if isinstance(functions, str):
functions = [functions]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figure to make this method general, I would accept either a string, or list of strings. This line converts the single string to a list with just one string, otherwise the for expected_method in functions: will loop through each char in the string.

There is no case currently that needs a list of functions (unless we want to get really explicit) so if you'd rather just simplify it to just have one string, I can change it to that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is definitely simpler (and harder for people in the future to screw up) if it's always operating on one type. Since we don't need the list functionality right now, I think we should just make it always accept a single string. This is also pretty easy to compose together later on if something needs to check multiple:

all(map(partial(self._implements_function, obj), ['function1', 'function2']))

Could either do it that way, which I realize looks terrible to anyone who's not a LISP nerd, or write another function at the same level of _implements_function which explicitly operates on lists and calls the single function version to do its work.

@rclough
Copy link
Collaborator Author

rclough commented Jul 16, 2015

I also just added a commit to make test_core.py pass PEP8 and pyflakes, so you'll see some whitespace in there

@@ -101,14 +104,14 @@ def test_dagobah_add_tasks():


@with_setup(blank_dagobah)
def test_dagobah_delete_job():
def test_dagobah_delete_job2():
dagobah.add_job('test_job')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed these two because they have the same name as an existing test, but are slightly different in how they test. Not sure if one is better than the other. But pyflakes was bitching.

# Traverse nodes and verify any JobTasks
logger.debug("Traversing topologically sorted tasks.")
for task in topo_sorted:
if self.implements_expandable(task):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to change this to the negative check, and do a continue in that case, which will eliminate 1 level of indentation from the rest of the following code

ex:

if not self.implements_expandable(task):
    continue

logger.debug("Found expandable task: {0}".format(task.name))
cur_job = self.parent._resolve_job(task.target_job_name)
... 

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, good idea

@thieman
Copy link
Owner

thieman commented Jul 30, 2015

Done with first pass review, looks pretty good

Ryan Clough added 3 commits July 30, 2015 17:20
_implements_function originally took either a string, or list of
strings. It has been decided that multiple datatypes are unnecessary,
and end users can easily call the method on multiple strings in a list
themselves. This commit also includes a deletion of an unnecessary log
line.
This commit switches a conditional statement to the opposite in order to
reduce the indentation on the following code block, which is
sufficiently large enough to argue neatness.

Also, an error is raised when referencing an invalid JobTask, instead of
a warning with verfify() returning false. This is because in this case,
the data is fundamentally broken.
@rclough
Copy link
Collaborator Author

rclough commented Jul 30, 2015

Direct concerns with the previous PR have all been addressed.

@thieman
Copy link
Owner

thieman commented Aug 5, 2015

LGTM 🐻

rclough added a commit that referenced this pull request Aug 6, 2015
@rclough rclough merged commit 2192f21 into thieman:dev-job-in-job Aug 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants