3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-25 04:02:37 +01:00

Factoids can now be run as background processes and have process-timeout override

This commit is contained in:
Pragmatic Software 2020-02-16 16:31:06 -08:00
parent a63a5308d5
commit 891a586409
2 changed files with 17 additions and 1 deletions

View File

@ -845,7 +845,17 @@ sub interpreter {
return "";
}
return $self->handle_action($stuff, $action);
if ($self->{factoids}->get_data($channel, $keyword, 'background-process')) {
my $timeout = $self->{factoids}->get_data($channel, $keyword, 'process-timeout') // $self->{pbot}->{registry}->get_value('processmanager', 'default_timeout');
$self->{pbot}->{process_manager}->execute_process(
$stuff,
sub { $stuff->{result} = $self->handle_action($stuff, $action); },
$timeout
);
return "";
} else {
return $self->handle_action($stuff, $action);
}
}
sub handle_action {

View File

@ -148,6 +148,12 @@ sub execute_process {
if (not exists $stuff->{commands}) { $stuff->{commands} = [$stuff->{command}]; }
# don't fork again if we're already a forked process
if (exists $stuff->{pid}) {
$subref->($stuff);
return $stuff->{result};
}
pipe(my $reader, my $writer);
$stuff->{pid} = fork;