Bug 31203: Add End action to cronjobs and log viewer
[koha-ffzg.git] / misc / background_jobs_worker.pl
index f10880d..eb36f34 100755 (executable)
@@ -90,7 +90,7 @@ while (1) {
         }
 
         my $body = $frame->body;
-        my $args = decode_json($body);
+        my $args = decode_json($body); # TODO Should this be from_json? Check utf8 flag.
 
         # FIXME This means we need to have create the DB entry before
         # It could work in a first step, but then we will want to handle job that will be created from the message received
@@ -102,7 +102,7 @@ while (1) {
     } else {
         my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues });
         while ( my $job = $jobs->next ) {
-            my $args = decode_json($job->data);
+            my $args = $job->json->decode($job->data);
             process_job( $job, { job_id => $job->id, %$args } );
         }
         sleep 10;
@@ -121,20 +121,7 @@ sub process_job {
 
     die "fork failed!" unless defined $pid;
 
-    my $patron = Koha::Patrons->find($job->borrowernumber);
-    if ( $patron ) {
-        C4::Context->_new_userenv(-1);
-        C4::Context->set_userenv(
-            $patron->borrowernumber,      $patron->userid,
-            $patron->cardnumber,          $patron->firstname,
-            $patron->surname,            $patron->branchcode,
-            $patron->library->branchname, $patron->flags
-        );
-        $job->process( $args );
-        C4::Context->_unset_userenv(-1);
-    } ese {
-        $job->process( $args );
-    }
+    $job->process( $args );
 
     exit;
 }