Brief description:
When I do a hot deployment of Hypnotoad, sometimes a new server immediately processes a lot of HTTP requests that have already been processed by the previous server.
If the response has been processed but the thread is still doing some processing, does Mojo / Hypnotoad keep the request until the processing stops? Do I need to tell the server that the HTTP request is allowed?
Long version:
I have a Mojolicious :: Lite application running under Hypnotoad. The function of the application is to accept HTTP requests from another service.
We process jobs that go through a series of conditions. Each time the status of a job changes, the application is notified by an HTTP request. This is a busy little script - getting over 1000 req / hour.
Scripting is the manipulation of some data. Performing database updates, editing files, sending mail.
In an attempt to keep things moving, when he receives an HTTP request, he checks the received data. If the data looks good, it immediately sends a 200 response, and then continues to perform more time-consuming tasks. (I guess this is the main reason)
When I deploy it hot - restarting the script (which runs "localperl / bin / hypnotoad $ RELDIR / etc / bki / bki.pl") - some requests that have already been processed are sent to the new server and processed.
? !
Mojolicious, , ?
( $c- > finish(), ?)
Hypnotoad , ?
psuedo , :
get '/jobStateChange/:jobId/:jobState/:jobCause' => sub {
my $c =shift;
my $jobId = $c->stash("jobId");
return $c->render(text => "invalid jobId: $jobId", status => 400) unless $jobId=~/^\d+$/;
my $jobState = $c->stash("jobState");
return $c->render(text => "invalid jobState: $jobState", status => 400) unless $jobState=~/^\d+$/;
my $jobCause = $c->stash("jobCause");
return $c->render(text => "invalid jobCause: $jobCause", status => 400) unless $jobCause=~/^\d+$/;
my $jobLocation = $c->req->param('jobLocation');
if ($jobLocation){ $jobLocation = $ENV{'DATADIR'} . "/jobs/" . $jobLocation; }
unless ( $jobLocation && -d $jobLocation ){
app->log->debug("determining jobLocation because passed job jobLocation isn't useable");
$jobLocation = getJobLocation($jobId);
$c->stash("jobLocation", $jobLocation);
}
return if $c->tx->res->code && 400 == $c->tx->res->code;
$c->render(text => 'ok');
handleJobStatusUpdate($c, $jobId, $jobState, $jobCause, $jobLocation);
};
sub handleJobStatusUpdate{
my ($c, $jobId, $jobState, $jobCause, $jobLocation) = @_;
app->log->info("job $jobId, state $jobState, cause $jobCause, loc $jobLocation");
app->work_db->do($sql, undef, @params);
if ($jobState == $SOME_JOB_STATE) {
... do stuff ...
... uses $c->stash to hold data used by other functions
}
if ($jobState == $OTHER_JOB_STATE) {
... do stuff ...
... uses $c->stash to hold data used by other functions
}
}