[Perl-workflow-devel] current event (was: Workflow 0.26 maintenance release)
Brought to you by:
jonasbn
From: Alexander K. <ak-...@cy...> - 2007-03-09 12:00:32
|
Hi Jonas & all, On Wed, Mar 07, 2007 at 09:57:05AM +0100, Alexander Klink wrote: > > We have a lot of things on the drawing board, one of the major ones > > being a change of SCM from CVS to SVN. I hope I will be able to put > One thing that I'll be working on soon (I guess this or next week) > is the ability to add something to the workflow structure to see > what a workflow is currently doing. In OpenXPKI, we have lots of > workflows and we can see their state but we can't really know whether > they are currently "working" (i.e. executing an action or checking a > condition, validating something, ...). I was thinking of adding > something to the workflow that says what is currently being done so > that we can see something like "checking condition <name>" next to > the workflow. > I haven't looked at where to put it in the code yet, so I am open for > suggestions. Work on that is coming along quite well. Because of the structure, it looks like I can't reach my goal of saving what condition is executed at the moment, but at least I can say that conditions are currently being checked for some action. Here is what I've done so far: Index: lib/Workflow.pm =================================================================== RCS file: /cvsroot/perl-workflow/workflow/lib/Workflow.pm,v retrieving revision 1.32 diff -u -r1.32 Workflow.pm --- lib/Workflow.pm 15 Dec 2006 07:59:20 -0000 1.32 +++ lib/Workflow.pm 9 Mar 2007 11:52:17 -0000 @@ -10,7 +10,7 @@ use Workflow::Exception qw( workflow_error ); use Workflow::Factory qw( FACTORY ); -my @FIELDS = qw( id type description state last_update ); +my @FIELDS = qw( id type description state last_update current_event save_events ); __PACKAGE__->mk_accessors( @FIELDS ); $Workflow::VERSION = sprintf("%d.%02d", q$Revision: 1.32 $ =~ /(\d+)\.(\d+)/); @@ -70,6 +70,10 @@ # This checks the conditions behind the scenes, so there's no # explicit 'check conditions' step here + if ( $self->save_events() ) { + $self->current_event('Checking conditions for ' . $action_name); + FACTORY->save_workflow( $self ); + } my $action = $self->_get_action( $action_name ); # Need this in case we encounter an exception after we store the @@ -79,10 +83,20 @@ my ( $new_state, $action_return ); eval { + if ( $self->save_events() ) { + $self->current_event('Validating input for ' . $action_name); + FACTORY->save_workflow( $self ); + } $action->validate( $self ); $log->is_debug && $log->debug( "Action validated ok" ); + + if ( $self->save_events() ) { + $self->current_event('Executing ' . $action_name); + FACTORY->save_workflow( $self ); + } $action_return = $action->execute( $self ); $log->is_debug && $log->debug( "Action executed ok" ); + $self->current_event(''); $new_state = $self->_get_next_state( $action_name, $action_return ); if ( $new_state ne NO_CHANGE_VALUE ) { @@ -98,7 +112,7 @@ FACTORY->save_workflow( $self ); $log->is_info && - $log->info( "Saved workflow with possible new state ok" ); + $log->info( "Saved workflow with possibly new state ok" ); }; # If there's an exception, reset the state to the original one and @@ -109,6 +123,7 @@ $log->error( "Caught exception from action: $error; reset ", "workflow to old state '$old_state'" ); $self->state( $old_state ); + $self->current_event(''); # Don't use 'workflow_error' here since $error should already # be a Workflow::Exception object or subclass @@ -209,6 +224,7 @@ $self->state( $current_state ); $self->type( $config->{type} ); + $self->save_events( $config->{save_events} ); $self->description( $config->{description} ); # other properties go into 'param'... @@ -920,6 +936,14 @@ Date of the workflow's last update. +B<current_event> + +If save_event is set in the workflow configuration, Workflow saves +persists the events (checking conditions, validating input, executing +actions). current_event is a textual description of the event that +is happening at the moment. If nothing is happening, current_event +returns the empty string. + =head3 context (read-write, see below) A L<Workflow::Context> object associated with this workflow. This Index: lib/Workflow/Config.pm =================================================================== RCS file: /cvsroot/perl-workflow/workflow/lib/Workflow/Config.pm,v retrieving revision 1.11 diff -u -r1.11 Config.pm --- lib/Workflow/Config.pm 8 Jul 2006 20:02:33 -0000 1.11 +++ lib/Workflow/Config.pm 9 Mar 2007 11:52:17 -0000 @@ -271,6 +271,7 @@ type $ description $ persister $ + save_events $ observer \@ sub $ class $ In the OpenXPKI persister, I now persist $wf->current_event to the database, which seems to work fine. This of course required a change to the database schema, so I'm not exactly sure if this is the right way to go for everybody. I've noticed that there is something called extra_workflow_data, but this seems to go right into the context. What do you all think, should we go for the schema change in the DBI persister or should we try to work around it (and if so, how?)? Regards, Alex -- Dipl.-Math. Alexander Klink | IT-Security Engineer ak-...@cy... | working @ urn:oid:1.3.6.1.4.1.11417 |