9 Replies Latest reply on Oct 17, 2006 5:20 AM by Laetitia Gyger

    Best way to structure a business process with a delay.

    Brad O'Hearne Newbie

      Hello -- I need your advice on the best way to structure a particular business process using jbpm 3.1.1. What the business process actually needs to accomplish is the following in order:

      1) Save information to custom tables in the database.
      2) Wait until midnight.
      3) Retrieve the information saved in step 1 from the database, and perform an action based on that informaiton.

      So far, I have tried to structure this with a simple business process with the following nodes:

      start > saveInfo > createTimer > End

      and another path in the business process that looks like this:

      performAction > End

      I have 3 questions regarding this:

      1) First, I am able to create a timer and save the timer to the scheduler. The business process instance is saved prior to the business process executing and after as well. However, there is nothing saved to the JBPM_TIMER table in the database. How can I get the timers that are created (not on a task, as there is no human intervention needed, but in a process node) to save to the database?

      2) My timer is set to transition to my performAction node. However, the business process has ended, by merits of completing the saving of the timer and traversing the end node. Will the timer appropriately transition to the performAction node? I'm sensing it will not, and there's probably a more appropriate way to structure this.

      3) How would you structure this requirement?

      Thanks a lot for your help. If there is specific documentation that addresses this, please direct me to it, as I haven't found the answers readily in the documentation.

      Thanks,

      Brad

        • 1. Re: Best way to structure a business process with a delay.
          Ronald van Kuijk Master

          1: I have no idea if this is at all possible this way. What you could do is build a custom node (not difficult) that calls a real scheduler (like quartz) and when that finishes signal this custom node
          2: I should see the processdef and code to get a better impression
          3: what I mentioned in 1 is an option

          • 2. Re: Best way to structure a business process with a delay.
            Laetitia Gyger Newbie

            Hi Brado,
            I need to do something very close :
            - start process
            - save information
            - wait until next business day
            - do some update into a parallel application
            - send notification
            I've tried to define some timer within a task node, as for example :

             <timer name="wait"
             duedate='2 minutes'
             transition='end' >
             <action name="update"
             class="ch.ne.gubpm.process.action.UpdateSIPPActionHandler">
             </action>
             </timer>
             <transition name="end" to="end"/>
            

            but testing this shows me that the task is not waiting the 2 required minutes before calling action and then following transition.
            Could you help me anyhow please ?
            Thanks in advance.

            • 3. Re: Best way to structure a business process with a delay.
              Brad O'Hearne Newbie

              Hello gygerl,

              I dont know how to work out your declarative approach -- I used a programmatic approach to creating my timer inside my node's ActionHandler, as follows:

              Date dueDate = <set your due date here>;
              timer.setDueDate(dueDate);
              timer.setTransitionName("mytransitionname");
              timer.setGraphElement(executionContext.getEventSource()); timer.setTaskInstance(executionContext.getTaskInstance());
              timer.setToken(executionContext.getToken());
              SchedulerService schedulerService = (SchedulerService) Services.getCurrentService(Services.SERVICENAME_SCHEDULER);
              schedulerService.createTimer(timer);
              


              That seemed to work fine for me. Hope that helps.

              Cheers,

              Brad

              • 4. Re: Best way to structure a business process with a delay.
                Laetitia Gyger Newbie

                Hi Brad and thanks for your answer.
                I erased the timer definition in the process-definition xml file and defined the timer as you described, but the timer doesn't "hold" the further execution of the node.
                As i understood, your code hold the execution until midnight and then the scheduler runs it when duedate "happens", right ?
                Did you do any special configuration ? (for scheduler running ??)
                Could you send me more code in order for me to compare mine with yours ? (for example : timer definition in process-definition xml file if any, action call in same file, and so on).
                Thanks in advance.
                Laetitia

                • 5. Re: Best way to structure a business process with a delay.
                  Brad O'Hearne Newbie

                  Is your scheduler running? I used the servlets that came with the jbpm start the scheduler.

                  Brad

                  • 6. Re: Best way to structure a business process with a delay.
                    Laetitia Gyger Newbie

                    Hi Brad,
                    Well. It was not :((
                    I am working on making it run but, beyond others, I got this error :

                    17:12:37,667 [JbpmScheduler] INFO ConnectionProviderFactory : Initializing connection provider: org.hibernate.connection.DatasourceConnectionProvider
                    17:12:37,682 [JbpmScheduler] INFO NamingHelper : JNDI InitialContext properties:{}
                    17:12:37,713 [JbpmScheduler] FATAL DatasourceConnectionProvider : Could not find datasource: java:/OracleDS
                    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
                     at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
                     at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
                     at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
                     at javax.naming.InitialContext.lookup(InitialContext.java:351)
                     at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
                     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
                     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
                     at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:366)
                     at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
                     at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1859)
                     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1152)
                     at org.jbpm.persistence.db.DbPersistenceServiceFactory.getSessionFactory(DbPersistenceServiceFactory.java:90)
                     at org.jbpm.persistence.db.DbPersistenceService.getSessionFactory(DbPersistenceService.java:74)
                     at org.jbpm.persistence.db.DbPersistenceService.getSession(DbPersistenceService.java:78)
                     at org.jbpm.persistence.db.DbPersistenceService.getSchedulerSession(DbPersistenceService.java:243)
                     at org.jbpm.JbpmContext.getSchedulerSession(JbpmContext.java:425)
                     at org.jbpm.scheduler.impl.SchedulerThread.executeTimers(SchedulerThread.java:103)
                     at org.jbpm.scheduler.impl.SchedulerThread.run(SchedulerThread.java:70)
                    

                    Do you know where it could come from ?
                    I do not get where the configuration needs to be done.
                    Cheers.

                    • 7. Re: Best way to structure a business process with a delay.
                      jrojas_pb Newbie

                      I posted a complete example that works and does what you want. Just as Brad suggested, mine worked only with custom timers -- not created in the process definition.

                      I later updated the process definition shown in order to get rid of the exception that I was getting.

                      Anyways, all you have to do is add a node-enter event with the timer parameters you want. The startTime is a new variable I added that allows you to start the timer whenever you want.
                      eg: startTime=23:59 and repeat=24 hours
                      to start the timer at then next 11:59 pm, and every 24 hours there after.

                      http://jboss.com/index.html?module=bb&op=viewtopic&t=92733

                      Good luck!

                      John

                      • 9. Re: Best way to structure a business process with a delay.
                        Laetitia Gyger Newbie

                        Thanks for your help.
                        I finally decided to deploy the jbpm webapp instead of trying to start the scheduler separately.
                        everything works fine now.
                        Cheers.
                        Laetitia