App-mqtt2job
view release on metacpan or search on metacpan
bin/mqtt2job view on Meta::CPAN
$helper_script = helper_v1($obj);
}
# Yee-ha!
system(join(" ", $opt->shebang, $helper_script, "&"));
$msg .= "- running $helper_script";
} else {
$msg = "Unknown command requested";
}
print STDERR "$msg: $topic - $message\n";
}
sub _cmd_ok {
my $cmd = shift;
# example command checker
$cmd =~ s/[^\w\-\.]//g;
return (-f $opt->job_dir . "/" . $cmd) ? 1 : undef;
}
__END__
=pod
=encoding UTF-8
=head1 NAME
mqtt2job - Subscribe to an MQTT topic and trigger job execution
=head1 VERSION
version 0.03
=head1 SYNOPSIS
mqtt2job --mqtt_server mqtt.example.com --base_topic my/topic --job_dir /apps
=head1 DESCRIPTION
Subscribes to the my/topic/job mqtt topic and upon receiving a
correctly formatted json message will fork and run the requested
job in a wrapper script providing it is present and executable in
the job_dir directory.
This wrapper will generate two child mqtt messages under the base
topic, at my/topic/status. Message one is sent when the job is
initiated. The second is sent when the job has completed (or timed
out). This second message will also include any output from the job
amongst various other metadata (e.g. execution datetime, duration,
timeout condition, etc.)
=head1 NAME
App::mqtt2job - Subscribe to an MQTT topic and trigger job execution
=head1 FOR THE LOVE OF ALL THAT IS SACRED, WHY?
This is part one of my "Cursed Solutions" series, URL to be added
later when I've uploaded it.
=head1 COPYRIGHT
Copyright 2024 -- Chris Carline
=head1 LICENSE
This software is licensed under the same terms as Perl.
=head1 NO WARRANTY
This software is provided "as is" without any express or implied
warranty. Using it for any reason whatsoever is probably an
extremely bad idea and it should only ever be considered if you
understand the potential consequences. In no event shall the
author be held liable for any damages arising from the use of
this software. It is provided for demonstration purposes only.
=head1 AUTHOR
Chris Carline <chris@carline.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2024 by Chris Carline.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
( run in 0.811 second using v1.01-cache-2.11-cpan-b16cb0d3907 )