Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
21cabf38
Commit
21cabf38
authored
Apr 01, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move real_next_run to helper
parent
5720919c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
37 deletions
+40
-37
app/helpers/triggers_helper.rb
app/helpers/triggers_helper.rb
+13
-0
app/models/ci/trigger_schedule.rb
app/models/ci/trigger_schedule.rb
+0
-13
spec/helpers/triggers_helper_spec.rb
spec/helpers/triggers_helper_spec.rb
+27
-0
spec/models/ci/trigger_schedule_spec.rb
spec/models/ci/trigger_schedule_spec.rb
+0
-24
No files found.
app/helpers/triggers_helper.rb
View file @
21cabf38
...
@@ -10,4 +10,17 @@ module TriggersHelper
...
@@ -10,4 +10,17 @@ module TriggersHelper
def
service_trigger_url
(
service
)
def
service_trigger_url
(
service
)
"
#{
Settings
.
gitlab
.
url
}
/api/v3/projects/
#{
service
.
project_id
}
/services/
#{
service
.
to_param
}
/trigger"
"
#{
Settings
.
gitlab
.
url
}
/api/v3/projects/
#{
service
.
project_id
}
/services/
#{
service
.
to_param
}
/trigger"
end
end
def
real_next_run
(
trigger_schedule
,
worker_cron:
nil
,
worker_time_zone:
nil
)
worker_cron
=
Settings
.
cron_jobs
[
'trigger_schedule_worker'
][
'cron'
]
unless
worker_cron
.
present?
worker_time_zone
=
Time
.
zone
.
name
unless
worker_time_zone
.
present?
worker_next_time
=
Ci
::
CronParser
.
new
(
worker_cron
,
worker_time_zone
).
next_time_from
(
Time
.
now
)
if
trigger_schedule
.
next_run_at
>
worker_next_time
trigger_schedule
.
next_run_at
else
worker_next_time
end
end
end
end
app/models/ci/trigger_schedule.rb
View file @
21cabf38
...
@@ -25,19 +25,6 @@ module Ci
...
@@ -25,19 +25,6 @@ module Ci
end
end
end
end
def
real_next_run
(
worker_cron:
nil
,
worker_time_zone:
nil
)
worker_cron
=
Settings
.
cron_jobs
[
'trigger_schedule_worker'
][
'cron'
]
unless
worker_cron
.
present?
worker_time_zone
=
Time
.
zone
.
name
unless
worker_time_zone
.
present?
worker_next_time
=
Ci
::
CronParser
.
new
(
worker_cron
,
worker_time_zone
).
next_time_from
(
Time
.
now
)
if
next_run_at
>
worker_next_time
next_run_at
else
worker_next_time
end
end
private
private
def
less_than_1_hour_from_now?
(
time
)
def
less_than_1_hour_from_now?
(
time
)
...
...
spec/helpers/triggers_helper_spec.rb
0 → 100644
View file @
21cabf38
require
'rails_helper'
describe
TriggersHelper
do
describe
'#real_next_run'
do
let
(
:trigger_schedule
)
{
create
(
:ci_trigger_schedule
,
cron:
user_cron
,
cron_time_zone:
'UTC'
)
}
subject
{
helper
.
real_next_run
(
trigger_schedule
,
worker_cron:
worker_cron
,
worker_time_zone:
'UTC'
)
}
context
'when next_run_at > worker_next_time'
do
let
(
:worker_cron
)
{
'* * * * *'
}
# every minutes
let
(
:user_cron
)
{
'0 0 1 1 *'
}
# every 00:00, January 1st
it
'returns next_run_at'
do
is_expected
.
to
eq
(
trigger_schedule
.
next_run_at
)
end
end
context
'when worker_next_time > next_run_at'
do
let
(
:worker_cron
)
{
'0 0 1 1 *'
}
# every 00:00, January 1st
let
(
:user_cron
)
{
'0 */6 * * *'
}
# each six hours
it
'returns worker_next_time'
do
is_expected
.
to
eq
(
Ci
::
CronParser
.
new
(
worker_cron
,
'UTC'
).
next_time_from
(
Time
.
now
))
end
end
end
end
spec/models/ci/trigger_schedule_spec.rb
View file @
21cabf38
...
@@ -54,28 +54,4 @@ describe Ci::TriggerSchedule, models: true do
...
@@ -54,28 +54,4 @@ describe Ci::TriggerSchedule, models: true do
end
end
end
end
end
end
describe
'#real_next_run'
do
let
(
:trigger_schedule
)
{
create
(
:ci_trigger_schedule
,
cron:
user_cron
,
cron_time_zone:
'UTC'
)
}
subject
{
trigger_schedule
.
real_next_run
(
worker_cron:
worker_cron
,
worker_time_zone:
'UTC'
)
}
context
'when next_run_at > worker_next_time'
do
let
(
:worker_cron
)
{
'* * * * *'
}
# every minutes
let
(
:user_cron
)
{
'0 0 1 1 *'
}
# every 00:00, January 1st
it
'returns next_run_at'
do
is_expected
.
to
eq
(
trigger_schedule
.
next_run_at
)
end
end
context
'when worker_next_time > next_run_at'
do
let
(
:worker_cron
)
{
'0 0 1 1 *'
}
# every 00:00, January 1st
let
(
:user_cron
)
{
'0 */6 * * *'
}
# each six hours
it
'returns worker_next_time'
do
is_expected
.
to
eq
(
Ci
::
CronParser
.
new
(
worker_cron
,
'UTC'
).
next_time_from
(
Time
.
now
))
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment