[Mojolicious] Re: how to run bash script in nonblocking mode?

2018-04-24 Thread Daniel Mantovani
Hi tj, I really don't know what could be the issue. Maybe some lock inside 
the bach program or something like that.

Anyway, you could try this simple mojo app to see that subprocesses should 
not block among them:

#!/usr/bin/env perl
> use Mojolicious::Lite;
>
> get '/:n' => sub {
> my $c = shift;
> $c->inactivity_timeout(180);
> my $n = $c->param('n');
> my $sp = Mojo::IOLoop::Subprocess->new;
> $sp->run(
> sub { `sleep $n` },
> sub {
> my $pid = shift->pid;
> $c->render( text =>
> "Subprocess with pid $pid finished after waiting $n segs\n" );
> }
> );
> };
>
> app->start;
>
>
Just run it with morbo, and then from one browser window go to 
http://localhost:3000/30, and from other browser window go for instance to 
http://localhost:3000/1, etc

You should be able to run many of them simultaneously, and the pids for 
each subprocess should be different.

BR,

El martes, 24 de abril de 2018, 10:49:46 (UTC-3), Caveman Pl escribió:
>
> Hi Daniel,
>
> I found that it works but only once.
>
> When I run batch via web page it is launched an it does its work. And web 
> page is working.
> But when I run second batch whens first one is still working web page 
> hangs until second one finisz its work.
> Do you know why is that? and how could it be fixed? 
>
> Thank you,
>
> tj
>
>
> W dniu niedziela, 22 kwietnia 2018 18:35:34 UTC+2 użytkownik Daniel 
> Mantovani napisał:
>
>> Hi tj, I understand that for the run 
>>  method both subs 
>> are required. If you don't want to do anything when the batch finish, the 
>> second one could be just sub {} 
>>
>> i.e.
>>
>>> $subprocess->run(sub { `sh runImportPhen`}, sub {});
>>
>>
>> BR,
>>
>> El sábado, 21 de abril de 2018, 15:46:43 (UTC-3), Caveman Pl escribió:
>>>
>>> Hi group,
>>>
>>>
>>> I just want to run bash script and forget about it.
>>>
>>> I was trying just put it in backgrount with '&' sign
>>> `sh runImportPhen &`;
>>> but it  doesn't work.
>>>
>>> Because of it I'm trying with Mojo::IOLoop
>>>
>>> Pdataexport.pm--
>>> package MyApp::Pdataexport;
>>>
>>> use base 'Mojolicious::Controller';
>>> use Date::Calc qw(:all);
>>> use File::Path qw(make_path remove_tree);
>>> use Mojo::IOLoop;
>>>
>>>
>>> sub importExternalPhenotypes{
>>>
>>>...prepare runImportPhen.sh script...
>>>
>>> my $delay = Mojo::IOLoop->delay;
>>>$delay->steps(
>>>sub {
>>>my $delay = shift;
>>>`sh runImportPhen `;
>>>}
>>>);
>>> $self->redirect_to('/pdataexport');
>>> }
>>>
>>> code above also doesn't work. When I click buton which run  
>>> importExternalPhenotypes subroutine I need to wait until bash script ends 
>>> work - (web page hangs until it finisz)
>>>
>>> I was trying also with
>>>
>>> sub importExternalPhenotypes{
>>>
>>>...prepare runImportPhen.sh script...
>>>
>>>
>>> my $subprocess = Mojo::IOLoop::Subprocess->new;
>>> $subprocess->run(
>>>   sub {
>>> my $subprocess = shift;
>>>`sh runImportPhen `;
>>>   }
>>> $self->redirect_to('/pdataexport');
>>> );
>>>
>>>
>>>
>>> but it crash...
>>>
>>> Can you please provide some simple example code how it should be done?
>>>
>>> Thank you,
>>>
>>> tj
>>>
>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Accessing SQLite database from two different modules

2018-04-24 Thread Dan Book
Even with write-ahead logging, committing a transaction or running a data
update outside a transaction should be immediately reflected in any other
readers -- as long as they run the read query after the commit/update has
completed. The ability to read while another connection is writing (and see
the state unaffected by the transaction) is the primary purpose of WAL mode.

I don't see any issue with what you presented so far, but more important
would be to see how you are running updates or transactions.

-Dan

On Tue, Apr 24, 2018 at 6:48 PM, mimosinnet  wrote:

> After writing a Mojolicious application
>  in Mojo::SQLite,
> some transactions doesn't seem to be immediately committed to the database.
> I wonder if this is related to SQLite Write-Ahead Logging
>  or how I have defined Mojo::SQLite (I am
> afraid it is the latter  :(  ). This is the logic I have followed:
>
> --> As some modules need to access the database, I have defined a module
> that loads the database
> 
> :
>
> *package GestioMaster::Obj::DB;*
> use Mojo::Base -base;
>
> use Mojo::SQLite;
> use GestioMaster::Model::DB;
>
> has sqlite => sub { Mojo::SQLite->new('sqlite:db/master.db') };
>
> has model  => sub {
> my $self = shift;
> return GestioMaster::Model::DB->new( sqlite =>  $self->sqlite );
> };
>
> --> This module is used when loading the application
> 
> :
>
> package GestioMaster;
> use Mojo::Base 'Mojolicious';
> *use GestioMaster::Obj::DB;*
>
> sub startup {
>   my $self = shift;
>   my $config = $self->plugin('Config');
>   $self->helper( model => sub {
> state $model = GestioMaster::Obj::DB->new->model;
>});
> ...
>
> --> Accessing the database is defined in the Model
> 
> :
>
> package GestioMaster::Model::DB;
> use Mojo::Base -base;
> has 'sqlite';
> ...
> sub un_modul {
> my ($self, $modul) = @_;
> return $self->sqlite->db->select('moduls',undef,{ modul => $modul})->hash;
> }
> ...
>
> --> The same module is also used to define registers from the database
> 
> :
>
> package *GestioMaster::Obj::Modul*;
> use Mojo::Base -base;
> # Object that makes database available
> *use GestioMaster::Obj::DB;*
>
> has _model => sub { GestioMaster::Obj::DB->new->model  };
> has modul => "";
>
> has un_modul => sub {
> my $self = shift;
> return $self->_model->un_modul( $self->modul );
> };
>
> has ident => sub { shift->un_modul->{'ident'} };
> has coord => sub { shift->un_modul->{'coord'} };
> has nom_modul => sub { shift->un_modul->{'nom_modul'}; };
> ...
>
>
> --> This builds an array-ref of registers
> 
> :
>
> package GestioMaster::Controller::Moduls::Modul;
> use Mojo::Base -base;
> use *GestioMaster::Obj::Modul*;
>
> has moduls => sub {
> my $self = shift;
> my @moduls = qw/M1 M2a M2b M3a M3b M3d M3e M4 M5a M5b M5c M5d M6/;
> my $mod_obj = [];
> foreach my $mod ( @moduls  ) {
> push @{$mod_obj}, *GestioMaster::Obj::Modul*->new( modul => $mod );
> }
> return $mod_obj;
> };
>
> d) Used in the controller
> 
> :
>
> package GestioMaster::Controller::Public;
> use GestioMaster::Controller::Moduls::Modul;
> state $moduls = GestioMaster::Controller::Moduls::Modul->new->moduls;
>
> sub inici  { shift->render( moduls => $moduls ) }
>
>
> e) That promised straightforward templates
> 
> :
>
> % foreach my $mod ( @{ $moduls } ) {
> <%= $mod->modul . ": " .
> $mod->nom_modul %>
> % }
>
>
> So far so good, till the application started to write to the database and
> noticed some transactions were not immediately committed :O
>
>
> My questions:
>
> a) Opening the database in two different modules has an effect on how
> transactions are committed?
> b) Could this be solved by "Application-Initiated Checkpoints
> "?
> c) If the application has to be rewritten, how can the database defined
> in package *GestioMaster* be accessed from *GestioMaster::Obj::Modul*?
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mojolicious+unsubscr...@googlegroups.com.
> To post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at 

[Mojolicious] Accessing SQLite database from two different modules

2018-04-24 Thread mimosinnet
After writing a Mojolicious application 
 in Mojo::SQLite, some 
transactions doesn't seem to be immediately committed to the database. I 
wonder if this is related to SQLite Write-Ahead Logging 
 or how I have defined Mojo::SQLite (I am 
afraid it is the latter  :(  ). This is the logic I have followed:

--> As some modules need to access the database, I have defined a module 
that loads the database 

:

*package GestioMaster::Obj::DB;*
use Mojo::Base -base;

use Mojo::SQLite;
use GestioMaster::Model::DB;

has sqlite => sub { Mojo::SQLite->new('sqlite:db/master.db') };

has model  => sub {
my $self = shift;
return GestioMaster::Model::DB->new( sqlite =>  $self->sqlite );
};

--> This module is used when loading the application 

:

package GestioMaster;
use Mojo::Base 'Mojolicious';
*use GestioMaster::Obj::DB;*

sub startup {
  my $self = shift;
  my $config = $self->plugin('Config');
  $self->helper( model => sub { 
state $model = GestioMaster::Obj::DB->new->model;
   });
...

--> Accessing the database is defined in the Model 

: 

package GestioMaster::Model::DB;
use Mojo::Base -base;
has 'sqlite';
...
sub un_modul {
my ($self, $modul) = @_;
return $self->sqlite->db->select('moduls',undef,{ modul => $modul})->hash;
}
...

--> The same module is also used to define registers from the database 

:

package *GestioMaster::Obj::Modul*;
use Mojo::Base -base;
# Object that makes database available
*use GestioMaster::Obj::DB;*

has _model => sub { GestioMaster::Obj::DB->new->model  };
has modul => "";

has un_modul => sub { 
my $self = shift;
return $self->_model->un_modul( $self->modul );
};

has ident => sub { shift->un_modul->{'ident'} };
has coord => sub { shift->un_modul->{'coord'} };
has nom_modul => sub { shift->un_modul->{'nom_modul'}; };
...


--> This builds an array-ref of registers 

:

package GestioMaster::Controller::Moduls::Modul;
use Mojo::Base -base;
use *GestioMaster::Obj::Modul*;

has moduls => sub {
my $self = shift;
my @moduls = qw/M1 M2a M2b M3a M3b M3d M3e M4 M5a M5b M5c M5d M6/;
my $mod_obj = [];
foreach my $mod ( @moduls  ) {
push @{$mod_obj}, *GestioMaster::Obj::Modul*->new( modul => $mod );
}
return $mod_obj;
};

d) Used in the controller 

:

package GestioMaster::Controller::Public;
use GestioMaster::Controller::Moduls::Modul;
state $moduls = GestioMaster::Controller::Moduls::Modul->new->moduls;

sub inici  { shift->render( moduls => $moduls ) }


e) That promised straightforward templates 

: 

% foreach my $mod ( @{ $moduls } ) {
<%= $mod->modul . ": " . 
$mod->nom_modul %>
% }


So far so good, till the application started to write to the database and 
noticed some transactions were not immediately committed :O


My questions:

a) Opening the database in two different modules has an effect on how 
transactions are committed?
b) Could this be solved by "Application-Initiated Checkpoints 
"?
c) If the application has to be rewritten, how can the database defined 
in package *GestioMaster* be accessed from *GestioMaster::Obj::Modul*?

Thanks! 

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


[Mojolicious] Re: [SECURITY] Windows is no longer officially supported

2018-04-24 Thread sri
Quick update, the secuity issue has been confirmed. We do have a path
traversal vulnerability on Windows and there is no known fix yet. So, please
make sure not to use Windows!

--
sebastian

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


[Mojolicious] Re: how to run bash script in nonblocking mode?

2018-04-24 Thread Caveman Pl
Hi Daniel,

I found that it works but only once.

When I run batch via web page it is launched an it does its work. And web 
page is working.
But when I run second batch whens first one is still working web page hangs 
until second one finisz its work.
Do you know why is that? and how could it be fixed? 

Thank you,

tj


W dniu niedziela, 22 kwietnia 2018 18:35:34 UTC+2 użytkownik Daniel 
Mantovani napisał:

> Hi tj, I understand that for the run 
>  method both subs 
> are required. If you don't want to do anything when the batch finish, the 
> second one could be just sub {} 
>
> i.e.
>
>> $subprocess->run(sub { `sh runImportPhen`}, sub {});
>
>
> BR,
>
> El sábado, 21 de abril de 2018, 15:46:43 (UTC-3), Caveman Pl escribió:
>>
>> Hi group,
>>
>>
>> I just want to run bash script and forget about it.
>>
>> I was trying just put it in backgrount with '&' sign
>> `sh runImportPhen &`;
>> but it  doesn't work.
>>
>> Because of it I'm trying with Mojo::IOLoop
>>
>> Pdataexport.pm--
>> package MyApp::Pdataexport;
>>
>> use base 'Mojolicious::Controller';
>> use Date::Calc qw(:all);
>> use File::Path qw(make_path remove_tree);
>> use Mojo::IOLoop;
>>
>>
>> sub importExternalPhenotypes{
>>
>>...prepare runImportPhen.sh script...
>>
>> my $delay = Mojo::IOLoop->delay;
>>$delay->steps(
>>sub {
>>my $delay = shift;
>>`sh runImportPhen `;
>>}
>>);
>> $self->redirect_to('/pdataexport');
>> }
>>
>> code above also doesn't work. When I click buton which run  
>> importExternalPhenotypes subroutine I need to wait until bash script ends 
>> work - (web page hangs until it finisz)
>>
>> I was trying also with
>>
>> sub importExternalPhenotypes{
>>
>>...prepare runImportPhen.sh script...
>>
>>
>> my $subprocess = Mojo::IOLoop::Subprocess->new;
>> $subprocess->run(
>>   sub {
>> my $subprocess = shift;
>>`sh runImportPhen `;
>>   }
>> $self->redirect_to('/pdataexport');
>> );
>>
>>
>>
>> but it crash...
>>
>> Can you please provide some simple example code how it should be done?
>>
>> Thank you,
>>
>> tj
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.