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

Runtime middleware #662

Merged
merged 16 commits into from
Feb 15, 2017
Merged

Runtime middleware #662

merged 16 commits into from
Feb 15, 2017

Conversation

bergie
Copy link
Member

@bergie bergie commented Jan 30, 2017

Improves runtime handling reliability following the same middleware approach as we did with users in #660.

This PR will change actions from payload to { state: stateWhenActionFired, payload: payload }. Will make compatibility wrapper so that old stores don't need to be touched.

@bergie bergie force-pushed the runtime_middleware branch from 182e2bb to 8515d8e Compare January 31, 2017 15:05
else
# Warn of actions that don't contain state
debug "#{groups.join(':')} was sent without state, using previous state"
state = data?.state or c.state
Copy link
Member

Choose a reason for hiding this comment

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

WTH is state middleware? Sounds like a god-module waiting to happen...
How does one know what is "state" and what is not supposed to be "state"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Explained in PR description. Basically we had problems with stale state because:

  • Application state is kept in the main Polymer element
  • However, certain middleware (and currently still stores) need partial state access
  • For this, old stores kept their own partial state
  • This state was not properly cleared in some situations, causing stores to use stale runtime connections etc
  • Now latest state is sent alongside UI actions so stores/middlewares don't need to keep track of it on their own

However, in the transitional period we will have actions sent without state. This middleware amends them with the latest state.

Copy link
Member

Choose a reason for hiding this comment

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

So as far as I understand, the entire application state is available as state on the messages - React style. Components like GetActionValues are then used to pick out the particular pieces of the state that is relevant for individual components that actually perform the logic of the "middleware".
Is this correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is correct. Middleware state access is meant to be read-only (though in plain JS that is hard to guarantee)


exports.getComponent = ->
c = new noflo.Component
c.description = 'Strips state from action payloads for backwards compat'
Copy link
Member

Choose a reason for hiding this comment

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

Why do components care about the presence of additional attributes?

Copy link
Member Author

Choose a reason for hiding this comment

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

They don't care about additional attributes, but the old stores expect to have event payload as the payload of the data packet. Now it is in data.payload (to provide support for data.state as well). This component is there so we don't need to change how the old stores operate until we migrate them to modern middleware/reducer combos

Copy link
Member

Choose a reason for hiding this comment

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

Ok

# Send selected edges to runtime
'runtime,graphs[0]' -> KEYS GetEdgeState(ui/GetActionValues)
Dispatch HANDLE[0] -> IN GetEdgeState
GetEdgeState VALUES[0] -> RUNTIME SendEdges(runtime/SendEdges)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we use arrayports for this? :( How is one supposed to know what-is-what?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we have variable number of connections to send data to. Just like we do with routers

Copy link
Member

Choose a reason for hiding this comment

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

Variable meaning not-known-at-component-creation-time?

Copy link
Member

Choose a reason for hiding this comment

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

Would prefer to use a JS array or object for such things, and then another component for picking out the particular element if/when needed. Don't like arrayports, and they are very badly supported in Flowhub.

@@ -5,6 +5,7 @@ var exported = {
'child_process': null,
'uuid': require('uuid'),
'flowhub-registry': require('flowhub-registry'),
'fbp-protocol-client': require('fbp-protocol-client'),
Copy link
Member

Choose a reason for hiding this comment

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

Who owns the connection to the runtime? What is the lifetime? How do code which needs a reference get it?

Copy link
Member Author

Choose a reason for hiding this comment

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

To be honest, that export there is just so we can load fbp-protocol-client in tests. We could do a separate webpack build for tests to remove it.

Copy link
Member

Choose a reason for hiding this comment

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

Not asking about the module export, but about the connection handling.

Copy link
Member Author

Choose a reason for hiding this comment

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

The connection is supposed to be owned by runtime/ConnectRuntime component, but right now we break encapsulation in the noflo-runtime element. That part should be refactored so that the Polymer element sends events to NoFlo-land and the correct component reacts to them

@bergie bergie changed the title WIP: Runtime middleware Runtime middleware Feb 6, 2017
@jonnor
Copy link
Member

jonnor commented Feb 8, 2017

Breaks current Msgflo completely, nothing happens when adding nodes. No error messages shown to user. Console has Error: Runtime 16ce3c8d-63e0-49fb-9af8-bcc5bb02448d cannot update graphs

@bergie
Copy link
Member Author

bergie commented Feb 8, 2017

@jonnor does MsgFlo send capabilities?

@jonnor
Copy link
Member

jonnor commented Feb 8, 2017

Ok the addnode thing actually seems to work. The bug seen where component did not get ports, is probably prefix-handling bugs with Msgflo.

@jonnor
Copy link
Member

jonnor commented Feb 8, 2017

@bergie yes of course. But Flowhub in project mode with existing components/graphs sends a bunch of messages before getting the reply of that... Not that I have any reason to believe that is new broken-ness. It also sends getruntime twice
screenshot from 2017-02-08 19-37-39

@jonnor
Copy link
Member

jonnor commented Feb 8, 2017

Looks like it re-sends the entire state also after receiving the runtime message

Copy link
Member

@jonnor jonnor left a comment

Choose a reason for hiding this comment

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

The edges payload is not following the spec.
It is using from and to instead of src and tgt.
https://flowbased.github.io/fbp-protocol/#edges

bergie added a commit to noflo/noflo-runtime that referenced this pull request Feb 10, 2017
@bergie
Copy link
Member Author

bergie commented Feb 10, 2017

@jonnor addressed in e6b46d4 and 5881de3

Copy link
Member

@jonnor jonnor left a comment

Choose a reason for hiding this comment

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

Seems to do the right thing. Tested MsgFlo

@jonnor
Copy link
Member

jonnor commented Feb 15, 2017

@bergie I suspect that the noflo-runtime changes brought in here broke edge data display? Should be fixed by #665 thought

@jonnor jonnor merged commit 479790d into master Feb 15, 2017
@jonnor jonnor deleted the runtime_middleware branch February 15, 2017 12:11
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.

2 participants