chiark / gitweb /
manager: print ephemeral information about running jobs' timeouts (v2)
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 28 Jan 2014 23:25:39 +0000 (18:25 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 29 Jan 2014 00:07:13 +0000 (19:07 -0500)
This reverts commit 28c758de94bc8ba97b89d9dab3f517cf466978d0
but makes job_coldplug smarter.

In (v1) I changed the job start timestamp to be always set, so the
start time can be reported in the cylon eye message.  The bug was that
when deserializing jobs, they would be ignored if their start
timestamp was unset which was synonymous with no timeout. But after
the change, jobs would have a start timestamp set despite having no
timeout. After deserialization they would be considered immediately
expired. Fix this by checking if the timeout is not zero when
considering jobs for expiration.

src/core/job.c
src/core/manager.c

index 1bcf4968e2c5df0d31e59b0f771efd0382cfb2bc..941f9560258518f493f71c73c896947d1a22ea47 100644 (file)
@@ -864,11 +864,14 @@ static int job_dispatch_timer(sd_event_source *s, uint64_t monotonic, void *user
 int job_start_timer(Job *j) {
         int r;
 
 int job_start_timer(Job *j) {
         int r;
 
-        if (j->unit->job_timeout <= 0 || j->timer_event_source)
+        if (j->timer_event_source)
                 return 0;
 
         j->begin_usec = now(CLOCK_MONOTONIC);
 
                 return 0;
 
         j->begin_usec = now(CLOCK_MONOTONIC);
 
+        if (j->unit->job_timeout <= 0)
+                return 0;
+
         r = sd_event_add_monotonic(j->manager->event, j->begin_usec + j->unit->job_timeout, 0, job_dispatch_timer, j, &j->timer_event_source);
         if (r < 0)
                 return r;
         r = sd_event_add_monotonic(j->manager->event, j->begin_usec + j->unit->job_timeout, 0, job_dispatch_timer, j, &j->timer_event_source);
         if (r < 0)
                 return r;
@@ -1048,7 +1051,7 @@ int job_coldplug(Job *j) {
 
         assert(j);
 
 
         assert(j);
 
-        if (j->begin_usec <= 0)
+        if (j->begin_usec == 0 || j->unit->job_timeout == 0)
                 return 0;
 
         if (j->timer_event_source)
                 return 0;
 
         if (j->timer_event_source)
index f7f8fa697a311d2e699be816e4837f42dd080f36..edde1091c403527ec41a72698277d6ce447298ad 100644 (file)
@@ -153,6 +153,8 @@ static void manager_print_jobs_in_progress(Manager *m) {
         unsigned counter = 0, print_nr;
         char cylon[6 + CYLON_BUFFER_EXTRA + 1];
         unsigned cylon_pos;
         unsigned counter = 0, print_nr;
         char cylon[6 + CYLON_BUFFER_EXTRA + 1];
         unsigned cylon_pos;
+        char time[FORMAT_TIMESPAN_MAX], limit[FORMAT_TIMESPAN_MAX] = "no limit";
+        uint64_t x;
 
         assert(m);
 
 
         assert(m);
 
@@ -174,14 +176,23 @@ static void manager_print_jobs_in_progress(Manager *m) {
                 cylon_pos = 14 - cylon_pos;
         draw_cylon(cylon, sizeof(cylon), 6, cylon_pos);
 
                 cylon_pos = 14 - cylon_pos;
         draw_cylon(cylon, sizeof(cylon), 6, cylon_pos);
 
+        m->jobs_in_progress_iteration++;
+
         if (m->n_running_jobs > 1)
                 if (asprintf(&job_of_n, "(%u of %u) ", counter, m->n_running_jobs) < 0)
                         job_of_n = NULL;
 
         if (m->n_running_jobs > 1)
                 if (asprintf(&job_of_n, "(%u of %u) ", counter, m->n_running_jobs) < 0)
                         job_of_n = NULL;
 
-        manager_status_printf(m, true, cylon, "%sA %s job is running for %s",
-                              strempty(job_of_n), job_type_to_string(j->type), unit_description(j->unit));
+        format_timespan(time, sizeof(time), now(CLOCK_MONOTONIC) - j->begin_usec, 1*USEC_PER_SEC);
+        if (job_get_timeout(j, &x) > 0)
+                format_timespan(limit, sizeof(limit), x - j->begin_usec, 1*USEC_PER_SEC);
+
+        manager_status_printf(m, true, cylon,
+                              "%sA %s job is running for %s (%s / %s)",
+                              strempty(job_of_n),
+                              job_type_to_string(j->type),
+                              unit_description(j->unit),
+                              time, limit);
 
 
-        m->jobs_in_progress_iteration++;
 }
 
 static int manager_watch_idle_pipe(Manager *m) {
 }
 
 static int manager_watch_idle_pipe(Manager *m) {