Long running tasks & workflows in nuxeo - easysoa/EasySOA GitHub Wiki
How to do some work asynchronously (in Nuxeo ?)
using java ThreadPoolExecutor & Queue :
- ThreadPoolExecutor made for what we want
- can use given Queue (ex. with Comparator-based priority, blocking...), implements Java 6 ExecutorService http://www.javamex.com/tutorials/threads/ThreadPoolExecutor.shtml
- queues impls : Array (faster), Linked (simplest), other impls with more features : http://stackoverflow.com/questions/1301691/java-queue-implementations-which-one
- in Nuxeo : used to execute async event (and therefore notifications), also in Nuxeo WorkManager, Quartz scheduler
- generic example : see OW's
using nuxeo scheduler :
- event-sending tasks, with static conf without context params http://explorer.nuxeo.org/nuxeo/site/distribution/current/viewExtensionPoint/org.nuxeo.ecm.core.scheduler.SchedulerService--schedule nuxeo-core/nuxeo-core-event/src/main/java/org/nuxeo/ecm/core/scheduler/ScheduleImpl.java
- doc & cron samples http://doc.nuxeo.com/display/NXDOC/Scheduling+periodic+events
use Nuxeo Notifications :
- NotificationEventListener listens to events, gets conf'd notifications from NotificationService, and sends them to their users as another event https://fisheye.nuxeo.com/browse/nuxeo-features/nuxeo-platform-notification/nuxeo-platform-notification-core/src/main/java/org/nuxeo/ecm/platform/ec/notification/NotificationEventListener.java?r=7ff11b8f3cf5e6eae02381051efaa98580110ba7
- supports : in between NotificationListenerHook, source document (i.e. a notification happens on a document) & its author / state / version / content...
(best answer) using nuxeo WorkManager service / impl :
- executes Work in a thread pool (with maxThreads)'s conf'ble work queue (ex. default, fulltextUpdater) that depends on the work's category (ex. fulltextUpdater) http://explorer.nuxeo.org/nuxeo/site/distribution/Nuxeo%20Platform-5.6/viewService/org.nuxeo.ecm.core.work.api.WorkManager https://fisheye.nuxeo.com/viewrep/nuxeo-core/nuxeo-core-event/src/main/resources/OSGI-INF/workmanager-config.xml?r=2efe9c842820f2da7a1a01903f222d6999d8d533
- uses AsyncEventExecutor, has its own ThreadPoolExecutor http://community.nuxeo.com/api/nuxeo/5.6/javadoc/org/nuxeo/ecm/core/work/WorkManagerImpl.WorkThreadPoolExecutor.html
- use : schedule(Work extends AbstractWork) ; api http://community.nuxeo.com/api/nuxeo/5.6/javadoc/org/nuxeo/ecm/core/work/api/WorkManager.html
- Work supports : async, transactional, data map, progress, time when scheduled & started
- conf http://explorer.nuxeo.org/nuxeo/site/distribution/current/viewComponent/org.nuxeo.ecm.core.work.service
- specs : for either Java 6 ExecutorService (with async ex. Futures) http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html , JCA, Quartz https://jira.nuxeo.com/browse/NXP-9079
- ex. priority queue according to Work implements Comparator, uses java PriorityBlockingQueue http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/PriorityBlockingQueue.html instead of LinkedBlockingQueue : https://fisheye.nuxeo.com/viewrep/nuxeo-core/nuxeo-core-event/src/test/resources/test-workmanager-config.xml?r=8c7f8ab68f77ea9aac643c84e7012e08612535cd nuxeo-core/nuxeo-core-event/src/test/java/org/nuxeo/ecm/core/work/WorkManagerTest.java
How to manage (auto or manual task) workflows in Nuxeo ?
using Nuxeo jBPM tasks :
- prefer content routing workflows http://www.nuxeo.com/blog/development/2011/12/content-routing-an-alternative-to-jbpm/
- still available as an addon http://doc.nuxeo.com/display/USERDOC56/Nuxeo+jBPM
- practical jbpm on nuxeo http://answers.nuxeo.com/questions/170/how-to-design-my-own-workflow-and-deploy-it-on-server
- code & configuration http://explorer.nuxeo.org/nuxeo/site/distribution/Nuxeo%20CM-1.0-SNAPSHOT/viewComponent/org.nuxeo.ecm.platform.jbpm.core.JbpmService
Using Nuxeo Task Service :
- manages any kind of workflow (user) task
- NB. implementation as switched from jBPM to Nuxeo's own http://www.nuxeo.com/blog/development/2011/12/content-routing-an-alternative-to-jbpm/
- available in content automation http://explorer.nuxeo.org/nuxeo/site/distribution/Nuxeo%20DM-5.4.2/viewOperation/Workflow.CreateTask
using Nuxeo Studio Workflow :
- it is built on Nuxeo Content Routing http://doc.nuxeo.com/display/Studio/Workflow
using Nuxeo Content Routing :
- "A route is a workflow, i.e. a set of steps that documents can go through." NB. provided by & for Nuxeo Case Management (CMF)
- IMPORTANT Nuxeo Studio workflows are built on Nuxeo Content Routing and is the easiest way to use it (define workflows / routes & their steps...)
- doc http://doc.nuxeo.com/display/CMDOC55/Content+Routing
- step types :
- Ex. steps : user validation tasks, publish, send email
- to define one, define its Document type (extending DocumentRouteStep) and layout
- default step types (from CMF) : DistributionStep, DistributionTask, GenericDistributionTask, PersonalDistributionTask http://explorer.nuxeo.org/nuxeo/site/distribution/Nuxeo%20Case%20Management-5.4.0-I20101018_1103/viewContribution/org.nuxeo.cm.schemas--doctype/introspection & layout http://explorer.nuxeo.org/nuxeo/site/distribution/Nuxeo%20Case%20Management-5.4.0-I20101018_1103/viewComponent/com.nuxeo.case-management.layouts/introspection
- then, to add actions to it, define them as Content Automation operations chains (document step available in Context at document.routing.step) http://doc.nuxeo.com/display/NXDOC55/Content+Automation , and bind them to step types (must also define undo & interrupt chains) as in http://explorer.nuxeo.org/nuxeo/site/distribution/Nuxeo%20Case%20Management-5.4.0-I20101018_1103/viewContribution/org.nuxeo.cm.typeChainMapping.contrib--chainsToType
- routes :
- it is defined as a document of type DocumentRoute, which is serial or parallel blocks / groups / folders of steps, by the user using the nuxeo ui defined for the step document http://doc.nuxeo.com/display/CMDOC55/Route+processing+and+lifecycle
- it has to be validated by routeManagers
- an instance of it (copied & stored in a hidden folder at the root) can then be started on a document from the UI, in the Summary of a Document or a Route.
- its documents are then displayed by http://explorer.nuxeo.org/nuxeo/site/distribution/Nuxeo%20Case%20Management-5.4.0-I20101018_1103/viewContribution/org.nuxeo.ecm.platform.routing.querymodel--model/introspection
- route instance step lifecycle : Ready, Running, Done, Cancelled. Lifecycle is updated by the default BulkLifeCycleChangeListener, but without recursion http://explorer.nuxeo.org/nuxeo/site/distribution/Nuxeo%20Case%20Management-5.4.0-I20101018_1103/viewContribution/org.nuxeo.ecm.platform.routing.lifecycle.contrib--types/introspection
- also :
- to define metadata that is shared among all steps, define a new route document type extending DocumentRoute http://doc.nuxeo.com/display/CMDOC55/Advanced+Features
- steps & routes are seen as documents for security, lifecycle etc.
- how to display (a button) only when a workflow is started TODO for updateToLatestVersion http://doc.nuxeo.com/pages/viewpage.action?pageId=12912851
- code & configuration :
- lookup "routing" in http://explorer.nuxeo.org
- document routing : DocumentRoutingServiceImpl implements http://community.nuxeo.com/api/nuxeo/5.6/javadoc/org/nuxeo/ecm/platform/routing/api/DocumentRoutingService.html
- user task management : TaskServiceImpl implements TaskService
- how execution state is stored http://doc.nuxeo.com/display/NXDOC56/How+to+complete+a+workflow+task+programmatically
- setup task dashboard & activate workflow tab http://doc.nuxeo.com/display/Studio/How+to+set+up+a+tasks+dashboard