8000 Raise TriggerFail from triggers and add a "message" attribute to all states by jlowin · Pull Request #67 · PrefectHQ/prefect · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Raise TriggerFail from triggers and add a "message" attribute to all states #67

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

Merged
merged 17 commits into from
Jul 19, 2018

Conversation

jlowin
Copy link
Member
@jlowin jlowin commented Jul 19, 2018

Following up on #59, this PR does two major things:

  1. Converts triggers to raise a new TRIGGERFAIL signal that, in turn, sets a TriggerFail state, which closes Update trigger functions to use TriggerFailed #61.

  2. Trapping this error highlighted the importance of being able to pass an optional message with each state, in addition to its data attribute, that helps explain how and why it came to be. So state now takes two (optional) arguments: data and message.

In addition, it adds a bunch of tests for states

@jlowin jlowin requested a review from cicdw as a code owner July 19, 2018 03:57
@jlowin
Copy link
Member Author
jlowin commented Jul 19, 2018

In one version of this, I had different states take different arguments. For example, Failed took a message argument (to explain why it failed) but other States didn't. Similarly, Scheduled and Retrying took a scheduled_time argument. After playing with that, I found it difficult to keep track of what state took what arguments, especially at moments where states were changing, so I think it's best for all states to share a common API, which here I propose to be State(data, message)

def set_state(self, current_state: State, state: State, data: Any = None) -> State:
return state(data)
def set_state(
self, current_state: State, state: State, data: Any = None, message: str = None
Copy link
Member

Choose a reason for hiding this comment

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

message will sometimes be an actual Exception as well.

Copy link
Member Author
@jlowin jlowin Jul 19, 2018

Choose a reason for hiding this comment

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

Good point. I'm not too familiar with passing errors around as strings (maybe the traceback is lost?)-- do you think it's preferable to change the type signature to message: Union[str, Exception] or to call this function as set_state(message=str(e))?

Copy link
Member

Choose a reason for hiding this comment

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

So from what I remember, we changed from str(e) because that drops the exception type and only returns the exception's message. Maybe we could use repr(e) though? I'm game to try it with all strings first and try to keep states lean, although I do wonder how a user would debug a failing task with no traceback.

Copy link
Member Author

Choose a reason for hiding this comment

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

Setting the exception is common enough, let's just make it Union type annotation for now. I am removing this method anyway in my proposed executor/state refactor

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good!

cicdw
cicdw previously approved these changes Jul 19, 2018
Copy link
Member
@cicdw cicdw left a comment

Choose a reason for hiding this comment

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

LGTM (assuming tests pass)

@jlowin jlowin merged commit 47fcefb into master Jul 19, 2018
@jlowin jlowin deleted the state-touchup branch July 19, 2018 16:28
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.

Update trigger functions to use TriggerFailed
2 participants
0