Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SymfonyLive London 2016 - The Workflow Awakens

SymfonyLive London 2016 - The Workflow Awakens

It is common having to handle statuses or product states, either on e-commerce or editorial websites. To do that, you can use the classical -manual- way, or get help from libraries covering the basis.

In this talk, we will talk about the state machine concept and definition before considering its usage looking at existing open source libraries. Finally following the Symfony way, we will study the brand-new "Workflow" component.

7d0490ac1ac3bbd80889f36efa32e4eb?s=128

Tugdual Saunier

September 16, 2016
Tweet

More Decks by Tugdual Saunier

Other Decks in Technology

Transcript

  1. The Workflow Awakens Tugdual Saunier

  2. 2 Tugdual Saunier @tucksaun Shipping guy.
 Loves Dev, Ops and

    automation. London, UK Blackfire.io/SensioLabs
  3. 3 History of the
 Workflow component

  4. 4 Genesis

  5. Winter 2013 5

  6. 6

  7. Do we open source it? 7

  8. Yes ! 8

  9. In Symfony? 9

  10. Ok, but Greg does the PR 10

  11. 11

  12. As usual for @lyrixx 12

  13. September 2014 13

  14. Lack of time 14

  15. February 2016 15

  16. Let’s get back to work 16

  17. 17 But was is it?

  18. 18 What problems should it address?

  19. 19 On an editorial website, there are several kinds of

    people involved. Freelancers, journalists, spellcheckers, chief editor, publication director, … An article is not published that easily. Context
  20. 20 For example, an article must be validated by a

    journalist and a spellchecker. Otherwise, the article can not be published. Rules exist
  21. 21 The component responsibili﬚ is to ensure the article properly

    goes by all validation steps. Welcome Workflow!
  22. 22 Workflow:
 a State Machine

  23. 23 States / Transitions state A state B Transition T1

  24. 24 Oriented Graph A B T1 C D E T2

    T3 T4 T5
  25. 25 Get back to the PR

  26. Read the code one more time 26

  27. Being able to handle article publication process There is a

    serie of steps that must be fulfilled Only some users can move from one step to the other Some steps can be done at the same time Define the specs 27
  28. 28 Example

  29. Let’s face it,
 a state machine is not appropriate 29

  30. Read some doc 30

  31. Explore existing libraries 31

  32. State machine: https:/ /github.com/yohang/Finite https:/ /github.com/winzou/state-machine Petrinet https:/ /github.com/florianv/petrinet https:/

    /github.com/alterway/component-workflow Other https:/ /github.com/vespolina/workflow Overview 32
  33. 33 Let’s move Workflow code to a “Workflow net”

  34. 34 What’s this?

  35. 35 This is an extension of Petri networks. It looks

    like state machines. But with more features. Note: Symfony Workflow component does not implement all the specs. Workflow Net
  36. 36 Places / Transitions place A place B Transition T1

  37. 37 Several Inputs Outputs place place Transition place place

  38. 38 Tokens

  39. Schrödinger's cat 39

  40. 40 Marking

  41. 41 Some Workflow examples

  42. 42 Straight

  43. 43 Round Trip

  44. 44 Or

  45. 45 And / Parallel

  46. 46 Wait, what?

  47. 47 Let’s implement

  48. Diff 48

  49. 49 Workflow::can()

  50. 50 Workflow::can() example

  51. 51 Workflow::apply()

  52. 52 Workflow::apply() example
 Before

  53. 53 Workflow::apply() example
 After

  54. 54 Workflow::getEnabledTransitions()

  55. 55 Definition class : Places

  56. 56 Definition class : Transitions

  57. 57 Definition class : Transitions

  58. 58 Definition class : Transitions

  59. 59 Definition class : Transitions

  60. 60 Graphviz dumper

  61. 61 The EventDispatcher has been plugged into the Workflow !

    Events are dispatched each time: • a place is leſt • a transition is fired • a place is reached Events
  62. 62 plus one : GuardEvent

  63. 63 What about Symfony?

  64. 64 It is always recommended to first draw your workflow

    on paper first to try it beforehand. Definition - By Hand
  65. 65 Definition - YML

  66. 66 Definition - YML - Supports

  67. 67 Definition - YML - Places

  68. 68 Definition - YML - Transitions

  69. 69 What does it look like?

  70. 70 The view

  71. 71 The view

  72. 72 The controller

  73. 73 What about guard?

  74. 74 What about guard?

  75. 75 What about guard?

  76. 76 Demo ?

  77. @blackfireio #blackfireio