]> iEval git - gruntmaster-daemon.git/commitdiff
Send POST request to remote address with job result
authorAndreiTocu <tocuandrei39@gmail.com>
Fri, 2 Oct 2020 11:13:12 +0000 (14:13 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sun, 17 Apr 2022 18:38:24 +0000 (21:38 +0300)
lib/Gruntmaster/Daemon.pm
lib/Gruntmaster/SendResults.pm [new file with mode: 0644]

index 1c820dbe6429c508946e89c80fee3d77b76c1106..ef24364184c6ef403ae898acee7d2cf7046c2af3 100644 (file)
@@ -8,6 +8,7 @@ our $VERSION = '5999.000_005';
 
 use Gruntmaster::Daemon::Constants qw/ERR/;
 use Gruntmaster::Daemon::Format qw/prepare_files stopvms/;
+use Gruntmaster::SendResults qw/send_results_request/;
 
 use File::Slurp qw/read_file/;
 use File::Temp qw/tempdir/;
@@ -110,6 +111,7 @@ sub process{
        $meta->{errors} = $errors;
 
        get_logger->info('Job result: ' . $meta->{result_text});
+       send_results_request($meta->{job_id}, $meta->{result}, $meta->{result_text});
 }
 
 sub process_job {
@@ -138,6 +140,7 @@ sub process_job {
                format => $pb->{verformat},
                content => $pb->{versource},
        } if $pb->{verformat};
+       $meta->{job_id} = $job->{id};
 
        process $meta;
 
diff --git a/lib/Gruntmaster/SendResults.pm b/lib/Gruntmaster/SendResults.pm
new file mode 100644 (file)
index 0000000..e01a9a6
--- /dev/null
@@ -0,0 +1,36 @@
+package Gruntmaster::SendResults;
+
+use 5.014000;
+use strict;
+use warnings;
+use parent qw/Exporter/;
+
+use HTTP::Request;
+use JSON qw/encode_json decode_json/;
+use LWP::UserAgent;
+
+our $VERSION = '5999.000_005';
+our @EXPORT_OK = qw/send_results_request/;
+
+sub send_results_request {
+  my ($job_id, $result, $result_text) = @_;
+
+  my $url = $ENV{REMOTE_ADDRESS};
+  my $header = [
+    'Content-Type' => 'application/json'
+  ];
+  my $data = {
+    gm_id => $job_id,
+    result => $result,
+    result_text => $result_text
+  };
+
+  my $encoded_data = encode_json($data);
+  my $request = HTTP::Request->new(POST => $url, $header, $encoded_data);
+  my $ua = LWP::UserAgent->new();
+  my $response = $ua->request($request);
+
+  return $response;
+}
+
+1;
This page took 0.028492 seconds and 4 git commands to generate.