Skip to content

Commit

Permalink
added job run
Browse files Browse the repository at this point in the history
  • Loading branch information
RalkeyOfficial committed Jan 2, 2025
1 parent 216b8da commit cc444f8
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 0 deletions.
162 changes: 162 additions & 0 deletions src/modals/Job/RunJob.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<script setup>
import { jobStore, navigationStore } from '../../store/store.js'
</script>

<template>
<NcModal ref="modalRef"
label-id="runJob"
@close="closeModal">
<div class="modalContent">
<h2>Run job</h2>

<NcButton
:disabled="loading"
type="primary"
@click="runJob()">
<template #icon>
<NcLoadingIcon v-if="loading" :size="20" />
<Sync v-if="!loading" :size="20" />
</template>
Run job
</NcButton>

<div v-if="jobStore.jobRun">
<NcNoteCard v-if="jobStore.jobRun?.level === 'INFO'" type="success">
<p>The job run was successful. {{ jobStore.jobRun?.message }}</p>
</NcNoteCard>
<NcNoteCard v-if="(jobStore.jobRun?.level !== 'INFO') || error" type="error">
<p>An error occurred while running the job: {{ jobStore.jobRun ? jobStore.jobRun.message : error }}</p>
</NcNoteCard>
</div>

<div v-if="jobStore.jobRun" class="jobRunTable">
<table>
<tr>
<th>UUID</th>
<td>{{ jobStore.jobRun.uuid }}</td>
</tr>
<tr>
<th>Level</th>
<td>{{ jobStore.jobRun.level }}</td>
</tr>
<tr>
<th>Message</th>
<td>{{ jobStore.jobRun.message }}</td>
</tr>
<tr>
<th>Job ID</th>
<td>{{ jobStore.jobRun.jobId }}</td>
</tr>
<tr>
<th>Job List ID</th>
<td>{{ jobStore.jobRun.jobListId }}</td>
</tr>
<tr>
<th>Job Class</th>
<td>{{ jobStore.jobRun.jobClass || 'N/A' }}</td>
</tr>
<tr>
<th>Arguments</th>
<td>
<ul>
<li v-for="(value, key) in jobStore.jobRun.arguments" :key="key">
{{ key }}: {{ value }}
</li>
</ul>
</td>
</tr>
<tr>
<th>Execution Time</th>
<td>{{ jobStore.jobRun.executionTime }} ms</td>
</tr>
<tr>
<th>User ID</th>
<td>{{ jobStore.jobRun.userId || 'N/A' }}</td>
</tr>
<tr>
<th>Session ID</th>
<td>{{ jobStore.jobRun.sessionId || 'N/A' }}</td>
</tr>
<tr>
<th>Stack Trace</th>
<td>
<ol>
<li v-for="(step, index) in jobStore.jobRun.stackTrace" :key="index">
{{ step }}
</li>
</ol>
</td>
</tr>
</table>
</div>
</div>
</NcModal>
</template>

<script>
import {
NcButton,
NcModal,
NcLoadingIcon,
NcNoteCard,
} from '@nextcloud/vue'
import Sync from 'vue-material-design-icons/Sync.vue'
export default {
name: 'RunJob',
components: {
NcModal,
NcButton,
NcLoadingIcon,
NcNoteCard,
},
data() {
return {
success: false,
loading: false,
error: false,
}
},
methods: {
closeModal() {
navigationStore.setModal(false)
this.success = false
this.loading = false
this.error = false
},
async runJob() {
this.loading = true
try {
await jobStore.runJob(jobStore.jobItem.id)
this.success = true
this.loading = false
this.error = false
} catch (error) {
this.loading = false
this.success = false
this.error = error.message || 'An error occurred while running the job'
jobStore.setJobRun(false)
}
},
},
}
</script>
<style>
.runJobDetailGrid {
display: grid;
grid-template-columns: 1fr;
gap: 5px;
}
.jobRunTable th,
.jobRunTable td {
padding: 4px;
}
.jobRunTable th {
font-weight: bold
}
.jobRunTable ol {
margin-left: 1rem;
}
</style>
3 changes: 3 additions & 0 deletions src/modals/Modals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { navigationStore } from '../store/store.js'
<TestSource />
<DeleteJob />
<TestJob />
<RunJob v-if="navigationStore.modal === 'runJob'" />
<EditJob />
<DeleteLog />
<EditLog />
Expand Down Expand Up @@ -54,6 +55,7 @@ import EditSource from './Source/EditSource.vue'
import TestSource from './TestSource/TestSource.vue'
import DeleteSource from './Source/DeleteSource.vue'
import TestJob from './Job/TestJob.vue'
import RunJob from './Job/RunJob.vue'
import EditJob from './Job/EditJob.vue'
import DeleteJob from './Job/DeleteJob.vue'
import EditLog from './Log/EditLog.vue'
Expand Down Expand Up @@ -97,6 +99,7 @@ export default {
TestSource,
DeleteJob,
EditJob,
RunJob,
TestJob,
DeleteLog,
EditLog,
Expand Down
30 changes: 30 additions & 0 deletions src/store/modules/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const useJobStore = defineStore(
state: () => ({
jobItem: false,
jobTest: false,
jobRun: false,
jobList: [],
jobLog: false,
jobLogs: [],
Expand All @@ -21,6 +22,10 @@ export const useJobStore = defineStore(
this.jobTest = jobTest
console.log('Job test set to ' + jobTest)
},
setJobRun(jobRun) {
this.jobRun = jobRun
console.log('Job run set to ' + jobRun)
},
setJobList(jobList) {
this.jobList = jobList.map(
(jobItem) => new Job(jobItem),
Expand Down Expand Up @@ -141,6 +146,31 @@ export const useJobStore = defineStore(
throw err
})
},
// Run a job
async runJob(id) {
if (!id) {
throw new Error('No job item to run')
}
console.log('Running job...')

const endpoint = `/index.php/apps/openconnector/api/jobs-test/${id}`

const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify([]),
})

const data = await response.json()
this.setJobRun(data)
console.log('Job run')
// Refresh the job list
this.refreshJobLogs()

return { response, data }
},
// Create or save a job from store
saveJob(jobItem) {
if (!jobItem) {
Expand Down
7 changes: 7 additions & 0 deletions src/views/Job/JobDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import { jobStore, navigationStore, logStore } from '../../store/store.js'
</template>
Test
</NcActionButton>
<NcActionButton @click="navigationStore.setModal('runJob')">
<template #icon>
<Play :size="20" />
</template>
Run
</NcActionButton>

<NcActionButton @click="refreshJobLogs()">
<template #icon>
Expand Down Expand Up @@ -194,6 +200,7 @@ import SitemapOutline from 'vue-material-design-icons/SitemapOutline.vue'
import Update from 'vue-material-design-icons/Update.vue'
import Sync from 'vue-material-design-icons/Sync.vue'
import EyeOutline from 'vue-material-design-icons/EyeOutline.vue'
import Play from 'vue-material-design-icons/Play.vue'
import getValidISOstring from '../../services/getValidISOstring.js'
Expand Down

0 comments on commit cc444f8

Please sign in to comment.