Skip to content

Zoekt: Return tasks in internal API

Dmitry Gruzd requested to merge 424124-send-zoekt-tasks into master

What does this MR do and why?

This MR adds zoekt_tasks to our Zoekt Internal API. This is needed to switch to a pull-based task model (right now we push tasks to Zoekt)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

DB queries

Click to see SQL to add tasks to postgres.ai
insert into zoekt_tasks (zoekt_node_id, zoekt_repository_id, project_identifier, perform_at, created_at, updated_at, task_type) select 4, 1, p.id, now(), now(), now(), 1 from generate_series(1,5000) as p(id);

Task processing query

SELECT "zoekt_tasks"."id",
       "zoekt_tasks"."zoekt_node_id",
       "zoekt_tasks"."zoekt_repository_id",
       "zoekt_tasks"."project_identifier",
       "zoekt_tasks"."perform_at",
       "zoekt_tasks"."created_at",
       "zoekt_tasks"."updated_at",
       "zoekt_tasks"."state",
       "zoekt_tasks"."task_type",
       "zoekt_tasks"."retries_left"
FROM "zoekt_tasks"
WHERE "zoekt_tasks"."zoekt_node_id" = 4
  AND "zoekt_tasks"."state" = 0
  AND "zoekt_tasks"."perform_at" >= '2024-02-26 11:26:54.873747'
ORDER BY "zoekt_tasks"."perform_at" ASC

https://postgres.ai/console/gitlab/gitlab-production-main/sessions/27234/commands/84716

Obsolete task update (100 batch size)

UPDATE "zoekt_tasks" SET "state" = 256 
WHERE "zoekt_tasks"."zoekt_node_id" = 4
  AND "zoekt_tasks"."state" = 0
  AND "zoekt_tasks"."perform_at" >= '2024-02-26 11:26:54.873747'
  AND "zoekt_tasks"."id" IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100)

https://postgres.ai/console/gitlab/gitlab-production-main/sessions/27234/commands/84721

Note: we don't have records on production. Locally it uses Index Scan

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Related to #424124 (closed)

Edited by Dmitry Gruzd

Merge request reports