Skip to content

Commit

Permalink
Handle timeouts on creating templates (#70635)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
Corey Robertson and elasticmachine authored Jul 3, 2020
1 parent a916e0a commit 571a610
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { EuiBasicTableColumn } from '@elastic/eui';
import { Paginate, PaginateChildProps } from '../paginate';
import { TagList } from '../tag_list';
import { getTagsFilter } from '../../lib/get_tags_filter';
// @ts-ignore untyped local
// @ts-expect-error
import { extractSearch } from '../../lib/extract_search';
import { ComponentStrings } from '../../../i18n';
import { CanvasTemplate } from '../../../types';
Expand Down Expand Up @@ -61,7 +61,7 @@ export class WorkpadTemplates extends React.PureComponent<
WorkpadTemplatesState
> {
static propTypes = {
createFromTemplate: PropTypes.func.isRequired,
onCreateFromTemplate: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
templates: PropTypes.object,
};
Expand Down
19 changes: 10 additions & 9 deletions x-pack/plugins/canvas/server/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ import { light } from './theme_light';

import { TEMPLATE_TYPE } from '../../common/lib/constants';

export const templates = [pitch, status, summary, dark, light];
export const templates = [status, summary, dark, light, pitch];

export async function initializeTemplates(
client: Pick<SavedObjectsRepository, 'bulkCreate' | 'find'>
client: Pick<SavedObjectsRepository, 'bulkCreate' | 'create' | 'find'>
) {
const existingTemplates = await client.find({ type: TEMPLATE_TYPE, perPage: 1 });

if (existingTemplates.total === 0) {
const templateObjects = templates.map((template) => ({
id: template.id,
type: TEMPLATE_TYPE,
attributes: template,
}));

client.bulkCreate(templateObjects);
// Some devs were seeing timeouts that would cause an unhandled promise rejection
// likely because the pitch template is so huge.
// So, rather than doing a bulk create of templates, we're going to fire off individual
// creates and catch and throw-away any errors that happen.
// Once packages are ready, we should probably move that pitch that is so large to a package
for (const template of templates) {
client.create(TEMPLATE_TYPE, template, { id: template.id }).catch((err) => undefined);
}
}
}

0 comments on commit 571a610

Please sign in to comment.