Sub::Slice

Split long-running tasks into manageable chunks
Download

Sub::Slice Ranking & Summary

Advertisement

  • Rating:
  • License:
  • GPL
  • Price:
  • FREE
  • Publisher Name:
  • BBC
  • Publisher web site:
  • http://www.bbc.co.uk

Sub::Slice Tags


Sub::Slice Description

Split long-running tasks into manageable chunks Sub::Slice is a Perl module that breaks up a long process into smaller chunks that can be executed one at a time over a stateless protocol such as HTTP/SOAP so that progress may be reported. This means that the client can display progress or cancel the operation part-way through.It works by the client requesting a token from the server, and passing the token back to the server on each iteration. The token passed to the client contains status information which the client can use to determine if the job has completed/failed and to display status/error messages.Within the routine called on each iteration, the server defines a set of coderefs, one of which will be called for a given iteration. In addition the server may define coderefs to be called at the start and end of the job. The server may provide the client with an estimate of the number of iterations the job is likely to take.It is possible to balance performance/usability by modifying the number of iterations that will be executed before returning progress to the client.SYNOPSIS # Client # Assume methods in the Server:: package are magically remoted my $token = Server::create_token(); for(1 .. MAX_ITERATIONS) { Server::do_work($token); last if $token->{done}; } # Server # Imagine this is on a remote machine package Server; use Sub::Slice; sub create_token { # create a new job: my $job = new Sub::Slice( backend => 'Filesystem', storage_options => { path => '/var/tmp/myproject/', } ); return $job->token; } sub do_work { # loading an existing job: my $job = new Sub::Slice( token => $token backend => 'Filesystem', storage_options => { path => '/var/tmp/myproject/', } ); at_start $job sub { $job->store('foo', '1'); $job->store('bar', { abc = > 'def' }); # store data, initialise $job->set_estimate(10); # estimate number of steps return ( $job->fetch('foo') ); }; my $foo = $job->fetch('foo'); at_stage $job "stage_one", sub { my $bar = $job->fetch('bar'); # do stuff $job->next_stage('stage_two') if $some_condition; }; at_stage $job "stage_two", sub { # ...do more stuff... # mark job as ready to be deleted $job->done() if $job->count() == $job->estimate(); }; return $job->return_value(); #Pass back any return value from coderefs } Requirements: · Perl


Sub::Slice Related Software