Commit 09e84bec authored by Furkan Ayhan's avatar Furkan Ayhan

Add daily_limit and pass it to frontend

parent 23884fb5
......@@ -63,6 +63,10 @@ module Ci
.execute(self, fallback_method: method(:calculate_next_run_at))
end
def daily_limit
project.actual_limits.limit_for(:ci_daily_pipeline_schedule_triggers)
end
private
def worker_cron_expression
......
......@@ -41,11 +41,11 @@ module Ci
def plan_cron
strong_memoize(:plan_cron) do
daily_scheduled_pipeline_limit = project.actual_limits.limit_for(:ci_daily_pipeline_schedule_triggers)
daily_limit = @schedule.daily_limit
next unless daily_scheduled_pipeline_limit
next unless daily_limit
every_x_minutes = (1.day.in_minutes / daily_scheduled_pipeline_limit).to_i
every_x_minutes = (1.day.in_minutes / daily_limit).to_i
Gitlab::Ci::CronParser.parse_natural("every #{every_x_minutes} minutes", Time.zone.name)
end
......
......@@ -7,7 +7,7 @@
.form-group.row
.col-md-9
= f.label :cron, _('Interval Pattern'), class: 'label-bold'
#interval-pattern-input{ data: { initial_interval: @schedule.cron } }
#interval-pattern-input{ data: { initial_interval: @schedule.cron, daily_limit: @schedule.daily_limit } }
.form-group.row
.col-md-9
= f.label :cron_timezone, _('Cron Timezone'), class: 'label-bold'
......
......@@ -122,6 +122,9 @@ RSpec.describe Ci::PipelineSchedule do
'*/5 * * * *' | '0 * * * *' | (1.day.in_minutes / 10).to_i | false | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 12, 5)
'*/5 * * * *' | '0 * * * *' | (1.day.in_minutes / 1.hour.in_minutes).to_i | true | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 12, 0)
'*/5 * * * *' | '0 * * * *' | (1.day.in_minutes / 2.hours.in_minutes).to_i | true | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 12, 5)
'*/5 * * * *' | '0 1 * * *' | (1.day.in_minutes / 1.hour.in_minutes).to_i | true | Time.zone.local(2021, 5, 27, 1, 0) | Time.zone.local(2021, 5, 28, 1, 0)
'*/5 * * * *' | '0 1 * * *' | (1.day.in_minutes / 1.hour.in_minutes).to_i | true | Time.zone.local(2021, 5, 27, 1, 0) | Time.zone.local(2021, 5, 28, 1, 0)
'*/5 * * * *' | '0 1 1 * *' | (1.day.in_minutes / 1.hour.in_minutes).to_i | true | Time.zone.local(2021, 5, 1, 1, 0) | Time.zone.local(2021, 6, 1, 1, 0)
end
with_them do
......@@ -198,4 +201,26 @@ RSpec.describe Ci::PipelineSchedule do
it { is_expected.to contain_exactly(*pipeline_schedule_variables.map(&:to_runner_variable)) }
end
describe '#daily_limit' do
let(:pipeline_schedule) { build(:ci_pipeline_schedule) }
subject(:daily_limit) { pipeline_schedule.daily_limit }
context 'when there is no limit' do
before do
create(:plan_limits, :default_plan, ci_daily_pipeline_schedule_triggers: 0)
end
it { is_expected.to be_nil }
end
context 'when there is a limit' do
before do
create(:plan_limits, :default_plan, ci_daily_pipeline_schedule_triggers: 144)
end
it { is_expected.to eq(144) }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment