summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2017-12-12 15:46:05 -0800
committerStan Hu <stanhu@gmail.com>2017-12-12 17:12:45 -0800
commit4b0465f20de1bf58326c7daf6876b63438f00d84 (patch)
tree0424373b472e20906f66d94783c86f4ff7f3060f /app
parent02e7e499d4011733c1cf0f6fb675dd2d309f0d52 (diff)
downloadgitlab-ce-4b0465f20de1bf58326c7daf6876b63438f00d84.tar.gz
Address review comments with playing pipeline schedulersh-add-schedule-pipeline-run-now
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/pipeline_schedules_controller.rb30
1 files changed, 15 insertions, 15 deletions
diff --git a/app/controllers/projects/pipeline_schedules_controller.rb b/app/controllers/projects/pipeline_schedules_controller.rb
index dd6593650e7..b478e7b5e05 100644
--- a/app/controllers/projects/pipeline_schedules_controller.rb
+++ b/app/controllers/projects/pipeline_schedules_controller.rb
@@ -1,6 +1,7 @@
class Projects::PipelineSchedulesController < Projects::ApplicationController
before_action :schedule, except: [:index, :new, :create]
+ before_action :play_rate_limit, only: [:play]
before_action :authorize_play_pipeline_schedule!, only: [:play]
before_action :authorize_read_pipeline_schedule!
before_action :authorize_create_pipeline_schedule!, only: [:new, :create]
@@ -42,21 +43,13 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
end
def play
- limiter = ::Gitlab::ActionRateLimiter.new(action: :play_pipeline_schedule)
-
- if limiter.throttled?(throttle_key, 1)
- flash[:alert] = 'You cannot play this scheduled pipeline at the moment. Please wait a minute.'
- return redirect_to pipeline_schedules_path(@project)
- end
-
job_id = RunPipelineScheduleWorker.perform_async(schedule.id, current_user.id)
- flash[:notice] =
- if job_id
- "Successfully scheduled a pipeline to run. Go to the <a href=\"#{project_pipelines_path(@project)}\">Pipelines page</a> for details.".html_safe
- else
- 'Unable to schedule a pipeline to run immediately'
- end
+ if job_id
+ flash[:notice] = "Successfully scheduled a pipeline to run. Go to the <a href=\"#{project_pipelines_path(@project)}\">Pipelines page</a> for details.".html_safe
+ else
+ flash[:alert] = 'Unable to schedule a pipeline to run immediately'
+ end
redirect_to pipeline_schedules_path(@project)
end
@@ -81,8 +74,15 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
private
- def throttle_key
- "user:#{current_user.id}:schedule:#{schedule.id}"
+ def play_rate_limit
+ return unless current_user
+
+ limiter = ::Gitlab::ActionRateLimiter.new(action: :play_pipeline_schedule)
+
+ return unless limiter.throttled?([current_user, schedule], 1)
+
+ flash[:alert] = 'You cannot play this scheduled pipeline at the moment. Please wait a minute.'
+ redirect_to pipeline_schedules_path(@project)
end
def schedule