[MOBY-guts] biomoby commit

Eddie Kawas kawas at dev.open-bio.org
Thu Apr 2 18:33:44 UTC 2009


kawas
Thu Apr  2 14:33:44 EDT 2009
Update of /home/repository/moby/moby-live/Docs/MOBY-S_API/Perl
In directory dev.open-bio.org:/tmp/cvs-serv1391/Docs/MOBY-S_API/Perl

Modified Files:
	construct_moses_cgi_async_service.html 
Log Message:
added information on updating event state for a running task
moby-live/Docs/MOBY-S_API/Perl construct_moses_cgi_async_service.html,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Docs/MOBY-S_API/Perl/construct_moses_cgi_async_service.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Docs/MOBY-S_API/Perl/construct_moses_cgi_async_service.html	2009/03/30 13:12:34	1.1
+++ /home/repository/moby/moby-live/Docs/MOBY-S_API/Perl/construct_moses_cgi_async_service.html	2009/04/02 18:33:44	1.2
@@ -20,7 +20,7 @@
     <dt><a href="#test">Step 5: Service testing</a> </dt>
     <dt><a href="#deploy">Step 6: Service deployment</a></dt>
     <dt><a href="#test2">Step 7: Service testing using CGI</a></dt>
-    <dt><em>How to update polling status (optional) - coming soon</em></dt>
+    <dt><a href="#poll">How to update polling status (optional)</a></dt>
   </dl>
 </dl>
 <h2><a name="req" id="req"></a>What is needed</h2>
@@ -108,7 +108,7 @@
 <h3>We can update our cache by issuing the following commands:</h3>
 <ol>
   <li> <em>moses-generate-services.pl -u <br />
-  </em></li>
+    </em></li>
   <li><em>moses-generate-datatypes.pl -u</em></li>
 </ol>
 <blockquote>
@@ -128,7 +128,7 @@
 <p>Basically, we used the script <em><strong>moses-generate-services.pl</strong></em> to:</p>
 <ol>
   <li>automatically generate a perl module called <strong>getReverseEchoString.pm</strong> in the directory <strong><em>/your_home_dir/Perl-MoSeS/services/Service</em></strong> (if it already exists, it won't overwrite it).<br />
-  This file contains the implementation for our service and is what we edit to inject our business logic.</li>
+    This file contains the implementation for our service and is what we edit to inject our business logic.</li>
   <li>automatically generates a cgi script called <strong>getReverseEchoString.cgi</strong> in the directory <em><strong>/your_home_dir/Perl-MoSeS/cgi/samples/jmoby/net/</strong></em>.<br />
     This file is what we deploy on our web server that redirects cgi requests to our service to the <em><strong>getReverseEchoString.pm</strong></em> module above.<br />
   </li>
@@ -231,6 +231,105 @@
    &lt;/moby:mobyData&gt;
  &lt;/moby:mobyContent&gt;
 &lt;/moby:MOBY&gt;</pre>
+<h2><a name="poll" id="poll"></a>How to update polling status (optional)</h2>
+<p>If you have a really long running service and would like to ensure that users know exactly how far along the service is to completion, you can create more detailed <em>status</em> messages.</p>
+<p>Before we continue, it would be useful for you to get acquainted with the perl module, <em><strong><a href="http://search.cpan.org/perldoc?MOBY::Async::LSAE" target="_blank">MOBY::Async::LSAE</a>.</strong></em></p>
+<h3>Updating the status of our service</h3>
+<blockquote>
+  <p>There are 2 things that you need to successfully update the status of your service:</p>
+  <ol>
+    <li><em>service invocation id<br />
+      </em></li>
+    <li><em>the job id for the current task</em></li>
+  </ol>
+  <p>The service invocation id is very simple to obtain: </p>
+</blockquote>
+<pre class="script2">my $ID = $ENV{ID};  </pre>
+<blockquote>
+  <p>The job id is equally as easy to obtain!</p>
+</blockquote>
+<pre class="script2">my $jid = $request-&gt;jid;</pre>
+<blockquote>
+  <p>Now that we have those 2 pieces of information, all that is left is for you to choose what type of status update you would like your service to create:</p>
+  <ul>
+    <li>Heartbeat progress event</li>
+    <li>Percent progress event</li>
+    <li>State changed event <em>(default)</em></li>
+    <li>Step progress event</li>
+    <li>Time progress event</li>
+  </ul>
+  <p>We will be using the State changed event in this example.</p>
+  <p>In order to save the state information for our task, we need certain variables like, <em><strong>pid</strong></em>, <em><strong>input</strong></em>, <em><strong>status</strong></em>, and <strong><em>result</em></strong>.</p>
+  <ul>
+    <li><strong><em>pid</em></strong>  is the property id for our service,</li>
+    <li><strong><em>input</em></strong> is the input to our service,</li>
+    <li><strong><em>status</em></strong> is the current event state for our running task, and</li>
+    <li><strong><em>result</em></strong> holds the result for our running task and is obtained once our state is set to completed.</li>
+  </ul>
+</blockquote>
+<pre class="script2"># some variables we need to access/store our event information
+
+my $property_pid    = &quot;pid_$jid&quot;;<br />my $property_input  = &quot;input_$jid&quot;;<br />my $property_status = &quot;status_$jid&quot;;<br />my $property_result = &quot;result_$jid&quot;;</pre>
+<blockquote>
+  <p>To provide updated state information for our event, we need to first remember what our previous state was:</p>
+</blockquote>
+<pre class="script2"># construct an LSAE object based on the old event block
+my $old_status = 
+         LSAE::AnalysisEventBlock-&gt;new(
+                 $WSRF::WSRP::ResourceProperties{$property_status}
+         );</pre>
+<blockquote>
+  <p>We now instantiate a new <em><strong>LSAE::AnalysisEventBlock</strong></em> and set its various fields. For instance, we will take the previous state information from <em><strong>$old_status</strong></em> and then provide new state information for our event:</p>
+</blockquote>
+<pre class="script2"># construct a new state changed event
+my $status = LSAE::AnalysisEventBlock-&gt;new();<br />$status-&gt;type(LSAE_STATE_CHANGED_EVENT);
+# set the previous state<br />$status-&gt;previous_state( $old_status-&gt;new_state() );
+# set the new state<br />$status-&gt;new_state('running');
+# set our job id for this event<br />$status-&gt;id($jid);</pre>
+<blockquote>
+  <p>Once we have created our new analysis event block, we need to save it so that the client that made the job request to our service can access the state information:</p>
+</blockquote>
+<pre class="script2"># create a file based resource that we will store our event information
+my $lock = WSRF::MobyFile-&gt;new( undef, $ID );<br />$WSRF::WSRP::ResourceProperties{$property_status} = $status-&gt;XML();
+# here we leave the result empty since the service is still running<br />$WSRF::WSRP::ResourceProperties{$property_result} = '';
+# save the event so that our clients can access the information
+$lock-&gt;toFile();</pre>
+<blockquote>
+  <p>Here is the complete code that we put into our <em><strong>process_it</strong></em> subroutine where ever you feel like you should update the state of our long running task!</p>
+</blockquote>
+<pre class="script2"># our service invocation id
+my $ID = $ENV{ID};
+
+# our job id
+my $jid = $request-&gt;jid;
+
+
+# some variables we need to access/store our event information
+my $property_pid    = &quot;pid_$jid&quot;;<br />my $property_input  = &quot;input_$jid&quot;;<br />my $property_status = &quot;status_$jid&quot;;<br />my $property_result = &quot;result_$jid&quot;;
+
+
+# construct an LSAE object based on the old event block
+my $old_status = 
+         LSAE::AnalysisEventBlock-&gt;new(
+                 $WSRF::WSRP::ResourceProperties{$property_status}
+         );
+
+
+# construct a new state changed event
+my $status = LSAE::AnalysisEventBlock-&gt;new();<br />$status-&gt;type(LSAE_STATE_CHANGED_EVENT);
+# set the previous state<br />$status-&gt;previous_state( $old_status-&gt;new_state() );
+# set the new state<br />$status-&gt;new_state('running');
+# set our job id for this event<br />$status-&gt;id($jid);
+
+
+# create a file based resource that we will store our event information
+my $lock = WSRF::MobyFile-&gt;new( undef, $ID );<br />$WSRF::WSRP::ResourceProperties{$property_status} = $status-&gt;XML();
+# here we leave the result empty since the service is still running<br />$WSRF::WSRP::ResourceProperties{$property_result} = '';
+# save the event so that our clients can access the information
+$lock-&gt;toFile();</pre>
+<blockquote>
+  <p>&nbsp;</p>
+</blockquote>
 <p>That's all there is to constructing asynchronous CGI based Perl MoSeS services!</p>
 </body>
 </html>




More information about the MOBY-guts mailing list