Skip to content

Commit 9227872

Browse files
flovilmartnatanrolnik
authored andcommitted
Restore jobs scheduling interface and capabilities (#728)
1 parent 181519c commit 9227872

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

src/dashboard/Data/Jobs/Jobs.react.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Toolbar from 'components/Toolbar/Toolbar.react';
2727

2828
let subsections = {
2929
all: 'All Jobs',
30-
/*scheduled: 'Scheduled Jobs',*/
30+
scheduled: 'Scheduled Jobs',
3131
status: 'Job Status'
3232
};
3333

@@ -109,8 +109,8 @@ export default class Jobs extends TableView {
109109
let current = this.props.params.section || '';
110110
return (
111111
<CategoryList current={current} linkPrefix={'jobs/'} categories={[
112-
/* { name: 'Scheduled Jobs', id: 'scheduled' }, */
113112
{ name: 'All Jobs', id: 'all' },
113+
{ name: 'Scheduled Jobs', id: 'scheduled' },
114114
{ name: 'Job Status', id: 'status' }
115115
]} />
116116
);
@@ -225,7 +225,23 @@ export default class Jobs extends TableView {
225225

226226
tableData() {
227227
let data = undefined;
228-
if (this.props.params.section === 'scheduled' || this.props.params.section === 'all' ) {
228+
if (this.props.params.section === 'all') {
229+
if (this.props.availableJobs) {
230+
data = this.props.availableJobs;
231+
}
232+
if (this.props.jobsInUse) {
233+
if (data) {
234+
data = data.concat(this.props.jobsInUse);
235+
} else {
236+
data = this.props.jobsInUse;
237+
}
238+
}
239+
if (data) {
240+
data = data.map((jobName) => {
241+
return { jobName };
242+
});
243+
}
244+
} else if (this.props.params.section === 'scheduled' ) {
229245
if (this.props.jobs.data) {
230246
let jobs = this.props.jobs.data.get('jobs');
231247
if (jobs) {

src/dashboard/Data/Jobs/JobsData.react.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default class JobsData extends React.Component {
2929
() => this.setState({ release: null })
3030
);
3131
}
32-
32+
*/
3333
fetchJobs(app) {
3434
app.getAvailableJobs().then(
3535
({ jobs, in_use }) => {
@@ -43,17 +43,15 @@ export default class JobsData extends React.Component {
4343
}, () => this.setState({ jobs: [], inUse: [] })
4444
);
4545
}
46-
*/
4746

4847
componentDidMount() {
49-
// this.fetchJobs(this.context.currentApp);
48+
this.fetchJobs(this.context.currentApp);
5049
// this.fetchRelease(this.context.currentApp);
5150
}
5251

5352
componentWillReceiveProps(props, context) {
5453
if (this.context !== context) {
55-
this.setState({ release: undefined, jobs: undefined, inUse: undefined });
56-
// this.fetchJobs(context.currentApp);
54+
this.fetchJobs(context.currentApp);
5755
// this.fetchRelease(context.currentApp);
5856
}
5957
}

src/lib/ParseApp.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,22 +506,26 @@ export default class ParseApp {
506506
}
507507

508508
getAvailableJobs() {
509-
let path = '/apps/' + this.slug + '/cloud_code/jobs/data';
510-
return Parse._request('GET', path);
509+
let path = 'cloud_code/jobs/data';
510+
return this.apiRequest('GET', path, {}, { useMasterKey: true });
511511
}
512512

513513
getJobStatus() {
514-
// Cache it for a minute
514+
// Cache it for a 30s
515+
if (new Date() - this.jobStatus.lastFetched < 30000) {
516+
return Parse.Promise.as(this.jobStatus.status);
517+
}
515518
let query = new Parse.Query('_JobStatus');
516519
query.descending('createdAt');
517520
return query.find({ useMasterKey: true }).then((status) => {
521+
status = status.map((jobStatus) => {
522+
return jobStatus.toJSON();
523+
});
518524
this.jobStatus = {
519525
status: status || null,
520526
lastFetched: new Date()
521527
};
522-
return status.map((jobStatus) => {
523-
return jobStatus.toJSON();
524-
});
528+
return status;
525529
});
526530
}
527531

src/lib/stores/JobsStore.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* This source code is licensed under the license found in the LICENSE file in
66
* the root directory of this source tree.
77
*/
8-
import * as AJAX from 'lib/AJAX';
98
import keyMirror from 'lib/keyMirror';
109
import Parse from 'parse';
1110
import { Map, List } from 'immutable';
@@ -34,16 +33,16 @@ function JobsStore(state, action) {
3433
return Map({ lastFetch: new Date(), jobs: List(results) });
3534
});
3635
case ActionTypes.CREATE:
37-
path = `/apps/${action.app.slug}/cloud_code/jobs`;
38-
return AJAX.post(path, action.schedule).then((result) => {
36+
path = `cloud_code/jobs`;
37+
return Parse._request('POST', path, action.schedule, {useMasterKey: true}).then((result) => {
3938
let { ...schedule } = action.schedule.job_schedule;
4039
schedule.objectId = result.objectId;
4140
schedule.startAfter = schedule.startAfter || new Date().toISOString();
4241
return state.set('jobs', state.get('jobs').push(schedule));
4342
});
4443
case ActionTypes.EDIT:
45-
path = `/apps/${action.app.slug}/cloud_code/jobs/${action.jobId}`;
46-
return AJAX.put(path, action.updates).then(() => {
44+
path = `cloud_code/jobs/${action.jobId}`;
45+
return Parse._request('PUT', path, action.updates, {useMasterKey: true}).then(() => {
4746
let index = state.get('jobs').findIndex((j) => j.objectId === action.jobId);
4847
let current = state.get('jobs').get(index);
4948
let { ...update } = action.updates.job_schedule;
@@ -52,8 +51,8 @@ function JobsStore(state, action) {
5251
return state.set('jobs', state.get('jobs').set(index, update));
5352
});
5453
case ActionTypes.DELETE:
55-
path = `/apps/${action.app.slug}/cloud_code/jobs/${action.jobId}`;
56-
return AJAX.del(path).then(() => {
54+
path = `cloud_code/jobs/${action.jobId}`;
55+
return Parse._request('DELETE', path, {}, {useMasterKey: true}).then(() => {
5756
let index = state.get('jobs').findIndex((j) => j.objectId === action.jobId);
5857
return state.set('jobs', state.get('jobs').delete(index));
5958
}, () => {

0 commit comments

Comments
 (0)