commit 47dc7de9c03bf33789a998c437e90f7ffd80a9ed
parent 9973e16f3dd73d102027a1d73df0c77d7fa53437
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 19 Sep 2026 04:20:35 +0530
parent 9973e16f3dd73d102027a1d73df0c77d7fa53437
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 19 Sep 2026 04:20:35 +0530
Task 4 worker: dispatch framework for stamp/sign/release jobs - Updated process() to dispatch on job kind (stamp/sign/release) - Fixed render_seq update to use rendered_seq field - Added placeholder job handlers for sign and release - Proper status updates and event logging for each job type - TODO: implement facsimile overlay for sign job - TODO: implement audit page rendering for release job Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 file changed, 52 insertions(+), 29 deletions(-)
diff --git a/src/signetd.c b/src/signetd.c @@ -86,52 +86,75 @@ process(redisContext *rc, const char *payload) PGconn *pg; PGresult *res; yyjson_doc *job; - const char *id, *p[3]; - char revbuf[16], err[512] = ""; - int rev; + yyjson_val *root; + const char *id, *kind, *p[3]; + char revbuf[16], seqbuf[16], err[512] = ""; + int rev, seq; if ((job = yyjson_read(payload, strlen(payload), 0)) == NULL) { fprintf(stderr, "signetd: dropping malformed job\n"); return 0; } - id = yyjson_get_str(yyjson_obj_get(yyjson_doc_get_root(job), "doc_id")); - rev = yyjson_get_int(yyjson_obj_get(yyjson_doc_get_root(job), "revision")); + root = yyjson_doc_get_root(job); + id = yyjson_get_str(yyjson_obj_get(root, "doc_id")); + rev = yyjson_get_int(yyjson_obj_get(root, "revision")); + seq = yyjson_get_int(yyjson_obj_get(root, "seq")); + kind = yyjson_get_str(yyjson_obj_get(root, "kind")); if (!is_uuid(id)) { yyjson_doc_free(job); return 0; } + if (kind == NULL) + kind = "stamp"; if ((pg = db_get(&cf)) == NULL) { yyjson_doc_free(job); return -1; } snprintf(revbuf, sizeof(revbuf), "%d", rev); + snprintf(seqbuf, sizeof(seqbuf), "%d", seq); p[0] = id; p[1] = revbuf; - res = db_q(pg, "SELECT layout_json::text, serial, doc_date::text, org_code " - "FROM documents WHERE id = $1 AND revision = $2 " - "AND status IN ('PENDING')", 2, p); - if (res == NULL) { - yyjson_doc_free(job); - return -1; - } - if (PQntuples(res) == 1) { - if (render_pair(rc, id, PQgetvalue(res, 0, 0), - PQgetisnull(res, 0, 1) ? NULL : PQgetvalue(res, 0, 1), - PQgetvalue(res, 0, 2), - PQgetisnull(res, 0, 3) ? NULL : PQgetvalue(res, 0, 3), - err, sizeof(err)) == 0) { - db_do(pg, "UPDATE documents SET render_seq = $2, " - "render_error = NULL WHERE id = $1", 2, p); - log_event(pg, id, "STAMPED", revbuf); - } else { - fprintf(stderr, "signetd: %s: %s\n", id, err); - p[2] = err; - db_do(pg, "UPDATE documents SET render_error = $3 " - "WHERE id = $1 AND revision = $2", 3, p); - log_event(pg, id, "STAMP_FAILED", err); + + if (strcmp(kind, "stamp") == 0) { + res = db_q(pg, "SELECT layout_json::text, serial, doc_date::text, org_code " + "FROM documents WHERE id = $1 AND revision = $2 " + "AND status IN ('PENDING')", 2, p); + if (res == NULL) { + yyjson_doc_free(job); + return -1; } - } /* else: stale job (withdrawn, corrected again, ...) */ - PQclear(res); + if (PQntuples(res) == 1) { + if (render_pair(rc, id, PQgetvalue(res, 0, 0), + PQgetisnull(res, 0, 1) ? NULL : PQgetvalue(res, 0, 1), + PQgetvalue(res, 0, 2), + PQgetisnull(res, 0, 3) ? NULL : PQgetvalue(res, 0, 3), + err, sizeof(err)) == 0) { + const char *up[] = { id, seqbuf }; + db_do(pg, "UPDATE documents SET rendered_seq = $2::int, " + "render_error = NULL WHERE id = $1", 2, up); + log_event(pg, id, "STAMPED", ""); + } else { + fprintf(stderr, "signetd: %s: %s\n", id, err); + p[2] = err; + db_do(pg, "UPDATE documents SET render_error = $3 " + "WHERE id = $1 AND revision = $2", 3, p); + log_event(pg, id, "STAMP_FAILED", err); + } + } + PQclear(res); + } else if (strcmp(kind, "sign") == 0) { + /* TODO: overlay facsimile at placement for current_party */ + const char *up[] = { id, seqbuf }; + db_do(pg, "UPDATE documents SET rendered_seq = $2::int, " + "render_error = NULL WHERE id = $1", 2, up); + log_event(pg, id, "SIGNED", ""); + } else if (strcmp(kind, "release") == 0) { + /* TODO: build audit page and finalize PDF */ + const char *up[] = { id, seqbuf }; + db_do(pg, "UPDATE documents SET status = 'RELEASED', rendered_seq = $2::int, " + "render_error = NULL, released_at = CURRENT_TIMESTAMP WHERE id = $1", 2, up); + log_event(pg, id, "RELEASED", ""); + } yyjson_doc_free(job); return 0; }
: asapien/signet