Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d8a0a1c

Browse files
committedFeb 8, 2021
fix: add delay after create/update operations
1 parent 4958678 commit d8a0a1c

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed
 

‎src/constants/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export const POSITION_CANDIDATES_PER_PAGE = 5;
2727
*/
2828
export const INPUT_DEBOUNCE_DELAY = 200;
2929

30+
/**
31+
* The delay in milliseconds we are giving to ElasticSearch of re-index changes
32+
*/
33+
export const ES_REINDEX_DELAY = 3000;
34+
3035
/**
3136
* Position statuses
3237
*/

‎src/services/jobs.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44
import { axiosInstance as axios } from "./requestInterceptor";
55
import config from "../../config";
6+
import { ES_REINDEX_DELAY } from "../constants";
7+
import { delay } from "utils/helpers";
68

79
/**
810
* Get job by id.
@@ -40,7 +42,14 @@ export const getEmptyJob = (teamId) => {
4042
* @returns {Promise<{}>} job object
4143
*/
4244
export const createJob = (data) => {
43-
return axios.post(`${config.API.V5}/jobs`, data);
45+
return (
46+
axios
47+
.post(`${config.API.V5}/jobs`, data)
48+
// temporary fix:
49+
// after creating a job we are reloading the list of jobs
50+
// so we have to wait a bit to make sure job is indexed in the ES
51+
.then((response) => delay(ES_REINDEX_DELAY).then(() => response))
52+
);
4453
};
4554

4655
/**
@@ -51,5 +60,12 @@ export const createJob = (data) => {
5160
* @returns {Promise<{}>} job object
5261
*/
5362
export const updateJob = (data, jobId) => {
54-
return axios.put(`${config.API.V5}/jobs/${jobId}`, data);
63+
return (
64+
axios
65+
.put(`${config.API.V5}/jobs/${jobId}`, data)
66+
// temporary fix:
67+
// after updating a job we are reloading the list of jobs
68+
// so we have to wait a bit to make sure job is indexed in the ES
69+
.then((response) => delay(ES_REINDEX_DELAY).then(() => response))
70+
);
5571
};

‎src/services/resourceBookings.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44
import { axiosInstance as axios } from "./requestInterceptor";
55
import config from "../../config";
6+
import { delay } from "utils/helpers";
7+
import { ES_REINDEX_DELAY } from "constants";
68

79
/**
810
* Get resource booking by id.
@@ -21,8 +23,11 @@ export const getReourceBookingById = (resourceBookingId) => {
2123
* @returns {Promise<{}>} resource booking object
2224
*/
2325
export const updateReourceBooking = (data, resourceBookingId) => {
24-
return axios.put(
25-
`${config.API.V5}/resourceBookings/${resourceBookingId}`,
26-
data
26+
return (
27+
axios
28+
.put(`${config.API.V5}/resourceBookings/${resourceBookingId}`, data) // temporary fix:
29+
// after updating a resource booking we are reloading the list of resource bookings
30+
// so we have to wait a bit to make sure job is indexed in the ES
31+
.then((response) => delay(ES_REINDEX_DELAY).then(() => response))
2732
);
2833
};

‎src/utils/helpers.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Helper utilities
3+
*
4+
* This file should contain helper methods which cannot be grouped into a separate file like we did for "format.js".
5+
* If there are multiple methods which could be grouped into a separate file by their meaning they should be extracted from here to not make this file too big.
6+
*/
7+
8+
/**
9+
* Delay code for some milliseconds using promise.
10+
*
11+
* @param {Number} duration duration in milliseconds
12+
*
13+
* @returns {Promise<void>} promise
14+
*/
15+
export const delay = (duration) =>
16+
new Promise((resolve) => {
17+
setTimeout(resolve, duration);
18+
});

0 commit comments

Comments
 (0)
This repository has been archived.