Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4aa43898

Von Moritz Bunkus vor mehr als 5 Jahren hinzugefügt

  • ID 4aa438985bc3b8d48c1350fe729c1ee25548b613
  • Vorgänger c2efc4a8
  • Nachfolger a4d4aaa1

Task-Server: CLI-Option zur Ausführung eines einzelnen Jobs

Führt einen einen bestimmten Job exakt einmal aus, egal, ob der Job
aktiv ist oder was sein nächstes Ausführungsdatum ist. Anschließend
beendet sich der Task-Server wieder.

Das Argument ist die Datenbank-ID aus Tabelle »background_jobs«.

Beispiel:

./scripts/task_server.pl debug --run-job=42

Unterschiede anzeigen:

scripts/task_server.pl
38 38
use Template;
39 39

  
40 40
our %lx_office_conf;
41
our $run_single_job;
41 42

  
42 43
sub debug {
43 44
  return if !$lx_office_conf{task_server}->{debug};
......
224 225
  return ();
225 226
}
226 227

  
228
sub run_single_job_for_all_clients {
229
  initialize_kivitendo();
230

  
231
  my $clients = enabled_clients();
232

  
233
  foreach my $client (@{ $clients }) {
234
    debug("Running single job ID $run_single_job for client ID " . $client->id . " (" . $client->name . ")");
235

  
236
    my $ok = eval {
237
      initialize_kivitendo($client);
238

  
239
      my $job = SL::DB::Manager::BackgroundJob->find_by(id => $run_single_job);
240

  
241
      if ($job) {
242
        debug(" Executing the following job: " . $job->package_name);
243
      } else {
244
        debug(" No jobs to execute found");
245
        next;
246
      }
247

  
248
      # Provide fresh global variables in case legacy code modifies
249
      # them somehow.
250
      initialize_kivitendo($client);
251

  
252
      my $history = $job->run;
253

  
254
      debug("   Executed job " . $job->package_name .
255
            "; result: " . (!$history ? "no return value" : $history->has_failed ? "failed" : "succeeded") .
256
            ($history && $history->has_failed ? "; error: " . $history->error_col : ""));
257

  
258
      notify_on_failure(history => $history) if $history && $history->has_failed;
259

  
260
      1;
261
    };
262

  
263
    if (!$ok) {
264
      my $error = $EVAL_ERROR;
265
      debug("Exception during execution: ${error}");
266
      notify_on_failure(exception => $error);
267
    }
268

  
269
    cleanup_kivitendo();
270
  }
271
}
272

  
227 273
sub run_once_for_all_clients {
228 274
  initialize_kivitendo();
229 275

  
......
271 317
}
272 318

  
273 319
sub gd_run {
320
  if ($run_single_job) {
321
    run_single_job_for_all_clients();
322
    return;
323
  }
324

  
274 325
  while (1) {
275 326
    $SIG{'ALRM'} = 'IGNORE';
276 327

  
......
295 346
  }
296 347
}
297 348

  
349
sub gd_flags_more {
350
  return (
351
    '--run-job=<id>' => 'Run the single job with the database ID <id> no matter if it is active or when its next execution is supposed to be; the daemon will exit afterwards',
352
  );
353
}
354

  
298 355
$exe_dir = SL::System::Process->exe_dir;
299 356
chdir($exe_dir) || die "Cannot change directory to ${exe_dir}\n";
300 357

  
......
309 366
newdaemon(configfile => $file,
310 367
          progname   => 'kivitendo-background-jobs',
311 368
          pidbase    => SL::System::TaskServer::PID_BASE() . '/',
369
          options    => {
370
            'run-job=i' => \$run_single_job,
371
          },
312 372
          );
313 373

  
314 374
1;

Auch abrufbar als: Unified diff