Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7546495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:12:47+00:00 2026-05-30T09:12:47+00:00

In my Mojolicious perl code I handle a jobs created and watched from a

  • 0

In my Mojolicious perl code I handle a jobs created and watched from a remote client.

I keep the jobs in a array of hashes, which is a global variable.

It is then used in handlers of PUT ‘/job/create’ and GET ‘/job/status’.
When adding a new job with the PUT ‘/job/create’ the array gets
extended in the subroutine (it contains 4 elements in the code below),
but when requesting the jobs’ status via GET ‘/job/status’ the list of
jobs, the array does not contain the added elements (it counts 2
elements).

Thanks, Jan

Here is the code:

#!/usr/bin/perl -w

use threads; 
use threads::shared; 
use Mojolicious::Lite; 
use Mojo::JSON; 
my (%record, %job1, %job2, %job3, @jobs) : shared; 

%job1 = ( id=>"id1"); 
%job2 = ( id=>"id2"); 
%job3 = ( id=>"id3"); 

push ( @jobs, \%job1 ); 
push ( @jobs, \%job2 ); 

app->config(hypnotoad => {listen => ['http://*:3000']}); 

put '/job/create' => sub { 
    my $self = shift; 
    my $obj = Mojo::JSON->decode( $self->req->body ); 
    my $id = $obj->{id}; 
    %record = (id => $id); 
    push ( @jobs, \%record ); # test the global prefilled 
    push ( @jobs, \%job3 );   # test the global locally filled 
    $self->render(text => "Created job id $id. Jobs count: " . 
$#jobs ); 
}; 

get '/job/status' => sub { 
    my $self = shift; 
    my $out = "["; 
    for(my $i=0; $i<$#jobs+1; $i++) { 
        $out .= "{id:\""  . $jobs[$i]{id}      . "\","; 
        $out .= "," if $i<$#jobs; 
    } 
    $out .= "]"; 
    $self->render(text => "allJobsInfo($out). Num jobs: " . $#jobs); 
};

app->start();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:12:49+00:00Added an answer on May 30, 2026 at 9:12 am

    This won’t really work, as hypnotoad is using fork, not threads. I suggest storing data in something like a database or Cache::FastMmap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the Mojolicious::Lite module to run a websockets server to handle the
From the Mojolicious wiki on the topic of Database support: Although SQL::Abstract looks like
I have the following code in my Mojolicious application module. When I run this
I’d like to match any GET request in Mojolicious::Lite. The code looks like this:
In a Mojolicious app I have a route in my Controller code like the
We have created the following simple Mojolicious controller: package SampleApp::Pages; # $Id$ use strict;
How do i set a cookie in mojolicious response and later read it from
I have some Mojolicious-based apps which happily run under Apache2 with mod_cgi and mod_fastcgi.
#!/usr/local/bin/perl use warnings; use 5.014; use Mojolicious::Lite; use DBI; # ... get '/choose' =>
That is from the apache error_log: [Mon Oct 17 17:55:42 2011] [error] [client 127.0.0.1]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.