14
Viewflow internals 0.6.0 beta

Viewflow internals: ~3k sloc explaned

Embed Size (px)

DESCRIPTION

Viewflow Internals http://viewflow.io

Citation preview

Page 1: Viewflow internals:  ~3k sloc explaned

Viewflow internals0.6.0 beta

Page 2: Viewflow internals:  ~3k sloc explaned

Intro

➔ Django friendly➔ Easy to start➔ Helps to grow

➔ Business applications➔ People collaboration

Reusable workflow library

Page 3: Viewflow internals:  ~3k sloc explaned

Intro

Highly technical talk

If anything unclear - ask [email protected]

Don’t panic. Library is only about 3k SLOC

Page 4: Viewflow internals:  ~3k sloc explaned

Intro

➔ Flow◆ Nodes◆ This object

➔ Models➔ Nodes

◆ Views◆ Jobs◆ Gates

➔ Activation◆ Livecycle

➔ Parallel tasks execution◆ Token◆ Locking

➔ Error handling◆ Activation context

➔ Viewsite◆ Forms

Viewflow internals

Page 5: Viewflow internals:  ~3k sloc explaned

Flow

➔ CRUD and Flow Separation➔ Task dependencies graph➔ Boilerplate: Permissions, URLs

Page 6: Viewflow internals:  ~3k sloc explaned

Models

➔ Process/Task tables➔ Multi-table inheritance➔ Abstract base classes

Page 7: Viewflow internals:  ~3k sloc explaned

Views

➔ Function based Views ➔ Class based Views

URL: <flow_cls>/<process_pk>/<task_name>/<task_pk>

Page 8: Viewflow internals:  ~3k sloc explaned

Jobs➔ Never miss the broken task➔ Celery out of the box➔ Easy to add another libraries support:

rq, huye

Page 9: Viewflow internals:  ~3k sloc explaned

Gates

➔ Workflow patterns support➔ Decide what task should be executed next➔ Easy to add logic by extending class or

providing callable

Page 10: Viewflow internals:  ~3k sloc explaned

Activation

def prepare(self, **data)

@classmethod

def activate(cls, flow_task, prev_activation, token):

def initialize(self, flow_task, task):

def assign(self, user)

def start(self)

def execute(self) def error(self, exc)

def done(self)

def activate_next(self)

➔ Weaves declarative Flow node with Process and Task instance

Page 11: Viewflow internals:  ~3k sloc explaned

Parallel task execution and Joins

➔ Split Node adds suffix➔ Join Node waits all nodes

with common prefix

Task Token

Short pessimistic locks➔ @flow_view➔ @flow_job

Optimistic lock with django-fsm on Task ➔ If your are ok with failsOR

Concurrent updates are rare, but:

Page 12: Viewflow internals:  ~3k sloc explaned

Error handling

View Jobs

➔ Any exception in subsequent task activation would rollback whole transaction.

➔ View task still available for user second try

➔ Job results committed immediately as job completes.

➔ Any exception in subsequent tasks activations would save subsequent task in error state.

Could be customized by providing custom Activation class

Page 13: Viewflow internals:  ~3k sloc explaned

ViewsiteCompletely optional, but you will like it

➔ Admin like speed for interface development➔ Works with your Views➔ Ready for end user➔ Forms layouts, dynamic formsets, bootstrap

More in next videos...

Page 14: Viewflow internals:  ~3k sloc explaned

Thank you

$ pip install django-viewflow

http://viewflow.io

http://github.com/kmmbvnr/django-viewflow/

[email protected]