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
Boxiang Sun
gitlab-ce
Commits
74f22d26
Commit
74f22d26
authored
Oct 26, 2018
by
Winnie Hellmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Vue mixin for delayed job timers
parent
390abbf0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
164 additions
and
2 deletions
+164
-2
app/assets/javascripts/jobs/mixins/delayed_job_mixin.js
app/assets/javascripts/jobs/mixins/delayed_job_mixin.js
+50
-0
spec/javascripts/fixtures/jobs.rb
spec/javascripts/fixtures/jobs.rb
+21
-2
spec/javascripts/jobs/mixins/delayed_job_mixin_spec.js
spec/javascripts/jobs/mixins/delayed_job_mixin_spec.js
+93
-0
No files found.
app/assets/javascripts/jobs/mixins/delayed_job_mixin.js
0 → 100644
View file @
74f22d26
import
{
calculateRemainingMilliseconds
,
formatTime
}
from
'
~/lib/utils/datetime_utility
'
;
export
default
{
data
()
{
return
{
remainingTime
:
formatTime
(
0
),
remainingTimeIntervalId
:
null
,
};
},
mounted
()
{
this
.
startRemainingTimeInterval
();
},
beforeDestroy
()
{
if
(
this
.
remainingTimeIntervalId
)
{
clearInterval
(
this
.
remainingTimeIntervalId
);
}
},
computed
:
{
isDelayedJob
()
{
return
this
.
job
&&
this
.
job
.
scheduled
;
},
},
watch
:
{
isDelayedJob
()
{
this
.
startRemainingTimeInterval
();
},
},
methods
:
{
startRemainingTimeInterval
()
{
if
(
this
.
remainingTimeIntervalId
)
{
clearInterval
(
this
.
remainingTimeIntervalId
);
}
if
(
this
.
isDelayedJob
)
{
this
.
updateRemainingTime
();
this
.
remainingTimeIntervalId
=
setInterval
(()
=>
this
.
updateRemainingTime
(),
1000
);
}
},
updateRemainingTime
()
{
const
remainingMilliseconds
=
calculateRemainingMilliseconds
(
this
.
job
.
scheduled_at
);
this
.
remainingTime
=
formatTime
(
remainingMilliseconds
);
},
},
};
spec/javascripts/fixtures/jobs.rb
View file @
74f22d26
...
@@ -5,16 +5,24 @@ describe Projects::JobsController, '(JavaScript fixtures)', type: :controller do
...
@@ -5,16 +5,24 @@ describe Projects::JobsController, '(JavaScript fixtures)', type: :controller do
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:namespace
)
{
create
(
:namespace
,
name:
'frontend-fixtures'
)}
let
(
:namespace
)
{
create
(
:namespace
,
name:
'frontend-fixtures'
)}
let
(
:project
)
{
create
(
:project
_empty_repo
,
namespace:
namespace
,
path:
'builds-project'
)
}
let
(
:project
)
{
create
(
:project
,
:repository
,
namespace:
namespace
,
path:
'builds-project'
)
}
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
project:
project
)
}
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
project:
project
,
sha:
project
.
commit
.
id
)
}
let!
(
:build_with_artifacts
)
{
create
(
:ci_build
,
:success
,
:artifacts
,
:trace_artifact
,
pipeline:
pipeline
,
stage:
'test'
,
artifacts_expire_at:
Time
.
now
+
18
.
months
)
}
let!
(
:build_with_artifacts
)
{
create
(
:ci_build
,
:success
,
:artifacts
,
:trace_artifact
,
pipeline:
pipeline
,
stage:
'test'
,
artifacts_expire_at:
Time
.
now
+
18
.
months
)
}
let!
(
:failed_build
)
{
create
(
:ci_build
,
:failed
,
pipeline:
pipeline
,
stage:
'build'
)
}
let!
(
:failed_build
)
{
create
(
:ci_build
,
:failed
,
pipeline:
pipeline
,
stage:
'build'
)
}
let!
(
:pending_build
)
{
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
,
stage:
'deploy'
)
}
let!
(
:pending_build
)
{
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
,
stage:
'deploy'
)
}
let!
(
:delayed_job
)
do
create
(
:ci_build
,
:scheduled
,
pipeline:
pipeline
,
name:
'delayed job'
,
stage:
'test'
,
commands:
'test'
)
end
render_views
render_views
before
(
:all
)
do
before
(
:all
)
do
clean_frontend_fixtures
(
'builds/'
)
clean_frontend_fixtures
(
'builds/'
)
clean_frontend_fixtures
(
'jobs/'
)
end
end
before
do
before
do
...
@@ -34,4 +42,15 @@ describe Projects::JobsController, '(JavaScript fixtures)', type: :controller do
...
@@ -34,4 +42,15 @@ describe Projects::JobsController, '(JavaScript fixtures)', type: :controller do
expect
(
response
).
to
be_success
expect
(
response
).
to
be_success
store_frontend_fixture
(
response
,
example
.
description
)
store_frontend_fixture
(
response
,
example
.
description
)
end
end
it
'jobs/delayed.json'
do
|
example
|
get
:show
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
id:
delayed_job
.
to_param
,
format: :json
expect
(
response
).
to
be_success
store_frontend_fixture
(
response
,
example
.
description
)
end
end
end
spec/javascripts/jobs/mixins/delayed_job_mixin_spec.js
0 → 100644
View file @
74f22d26
import
Vue
from
'
vue
'
;
import
delayedJobMixin
from
'
~/jobs/mixins/delayed_job_mixin
'
;
import
mountComponent
from
'
spec/helpers/vue_mount_component_helper
'
;
describe
(
'
DelayedJobMixin
'
,
()
=>
{
const
delayedJobFixture
=
getJSONFixture
(
'
jobs/delayed.json
'
);
const
dummyComponent
=
Vue
.
extend
({
mixins
:
[
delayedJobMixin
],
props
:
{
job
:
{
type
:
Object
,
required
:
true
,
},
},
template
:
'
<div>{{ remainingTime }}</div>
'
,
});
let
vm
;
beforeEach
(()
=>
{
jasmine
.
clock
().
install
();
});
afterEach
(()
=>
{
vm
.
$destroy
();
jasmine
.
clock
().
uninstall
();
});
describe
(
'
if job is empty object
'
,
()
=>
{
beforeEach
(()
=>
{
vm
=
mountComponent
(
dummyComponent
,
{
job
:
{},
});
});
it
(
'
sets remaining time to 00:00:00
'
,
()
=>
{
expect
(
vm
.
$el
.
innerText
).
toBe
(
'
00:00:00
'
);
});
describe
(
'
after mounting
'
,
()
=>
{
beforeEach
(
done
=>
{
Vue
.
nextTick
()
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
doe not update remaining time
'
,
()
=>
{
expect
(
vm
.
$el
.
innerText
).
toBe
(
'
00:00:00
'
);
});
});
});
describe
(
'
if job is delayed job
'
,
()
=>
{
let
remainingTimeInMilliseconds
=
42000
;
beforeEach
(()
=>
{
spyOn
(
Date
,
'
now
'
).
and
.
callFake
(
()
=>
new
Date
(
delayedJobFixture
.
scheduled_at
).
getTime
()
-
remainingTimeInMilliseconds
,
);
vm
=
mountComponent
(
dummyComponent
,
{
job
:
delayedJobFixture
,
});
});
it
(
'
sets remaining time to 00:00:00
'
,
()
=>
{
expect
(
vm
.
$el
.
innerText
).
toBe
(
'
00:00:00
'
);
});
describe
(
'
after mounting
'
,
()
=>
{
beforeEach
(
done
=>
{
Vue
.
nextTick
()
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
sets remaining time
'
,
()
=>
{
expect
(
vm
.
$el
.
innerText
).
toBe
(
'
00:00:42
'
);
});
it
(
'
updates remaining time
'
,
done
=>
{
remainingTimeInMilliseconds
=
41000
;
jasmine
.
clock
().
tick
(
1000
);
Vue
.
nextTick
()
.
then
(()
=>
{
expect
(
vm
.
$el
.
innerText
).
toBe
(
'
00:00:41
'
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
});
});
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