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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
3d1bc4a4
Commit
3d1bc4a4
authored
Mar 29, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed strcture for db change
parent
c426763c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
19 deletions
+22
-19
app/services/ci/create_pipeline_service.rb
app/services/ci/create_pipeline_service.rb
+4
-6
app/workers/trigger_schedule_worker.rb
app/workers/trigger_schedule_worker.rb
+6
-5
spec/factories/ci/trigger_schedules.rb
spec/factories/ci/trigger_schedules.rb
+0
-0
spec/factories/ci/triggers.rb
spec/factories/ci/triggers.rb
+1
-1
spec/services/ci/create_pipeline_service_spec.rb
spec/services/ci/create_pipeline_service_spec.rb
+0
-4
spec/workers/trigger_schedule_worker_spec.rb
spec/workers/trigger_schedule_worker_spec.rb
+11
-3
No files found.
app/services/ci/create_pipeline_service.rb
View file @
3d1bc4a4
...
@@ -2,14 +2,14 @@ module Ci
...
@@ -2,14 +2,14 @@ module Ci
class
CreatePipelineService
<
BaseService
class
CreatePipelineService
<
BaseService
attr_reader
:pipeline
attr_reader
:pipeline
def
execute
(
ignore_skip_ci:
false
,
save_on_errors:
true
,
trigger_request:
nil
,
scheduled_trigger:
false
)
def
execute
(
ignore_skip_ci:
false
,
save_on_errors:
true
,
trigger_request:
nil
)
@pipeline
=
Ci
::
Pipeline
.
new
(
@pipeline
=
Ci
::
Pipeline
.
new
(
project:
project
,
project:
project
,
ref:
ref
,
ref:
ref
,
sha:
sha
,
sha:
sha
,
before_sha:
before_sha
,
before_sha:
before_sha
,
tag:
tag?
,
tag:
tag?
,
trigger_requests:
(
scheduled_trigger
)
?
[]
:
Array
(
trigger_request
),
trigger_requests:
Array
(
trigger_request
),
user:
current_user
user:
current_user
)
)
...
@@ -17,10 +17,8 @@ module Ci
...
@@ -17,10 +17,8 @@ module Ci
return
error
(
'Pipeline is disabled'
)
return
error
(
'Pipeline is disabled'
)
end
end
unless
scheduled_trigger
unless
trigger_request
||
can?
(
current_user
,
:create_pipeline
,
project
)
unless
trigger_request
||
can?
(
current_user
,
:create_pipeline
,
project
)
return
error
(
'Insufficient permissions to create a new pipeline'
)
return
error
(
'Insufficient permissions to create a new pipeline'
)
end
end
end
unless
branch?
||
tag?
unless
branch?
||
tag?
...
...
app/workers/trigger_schedule_worker.rb
View file @
3d1bc4a4
...
@@ -3,14 +3,15 @@ class TriggerScheduleWorker
...
@@ -3,14 +3,15 @@ class TriggerScheduleWorker
include
CronjobQueue
include
CronjobQueue
def
perform
def
perform
Ci
::
TriggerSchedule
.
where
(
"next_run_at < ?"
,
Time
.
now
).
find_each
do
|
trigger
|
Ci
::
TriggerSchedule
.
where
(
"next_run_at < ?"
,
Time
.
now
).
find_each
do
|
trigger
_schedule
|
begin
begin
Ci
::
CreatePipelineService
.
new
(
trigger
.
project
,
trigger
.
owner
,
ref:
trigger
.
ref
).
Ci
::
CreateTriggerRequestService
.
new
.
execute
(
trigger_schedule
.
trigger
.
project
,
execute
(
ignore_skip_ci:
true
,
scheduled_trigger:
true
)
trigger_schedule
.
trigger
,
trigger_schedule
.
trigger
.
ref
)
rescue
=>
e
rescue
=>
e
Rails
.
logger
.
error
"
#{
trigger
.
id
}
: Failed to trigger
job:
#{
e
.
message
}
"
Rails
.
logger
.
error
"
#{
trigger
_schedule
.
id
}
: Failed to trigger_schedule
job:
#{
e
.
message
}
"
ensure
ensure
trigger
.
schedule_next_run!
trigger
_schedule
.
schedule_next_run!
end
end
end
end
end
end
...
...
spec/factories/ci/
scheduled_trigger
s.rb
→
spec/factories/ci/
trigger_schedule
s.rb
View file @
3d1bc4a4
File moved
spec/factories/ci/triggers.rb
View file @
3d1bc4a4
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:ci_trigger_without_token
,
class:
Ci
::
Trigger
do
factory
:ci_trigger_without_token
,
class:
Ci
::
Trigger
do
factory
:ci_trigger
do
factory
:ci_trigger
do
token
'token'
token
{
SecureRandom
.
hex
(
10
)
}
end
end
end
end
end
end
spec/services/ci/create_pipeline_service_spec.rb
View file @
3d1bc4a4
...
@@ -214,9 +214,5 @@ describe Ci::CreatePipelineService, services: true do
...
@@ -214,9 +214,5 @@ describe Ci::CreatePipelineService, services: true do
expect
(
Environment
.
find_by
(
name:
"review/master"
)).
not_to
be_nil
expect
(
Environment
.
find_by
(
name:
"review/master"
)).
not_to
be_nil
end
end
end
end
context
'when scheduled_trigger'
do
# TODO: spec if approved
end
end
end
end
end
spec/workers/trigger_schedule_worker_spec.rb
View file @
3d1bc4a4
...
@@ -8,18 +8,26 @@ describe TriggerScheduleWorker do
...
@@ -8,18 +8,26 @@ describe TriggerScheduleWorker do
end
end
context
'when there is a scheduled trigger within next_run_at'
do
context
'when there is a scheduled trigger within next_run_at'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:trigger
)
{
create
(
:ci_trigger
,
owner:
user
,
project:
project
,
ref:
'master'
)
}
let!
(
:trigger_schedule
)
{
create
(
:ci_trigger_schedule
,
:cron_nightly_build
,
:force_triggable
,
trigger:
trigger
,
project:
project
)
}
before
do
before
do
create
(
:ci_trigger_schedule
,
:cron_nightly_build
,
:force_triggable
)
worker
.
perform
worker
.
perform
end
end
it
'creates a new trigger request'
do
expect
(
Ci
::
TriggerRequest
.
first
.
trigger_id
).
to
eq
(
trigger
.
id
)
end
it
'creates a new pipeline'
do
it
'creates a new pipeline'
do
expect
(
Ci
::
Pipeline
.
last
.
status
).
to
eq
(
'pending'
)
expect
(
Ci
::
Pipeline
.
last
.
status
).
to
eq
(
'pending'
)
end
end
it
'schedules next_run_at'
do
it
'schedules next_run_at'
do
trigger_schedule2
=
create
(
:ci_trigger_schedule
,
:cron_nightly_build
)
next_time
=
Ci
::
CronParser
.
new
(
'0 1 * * *'
,
'Europe/Istanbul'
).
next_time_from_now
expect
(
Ci
::
TriggerSchedule
.
last
.
next_run_at
).
to
eq
(
trigger_schedule2
.
next_run_at
)
expect
(
Ci
::
TriggerSchedule
.
last
.
next_run_at
).
to
eq
(
next_time
)
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