]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
replicator: Add "next sync secs" field to doveadm replicator status
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 25 Oct 2022 12:39:39 +0000 (15:39 +0300)
committerMartti Rannanjärvi <martti.rannanjarvi@open-xchange.com>
Wed, 2 Nov 2022 13:53:07 +0000 (15:53 +0200)
src/doveadm/doveadm-replicator.c
src/replication/replicator/doveadm-connection.c

index 17af8b9cbc38d6bd69c7d155cc3d119a932a0691..57cb972ae1d0f7c68515c405b9d1b423abb058f6 100644 (file)
@@ -92,14 +92,19 @@ cmd_replicator_init(struct doveadm_cmd_context *cctx)
        return ctx;
 }
 
+static const char *time_formatted_hms(unsigned int secs)
+{
+       return t_strdup_printf("%02d:%02d:%02d", secs/3600,
+                              (secs/60)%60, secs%60);
+}
+
 static const char *time_ago(time_t t)
 {
        int diff = ioloop_time - t;
 
        if (t == 0)
                return "-";
-       return t_strdup_printf("%02d:%02d:%02d", diff/3600,
-                              (diff/60)%60, diff%60);
+       return time_formatted_hms(diff);
 }
 
 static void cmd_replicator_status_overview(struct replicator_context *ctx)
@@ -132,6 +137,7 @@ static void cmd_replicator_status(struct doveadm_cmd_context *cctx)
        struct replicator_context *ctx;
        const char *line, *const *args;
        time_t last_fast, last_full, last_success;
+       unsigned int next_secs;
 
        ctx = cmd_replicator_init(cctx);
        if (ctx->user_mask == NULL) {
@@ -147,6 +153,7 @@ static void cmd_replicator_status(struct doveadm_cmd_context *cctx)
        doveadm_print_header_simple("full sync");
        doveadm_print_header_simple("success sync");
        doveadm_print_header_simple("failed");
+       doveadm_print_header_simple("next sync secs");
 
        replicator_send(ctx, t_strdup_printf("STATUS\t%s\n",
                                             str_tabescape(ctx->user_mask)));
@@ -155,16 +162,18 @@ static void cmd_replicator_status(struct doveadm_cmd_context *cctx)
                        break;
                T_BEGIN {
                        args = t_strsplit_tabescaped(line);
-                       if (str_array_length(args) >= 5 &&
+                       if (str_array_length(args) >= 6 &&
                            str_to_time(args[2], &last_fast) == 0 &&
                            str_to_time(args[3], &last_full) == 0 &&
-                           str_to_time(args[5], &last_success) == 0) {
+                           str_to_time(args[5], &last_success) == 0 &&
+                           str_to_uint(args[6], &next_secs) == 0) {
                                doveadm_print(args[0]);
                                doveadm_print(args[1]);
                                doveadm_print(time_ago(last_fast));
                                doveadm_print(time_ago(last_full));
                                doveadm_print(time_ago(last_success));
                                doveadm_print(args[4][0] == '0' ? "-" : "y");
+                               doveadm_print(time_formatted_hms(next_secs));
                        }
                } T_END;
        }
index 80e2cd2206103fcfdf01c683b71a4b1a15b49d25..1932bc6bcaaf7bcb73fa4c1bc6b6a9b72410282d 100644 (file)
@@ -84,6 +84,7 @@ client_input_status(struct doveadm_connection *client, const char *const *args)
        struct replicator_queue_iter *iter;
        struct replicator_user *user;
        const char *mask = args[0];
+       unsigned int next_secs;
        string_t *str = t_str_new(128);
 
        if (mask == NULL)
@@ -98,11 +99,14 @@ client_input_status(struct doveadm_connection *client, const char *const *args)
                str_append_tabescaped(str, user->username);
                str_append_c(str, '\t');
                str_append(str, replicator_priority_to_str(user->priority));
-               str_printfa(str, "\t%lld\t%lld\t%d\t%lld\n",
+               if (replicator_queue_want_sync_now(user, &next_secs))
+                       next_secs = 0;
+               str_printfa(str, "\t%lld\t%lld\t%d\t%lld\t%u\n",
                            (long long)user->last_fast_sync,
                            (long long)user->last_full_sync,
                            user->last_sync_failed ? 1 : 0,
-                           (long long)user->last_successful_sync);
+                           (long long)user->last_successful_sync,
+                           next_secs);
                o_stream_nsend(client->conn.output, str_data(str), str_len(str));
        }
        replicator_queue_iter_deinit(&iter);