Skip to content

Commit

Permalink
Merge branch 'auto_tailing_on_run_now' into hs_staging
Browse files Browse the repository at this point in the history
  • Loading branch information
tpetr committed Apr 7, 2015
2 parents 9fdca00 + 463a365 commit 6642494
Showing 9 changed files with 148 additions and 13 deletions.
3 changes: 3 additions & 0 deletions SingularityUI/app/collections/TaskFiles.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Collection = require './collection'
TaskFile = require '../models/TaskFile'

class TaskFiles extends Collection

url: -> "#{ config.apiRoot }/sandbox/#{ @taskId }/browse"

model: TaskFile

initialize: (models, { @taskId, @path }) ->

fetch: (params) ->
2 changes: 2 additions & 0 deletions SingularityUI/app/controllers/RequestDetail.coffee
Original file line number Diff line number Diff line change
@@ -96,6 +96,8 @@ class RequestDetailController extends Controller
#
@setView new RequestDetailView _.extend {@requestId, @subviews},
model: @models.request
history: @collections.taskHistory
activeTasks: @collections.activeTasks

@refresh()

12 changes: 10 additions & 2 deletions SingularityUI/app/models/Request.coffee
Original file line number Diff line number Diff line change
@@ -121,15 +121,23 @@ class Request extends Model
@unpause().done callback

promptRun: (callback) =>

vex.dialog.prompt
message: runTemplate id: @get "id"
input: runTemplate id: @get "id"
buttons: [
$.extend _.clone(vex.dialog.buttons.YES), text: 'Run now'
vex.dialog.buttons.NO
]
afterOpen: ->
$('#filename').val localStorage.getItem('taskRunRedirectFilename')
$('#autoTail').prop 'checked', (localStorage.getItem('taskRunAutoTail') is 'on')

callback: (data) =>
return if data is false
@run(data).done callback
localStorage.setItem('taskRunRedirectFilename', data.filename) if data.filename?
localStorage.setItem('taskRunAutoTail', data.autoTail)
data.id = @get 'id'
@run(data.commandLineInput).done callback(data)

promptRemove: (callback) =>
vex.dialog.confirm
7 changes: 7 additions & 0 deletions SingularityUI/app/models/TaskFile.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Model = require './model'

class TaskFile extends Model

idAttribute: 'name'

module.exports = TaskFile
2 changes: 1 addition & 1 deletion SingularityUI/app/styles/colors.styl
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ $linkBlue = #08c

$beige = #f3efe0
$grey = #444444

$gray-light = #dadada
$red = #e94d4d
$orange = #df7310
$yellow = #ffff99
5 changes: 5 additions & 0 deletions SingularityUI/app/styles/layout.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import colors

.border-color-light-gray
border-color: $gray-light

11 changes: 11 additions & 0 deletions SingularityUI/app/styles/main.styl
Original file line number Diff line number Diff line change
@@ -93,3 +93,14 @@ code
@-moz-document url-prefix()
fieldset
display table-cell

.auto-tail-checklist
margin-top 10px
.auto-tail-task-start
font-weight bolder

&.waiting-for-file
.auto-tail-task-start
font-weight normal
.auto-tail-file-exists
font-weight bolder
15 changes: 13 additions & 2 deletions SingularityUI/app/templates/vex/requestRun.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<p>Are you sure you want to run a task for this request immediately?</p>
<p>Are you sure you want to immediately launch a task for this request?</p>
<pre>{{ id }}</pre>
<p>Additional command line input (optional):</p>

<p>Additional command line input: <small>(optional)</small></p>
<div class="vex-dialog-input">
<input id='commandLineInput' name="commandLineInput" type="text" class="vex-dialog-prompt-input" placeholder="" value="">
</div>
<hr class='border-color-light-gray'>

<p><input id="autoTail" name="autoTail" type="checkbox"> Wait for task to start, then start tailing:</p>

<div class="vex-dialog-input">
<input id='filename' name="filename" type="text" class="vex-dialog-prompt-input" placeholder="e.g. service.log" value="">
</div>
104 changes: 96 additions & 8 deletions SingularityUI/app/views/request.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
View = require './view'

Deploy = require '../models/Deploy'
TaskFiles = require '../collections/TaskFiles'

interval = (a, b) -> setInterval(b, a) # f u javascript
timeout = (a, b) -> setTimeout(b, a)

AUTO_TAIL_TIMEOUT = 5 * 60 * 1000

class RequestView extends View

@@ -22,11 +28,11 @@ class RequestView extends View

'click [data-action="expand-deploy-history"]': 'flashDeployHistory'

initialize: ({@requestId}) ->
initialize: ({@requestId, @history, @activeTasks}) ->

render: ->
@$el.html @template
config: config
config: config

# Attach subview elements
@$('#header').html @subviews.header.$el
@@ -54,11 +60,15 @@ class RequestView extends View
app.router.navigate 'requests', trigger: true

runRequest: (e) =>
@model.promptRun =>
@trigger 'refreshrequest'
setTimeout =>
@model.promptRun (data) =>
# If user wants to redirect to a file after the task starts
if data.autoTail is 'on'
@autoTailFilename = data.filename
@autoTailTimestamp = +new Date()
@startAutoTailPolling()
else
@trigger 'refreshrequest'
, 2500
setTimeout ( => @trigger 'refreshrequest'), 2500

scaleRequest: (e) =>
@model.promptScale =>
@@ -81,13 +91,91 @@ class RequestView extends View

@model.promptRun =>
@subviews.scheduledTasks.collection.remove id
@subviews.scheduledTasks.render()

@subviews.scheduledTasks.render()
setTimeout =>
@trigger 'refreshrequest'
, 3000

flashDeployHistory: ->
@subviews.deployHistory.flash()

# Start polling for task changes, and check
# Task History changes in case we need
# to back out of the file redirect
startAutoTailPolling: ->
@showAutoTailWaitingDialog()
@stopAutoTailPolling()

@listenTo @history, 'reset', @handleHistoryReset
@listenToOnce @activeTasks, 'add', @handleActiveTasksAdd

@autoTailPollInterval = interval 2000, =>
if @autoTailTaskFiles
@autoTailTaskFiles.fetch().error -> app.caughtError() # we don't care about errors in this situation
else
@history.fetch()
@activeTasks.fetch()

@autoTailTimeout = timeout 60000, =>
@stopAutoTailPolling()
vex.close()
vex.dialog.alert
message: """
<h3>Failure</h3>
<code>#{ @autoTailFilename }</code> did not exist after #{ Math.floor(AUTO_TAIL_TIMEOUT / 60000) } minute(s).
"""
buttons: [
$.extend _.clone(vex.dialog.buttons.YES), text: 'OK'
]

handleHistoryReset: (tasks) =>
timestamp = @autoTailTimestamp
matchingTask = tasks.find (task) -> task.get('taskId').startedAt > timestamp
if matchingTask
$('.auto-tail-checklist').addClass 'waiting-for-file'
@stopListening @activeTasks, 'add'
@autoTailTaskFiles = new TaskFiles [], taskId: matchingTask.get('id')

handleActiveTasksAdd: (task) =>
$('.auto-tail-checklist').addClass 'waiting-for-file'
@autoTailTaskId = task.get('id')
@autoTailTaskFiles = new TaskFiles [], taskId: @autoTailTaskId
@listenTo @autoTailTaskFiles, 'add', @handleTaskFilesAdd

handleTaskFilesAdd: =>
if @autoTailTaskFiles.findWhere({name: @autoTailFilename})
@stopAutoTailPolling()
@stopListening @history, 'reset', @handleHistoryReset
app.router.navigate "#task/#{@autoTailTaskId}/tail/#{@autoTailTaskId}/#{@autoTailFilename}", trigger: true
vex.close()

stopAutoTailPolling: ->
if @autoTailPollInterval
clearInterval @autoTailPollInterval
if @autoTailTimeout
clearTimeout @autoTailTimeout
@stopListening @activeTasks, 'add', @handleActiveTasksAdd
@stopListening @history, 'reset', @handleHistoryReset
if @autoTailTaskFiles
@stopListening @autoTailTaskFiles, 'add', @handleTaskFilesAdd
@autoTailTaskFiles = null

## Prompt for cancelling the redirect after it's been initiated
showAutoTailWaitingDialog: ->
vex.dialog.alert
overlayClosesOnClick: false
message: """
<h3>Launching</h3>
<ol class="auto-tail-checklist">
<li class="auto-tail-task-start">Waiting for task to launch</li>
<li class="auto-tail-file-exists">Waiting for <code>#{ @autoTailFilename }</code> to exist</li>
</ol>
"""
buttons: [
$.extend _.clone(vex.dialog.buttons.NO), text: 'Close'
]
callback: (data) =>
@stopAutoTailPolling()


module.exports = RequestView

0 comments on commit 6642494

Please sign in to comment.