Check the pipeline schedule play rate limit in the service

What does this MR do and why?

Moves the play_pipeline_schedule rate limit check from Projects::PipelineSchedulesController into Ci::PipelineSchedules::PlayService, so the controller, the GraphQL mutation pipelineSchedulePlay and POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/play all apply the same limit (one play per user per schedule per minute).

The service now returns a ServiceResponse on every path. Callers branch on reason: :rate_limited: the controller keeps its existing flash message, the mutation returns the message in errors, and the REST endpoint returns 429 with a Retry-After header. Other failures keep their current messages.

As with the pipeline cancel, retry and delete services, the check runs through Gitlab::ApplicationRateLimiter.throttled? inside the service, so the request bypass header is not consulted and the throttle is logged through Gitlab::AppJsonLogger instead of the controller's AuthLogger line. Controller requests that fail authorization are no longer counted toward the limit, because the authorization check now runs before the service is called.

The GraphQL and REST request specs are tagged :clean_gitlab_redis_rate_limiting (and :clean_gitlab_redis_queues where the real worker is enqueued), because rate limit counters and Sidekiq deduplication keys otherwise persist across examples that share the same schedule and user.

References

Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/636625

Screenshots or screen recordings

No UI change. The pipeline schedules page already shows a generic error when the mutation returns errors.

How to set up and validate locally

  1. On a project with a pipeline schedule, open Build > Pipeline schedules and select Run twice within a minute. The second run shows an error.

  2. REST: run the following twice within a minute. The second call returns 429 with a Retry-After header.

    curl --request POST --header "PRIVATE-TOKEN: <token>" \
      "http://gdk.test:3000/api/v4/projects/<project_id>/pipeline_schedules/<schedule_id>/play"

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

🤖 Generated with Claude Code

Merge request reports

Loading
Loading