Skip to content

Restore jobs scheduling interface and capabilities #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/dashboard/Data/Jobs/Jobs.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Toolbar from 'components/Toolbar/Toolbar.react';

let subsections = {
all: 'All Jobs',
/*scheduled: 'Scheduled Jobs',*/
scheduled: 'Scheduled Jobs',
status: 'Job Status'
};

Expand Down Expand Up @@ -109,8 +109,8 @@ export default class Jobs extends TableView {
let current = this.props.params.section || '';
return (
<CategoryList current={current} linkPrefix={'jobs/'} categories={[
/* { name: 'Scheduled Jobs', id: 'scheduled' }, */
{ name: 'All Jobs', id: 'all' },
{ name: 'Scheduled Jobs', id: 'scheduled' },
{ name: 'Job Status', id: 'status' }
]} />
);
Expand Down Expand Up @@ -225,7 +225,23 @@ export default class Jobs extends TableView {

tableData() {
let data = undefined;
if (this.props.params.section === 'scheduled' || this.props.params.section === 'all' ) {
if (this.props.params.section === 'all') {
if (this.props.availableJobs) {
data = this.props.availableJobs;
}
if (this.props.jobsInUse) {
if (data) {
data = data.concat(this.props.jobsInUse);
} else {
data = this.props.jobsInUse;
}
}
if (data) {
data = data.map((jobName) => {
return { jobName };
});
}
} else if (this.props.params.section === 'scheduled' ) {
if (this.props.jobs.data) {
let jobs = this.props.jobs.data.get('jobs');
if (jobs) {
Expand Down
8 changes: 3 additions & 5 deletions src/dashboard/Data/Jobs/JobsData.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class JobsData extends React.Component {
() => this.setState({ release: null })
);
}

*/
fetchJobs(app) {
app.getAvailableJobs().then(
({ jobs, in_use }) => {
Expand All @@ -43,17 +43,15 @@ export default class JobsData extends React.Component {
}, () => this.setState({ jobs: [], inUse: [] })
);
}
*/

componentDidMount() {
// this.fetchJobs(this.context.currentApp);
this.fetchJobs(this.context.currentApp);
// this.fetchRelease(this.context.currentApp);
}

componentWillReceiveProps(props, context) {
if (this.context !== context) {
this.setState({ release: undefined, jobs: undefined, inUse: undefined });
// this.fetchJobs(context.currentApp);
this.fetchJobs(context.currentApp);
// this.fetchRelease(context.currentApp);
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/lib/ParseApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,22 +506,26 @@ export default class ParseApp {
}

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

getJobStatus() {
// Cache it for a minute
// Cache it for a 30s
if (new Date() - this.jobStatus.lastFetched < 30000) {
return Parse.Promise.as(this.jobStatus.status);
}
let query = new Parse.Query('_JobStatus');
query.descending('createdAt');
return query.find({ useMasterKey: true }).then((status) => {
status = status.map((jobStatus) => {
return jobStatus.toJSON();
});
this.jobStatus = {
status: status || null,
lastFetched: new Date()
};
return status.map((jobStatus) => {
return jobStatus.toJSON();
});
return status;
});
}

Expand Down
13 changes: 6 additions & 7 deletions src/lib/stores/JobsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
import * as AJAX from 'lib/AJAX';
import keyMirror from 'lib/keyMirror';
import Parse from 'parse';
import { Map, List } from 'immutable';
Expand Down Expand Up @@ -34,16 +33,16 @@ function JobsStore(state, action) {
return Map({ lastFetch: new Date(), jobs: List(results) });
});
case ActionTypes.CREATE:
path = `/apps/${action.app.slug}/cloud_code/jobs`;
return AJAX.post(path, action.schedule).then((result) => {
path = `cloud_code/jobs`;
return Parse._request('POST', path, action.schedule, {useMasterKey: true}).then((result) => {
let { ...schedule } = action.schedule.job_schedule;
schedule.objectId = result.objectId;
schedule.startAfter = schedule.startAfter || new Date().toISOString();
return state.set('jobs', state.get('jobs').push(schedule));
});
case ActionTypes.EDIT:
path = `/apps/${action.app.slug}/cloud_code/jobs/${action.jobId}`;
return AJAX.put(path, action.updates).then(() => {
path = `cloud_code/jobs/${action.jobId}`;
return Parse._request('PUT', path, action.updates, {useMasterKey: true}).then(() => {
let index = state.get('jobs').findIndex((j) => j.objectId === action.jobId);
let current = state.get('jobs').get(index);
let { ...update } = action.updates.job_schedule;
Expand All @@ -52,8 +51,8 @@ function JobsStore(state, action) {
return state.set('jobs', state.get('jobs').set(index, update));
});
case ActionTypes.DELETE:
path = `/apps/${action.app.slug}/cloud_code/jobs/${action.jobId}`;
return AJAX.del(path).then(() => {
path = `cloud_code/jobs/${action.jobId}`;
return Parse._request('DELETE', path, {}, {useMasterKey: true}).then(() => {
let index = state.get('jobs').findIndex((j) => j.objectId === action.jobId);
return state.set('jobs', state.get('jobs').delete(index));
}, () => {
Expand Down