Cast status property to Status type
This commit is contained in:
@@ -28,6 +28,6 @@ ReactDOM.render(
|
|||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<App />
|
<App />
|
||||||
</Provider>
|
</Provider>
|
||||||
),
|
),
|
||||||
document.getElementById('root'),
|
document.getElementById('root'),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { combineEpics, Epic, ofType } from 'redux-observable';
|
import { combineEpics, Epic } from 'redux-observable';
|
||||||
import { filter, map, tap, ignoreElements } from 'rxjs/operators';
|
import { filter, map, tap, ignoreElements } from 'rxjs/operators';
|
||||||
import { isActionOf } from 'typesafe-actions';
|
import { isActionOf } from 'typesafe-actions';
|
||||||
|
|
||||||
@@ -8,13 +8,6 @@ import * as workloadsActions from './actions';
|
|||||||
|
|
||||||
type AppEpic = Epic<RootAction, RootAction, RootState>;
|
type AppEpic = Epic<RootAction, RootAction, RootState>;
|
||||||
|
|
||||||
|
|
||||||
// import { WorkloadService } from './services';
|
|
||||||
// const workloadService = new WorkloadService();
|
|
||||||
// workloadService.create({ complexity: 1 })
|
|
||||||
// .then(console.log.bind(console, 'workloadService create'));
|
|
||||||
|
|
||||||
|
|
||||||
const logWorkloadSubmissions: AppEpic = (action$, state$) => (
|
const logWorkloadSubmissions: AppEpic = (action$, state$) => (
|
||||||
action$.pipe(
|
action$.pipe(
|
||||||
filter(isActionOf(workloadsActions.submit)),
|
filter(isActionOf(workloadsActions.submit)),
|
||||||
@@ -29,4 +22,4 @@ export const epics = combineEpics(
|
|||||||
logWorkloadSubmissions,
|
logWorkloadSubmissions,
|
||||||
);
|
);
|
||||||
|
|
||||||
export default epics;
|
export default epics;
|
||||||
|
|||||||
@@ -3,18 +3,18 @@ import moment from 'moment';
|
|||||||
import { Status } from './types';
|
import { Status } from './types';
|
||||||
|
|
||||||
|
|
||||||
export class WorkloadService {
|
export class WorkloadService {
|
||||||
|
|
||||||
private workLoads: { [key in number]: Work } = {};
|
private workLoads: { [key in number]: Work } = {};
|
||||||
private counter = 0;
|
private counter = 0;
|
||||||
|
|
||||||
|
|
||||||
private getWorkload(id: number): Work | undefined {
|
private getWorkload(id: number): Work | undefined {
|
||||||
return this.workLoads[id];
|
return this.workLoads[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
private completeWorkload(work: Work) {
|
private completeWorkload(work: Work) {
|
||||||
work.status = work.id % 2
|
work.status = work.id % 2
|
||||||
? 'FAILURE'
|
? 'FAILURE'
|
||||||
: 'SUCCESS';
|
: 'SUCCESS';
|
||||||
}
|
}
|
||||||
@@ -22,8 +22,8 @@ export class WorkloadService {
|
|||||||
|
|
||||||
public create({ complexity }: { complexity: number }) {
|
public create({ complexity }: { complexity: number }) {
|
||||||
const id = this.counter++;
|
const id = this.counter++;
|
||||||
const status = 'WORKING';
|
const status: Status = 'WORKING';
|
||||||
|
|
||||||
const milliseconds = complexity * 1000;
|
const milliseconds = complexity * 1000;
|
||||||
const completeDate = moment().add(complexity, 'second').toDate();
|
const completeDate = moment().add(complexity, 'second').toDate();
|
||||||
const timer = setTimeout(() => this.completeWorkload(work), milliseconds);
|
const timer = setTimeout(() => this.completeWorkload(work), milliseconds);
|
||||||
@@ -50,7 +50,7 @@ export class WorkloadService {
|
|||||||
const work = this.getWorkload(id);
|
const work = this.getWorkload(id);
|
||||||
if (!work) return Promise.reject('Workload not found');
|
if (!work) return Promise.reject('Workload not found');
|
||||||
if (work.status !== 'WORKING') return Promise.reject('Workload cannot be canceled');
|
if (work.status !== 'WORKING') return Promise.reject('Workload cannot be canceled');
|
||||||
|
|
||||||
clearTimeout(work.timer)
|
clearTimeout(work.timer)
|
||||||
work.status = 'CANCELED';
|
work.status = 'CANCELED';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user