Skip to content

Commit

Permalink
set default log file by job outcome
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
markgrahamdawson committed Dec 10, 2024
1 parent eff665f commit 8f97803
Showing 1 changed file with 50 additions and 23 deletions.
73 changes: 50 additions & 23 deletions src/views/Log.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<script>
import { ref, computed } from 'vue'
import { usePrevious, whenever } from '@vueuse/core'
import { useStore } from 'vuex'
import { useStore, mapGetters } from 'vuex'
import {
mdiClockOutline,
mdiFileAlertOutline,
Expand Down Expand Up @@ -248,27 +248,6 @@ const LOG_FILE_DEFAULTS = [
/^scheduler\/*/
]

/**
* Return the default log file from the given log filenames, if there is a
* matching filename. Relies on the filenames having been sorted in descending
* order.
*
* @param {string[]} logFiles - list of available log filenames
* @returns {?string}
*/
export const getDefaultFile = (logFiles) => {
if (logFiles.length) {
for (const filePattern of LOG_FILE_DEFAULTS) {
for (const fileName of logFiles) {
if (filePattern.exec(fileName)) {
return fileName
}
}
}
}
return null // rather than undefined
}

class Results {
constructor () {
/** @type {string[]} */
Expand Down Expand Up @@ -455,10 +434,17 @@ export default {
},

computed: {
...mapGetters('workflows', ['getNodes']),
workflowTokens () {
// tokens for the workflow this view was opened for
return new Tokens(this.workflowId)
},
workflowIDs () {
return [this.workflowId]
},
workflows () {
return this.getNodes('workflow', this.workflowIDs)
},
id () {
// the ID of the workflow/task/job we are subscribed to
// OR null if not subscribed
Expand All @@ -474,6 +460,18 @@ export default {
}
}
return this.workflowId
},
workflowStatus () {
if (this.workflows[0].node.stateTotals.failed) {
return 'failed'
}
if (this.workflows[0].node.stateTotals.submitted | this.workflows[0].node.stateTotals.running | this.workflows[0].node.stateTotals.succeeded) {
return 'succeeded'
}
if (this.workflows[0].node.stateTotals['submit-failed']) {
return 'submit-failed'
}
return 0
}
},

Expand Down Expand Up @@ -503,6 +501,35 @@ export default {
/* isGlobalCallback */ false
)
},
/**
* Return the default log file from the given log filenames, if there is a
* matching filename. Relies on the filenames having been sorted in descending
* order.
*
* @param {string[]} logFiles - list of available log filenames
* @returns {?string}
*/
getDefaultFile (logFiles) {
if (this.workflowStatus === 'failed') {
return 'job.err'
}
if (this.workflowStatus === 'submit-failed') {
return 'job-activity.log'
}

if (logFiles.length) {
// loop through all the options in LOG_FILE_DEFAULTS
for (const filePattern of LOG_FILE_DEFAULTS) {
// Loop through all the filenames e.g.[job.out, job.status]
for (const fileName of logFiles) {
if (filePattern.exec(fileName)) {
return fileName
}
}
}
}
return null // rather than undefined
},
async updateLogFileList (reset = true) {
// if reset===true then the this.file will be reset
// otherwise it will be left alone
Expand Down Expand Up @@ -542,7 +569,7 @@ export default {
}
if (!this.file) {
// set the default log file if appropriate
this.file = getDefaultFile(logFiles)
this.file = this.getDefaultFile(logFiles)
}
}

Expand Down

0 comments on commit 8f97803

Please sign in to comment.