Adds Flow Schedule Model

What does this MR do and why?

This is MR 3 of 7 for scheduled flow triggers (work item). Users will be able to run AI flows on a cron schedule. For that, GitLab needs to store when each flow should run and track failed runs. This MR adds the Ai::FlowSchedule model for this purpose. Later MRs in the stack build on it (GraphQL API, dispatcher worker, emails, frontend). Nothing reads these schedules yet, so there is no user-facing change.

The ai_flow_schedules table already exists. It was merged in !250227 (merged), so this MR has no migrations. Two things were promised to the database reviewers of that MR and are delivered here, because they belong to the model, not the table: a development seed file for the new table (asked by @egrieff), and a validation so a schedule always stays in the same project as its flow trigger (asked by @reza-marandi).

Stack note: the stack was reordered to move the auth/identity work to the end, because the auth approach is still under discussion. This branch was rebased onto the reworked parent MR !250805 (merged), which now only registers the scheduled event type. Review can start now as a stacked review. Merging waits until the parent MR merges.

Raw SQL Queries

  1. .active
SELECT "ai_flow_schedules".*
FROM "ai_flow_schedules"
WHERE "ai_flow_schedules"."active" = TRUE;
  1. .runnable_schedules
SELECT "ai_flow_schedules".*
FROM "ai_flow_schedules"
WHERE "ai_flow_schedules"."active" = TRUE
  AND (next_run_at < now());

Query Execution Plan

  1. .active: https://console.postgres.ai/gitlab/projects/gitlab-production-main/sessions/56105/commands/160172
  2. .runnable_schedules: https://console.postgres.ai/gitlab/projects/gitlab-production-main/sessions/56105/commands/160187
  1. Adds ai_flow_schedules table for scheduled AI f... (!250227 - merged)
  2. Add scheduled event type to AI flow triggers (!250805 - merged)
  3. Adds Flow Schedule Model (!250809 - merged) (This MR)
  4. Add Flow Schedules API (!250821 - merged)
  5. Adds Flow Schedule Email Notifications (!250824 - merged)
  6. Adds flow schedule execution (!250838)
  7. Adds FE changes for Flow Schedules (!250843)

How to set up and validate locally

  1. Seed a flow schedule:

    bundle exec rake db:seed_fu FILTER=ai_flow_schedules
  2. Check the record in the Rails console. Its project_id matches the flow trigger's project, and next_run_at is set:

    Ai::FlowSchedule.last
  3. Run the specs:

    bundle exec rspec ee/spec/models/ai/flow_schedule_spec.rb ee/spec/policies/ai/flow_schedule_policy_spec.rb

MR acceptance checklist

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

Edited by Shola Quadri

Merge request reports

Loading
Loading