jasquat 18600189c8 Feature/background proc with celery (#788)
* WIP: some initial test code to test out celery w/ burnettk

* some cleanup for celery and added base model to put tasks waiting on timers

* removed dup bpmn file

* some more cleanup and added strategy to queue instructions

* some minor code changes w/ burnettk

* remove the unused next_task key from api calls since nobody uses it w/ burnettk essweine

* added migration for future tasks and added test to make sure we are inserting into it w/ burnettk essweine

* ensure future task run at time can be updated w/ burnettk

* added table to queue instructions for end user in w/ burnettk

* added test to ensure we are storing instructions for end users w/ burnettk

* added progress page to display new instructions to user

* ignore dup instructions on db insert w/ burnettk

* some more updates for celery w/ burnettk

* some pyl and test fixes w/ burnettk

* fixed tests w/ burnettk

* WIP: added in page to show instructions on pi show page w/ burnettk

* pi show page is fully using not interstitial now w/ burnettk

* fixed broken test w/ burnettk

* moved background processing items to own module w/ burnettk

* fixed apscheduler start script

* updated celery task queue to handle future tasks and upgraded black and set its line-length to match ruff w/ burnettk

* added support to run future tasks using countdown w/ burnettk

* build image for celery branch w/ burnettk

* poet does not exist in the image w/ burnettk

* start blocking scheduler should always start the scheduler w/ burnettk

* add init and stuff for this branch

* make this work not just on my mac

* send other args to only

* added running status for process instance and use that on fe to go to show page and added additional identifier to locking system to isolate celery workers better w/ burnettk

* fixed typing error that typeguard found, not sure why mypy did not w/ burnettk

* do not check for no instructions on interstitial page for cypress tests on frontend w/ burnettk

* do not queue process instances twice w/ burnettk

* removed bad file w/ burnettk

* queue tasks using strings to avoid circular imports when attmepting to queue w/ burnettk

* only queue imminent new timer events and mock celery

* some keyboard shortcut support on frontend and added ability to force run a process instance over the api w/ burnettk

* some styles added for the shortcut menu w/ burnettk

* pyl w/ burnettk

* fixed test w/ burnettk

* removed temporary celery script and added support for celery worker in run server locally w/ burnettk

* cleaned up migrations w/ burnettk

* created new migration to clean up old migrations

---------

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
Co-authored-by: burnettk <burnettk@users.noreply.github.com>
2023-12-05 11:41:59 -05:00

203 lines
7.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { modifyProcessIdentifierForPathParam } from '../../src/helpers';
import { miscDisplayName } from './helpers';
import 'cypress-file-upload';
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
Cypress.Commands.add('getBySel', (selector, ...args) => {
return cy.get(`[data-qa=${selector}]`, ...args);
});
Cypress.Commands.add('navigateToHome', () => {
cy.getBySel('header-menu-expand-button').click();
cy.getBySel('side-nav-items').contains('Home').click();
});
Cypress.Commands.add('navigateToAdmin', () => {
cy.visit('/process-groups');
});
Cypress.Commands.add('login', (username, password) => {
cy.visit('/process-groups');
let usernameToUse = username;
let passwordToUse = password;
if (!usernameToUse) {
usernameToUse =
Cypress.env('SPIFFWORKFLOW_FRONTEND_USERNAME') || 'ciadmin1';
passwordToUse =
Cypress.env('SPIFFWORKFLOW_FRONTEND_PASSWORD') || 'ciadmin1';
}
cy.get('#username').type(usernameToUse);
cy.get('#password').type(passwordToUse);
if (Cypress.env('SPIFFWORKFLOW_FRONTEND_AUTH_WITH_KEYCLOAK') === true) {
cy.get('#kc-login').click();
} else {
cy.get('#spiff-login-button').click();
}
});
Cypress.Commands.add('logout', (_selector, ..._args) => {
cy.wait(2000);
// click the profile thingy in the top right
cy.get('.user-profile-toggletip-button').click();
cy.getBySel('logout-button').click();
if (Cypress.env('SPIFFWORKFLOW_FRONTEND_AUTH_WITH_KEYCLOAK') === true) {
// otherwise we can click logout, quickly load the next page, and the javascript
// doesn't have time to actually sign you out
// cy.wait(4000);
cy.contains('Sign in to your account');
} else {
cy.get('#spiff-login-button').should('exist');
}
});
Cypress.Commands.add('createGroup', (groupId, groupDisplayName) => {
cy.contains(groupId).should('not.exist');
cy.contains('Add a process group').click();
cy.get('input[name=display_name]').type(groupDisplayName);
cy.get('input[name=display_name]').should('have.value', groupDisplayName);
cy.get('input[name=id]').should('have.value', groupId);
cy.contains('Submit').click();
cy.url().should('include', `process-groups/${groupId}`);
cy.contains(`Process Group: ${groupDisplayName}`);
});
Cypress.Commands.add('createModel', (groupId, modelId, modelDisplayName) => {
cy.contains(modelId).should('not.exist');
cy.contains('Add a process model').click();
cy.get('input[name=display_name]').type(modelDisplayName);
cy.get('input[name=display_name]').should('have.value', modelDisplayName);
cy.get('input[name=id]').should('have.value', modelId);
cy.contains('Submit').click();
cy.url().should(
'include',
`process-models/${modifyProcessIdentifierForPathParam(groupId)}:${modelId}`
);
cy.contains(`Process Model: ${modelDisplayName}`);
});
// Intended to be run from the process model show page
Cypress.Commands.add(
'runPrimaryBpmnFile',
(expectAutoRedirectToHumanTask = false, returnToProcessModelShow = true) => {
cy.getBySel('start-process-instance').click();
if (expectAutoRedirectToHumanTask) {
// the url changes immediately, so also make sure we get some content from the next page, "Task:",
// or else when we try to interact with the page, it'll re-render and we'll get an error with cypress.
cy.url().should('include', `/tasks/`);
cy.contains('Task: ', { timeout: 30000 });
} else {
cy.url().should('include', `/process-instances`);
cy.contains('Process Instance Id');
cy.contains('complete');
if (returnToProcessModelShow) {
cy.getBySel('process-model-breadcrumb-link').click();
cy.getBySel('process-model-show-permissions-loaded').should('exist');
}
}
}
);
Cypress.Commands.add(
'navigateToProcessModel',
(groupDisplayName, modelDisplayName) => {
cy.navigateToAdmin();
cy.contains(miscDisplayName).click();
cy.contains(`Process Group: ${miscDisplayName}`, { timeout: 10000 });
cy.contains(groupDisplayName).click();
cy.contains(`Process Group: ${groupDisplayName}`);
// https://stackoverflow.com/q/51254946/6090676
cy.getBySel('process-model-show-link').contains(modelDisplayName).click();
cy.contains(`Process Model: ${modelDisplayName}`);
}
);
Cypress.Commands.add(
'basicPaginationTest',
(
dataQaTagToUseToEnsureTableHasLoaded = 'paginated-entity-id',
paginationOptionsDataQa = 'pagination-options'
) => {
cy.getBySel(paginationOptionsDataQa).scrollIntoView();
cy.getBySel(paginationOptionsDataQa)
.find('.cds--select__item-count')
.find('.cds--select-input')
.select('2');
// NOTE: this is a em dash instead of en dash
cy.contains(/\b12 of \d+/);
// ok, trying to ensure that we have everything loaded before we leave this
// function and try to sign out. Just showing results 1-2 of blah is not good enough,
// since the ajax request may not have finished yet.
// to be sure it's finished, grab the log id from page 1. remember it.
// then use the magical contains command that waits for the element to exist AND
// for that element to contain the text we're looking for.
cy.getBySel(dataQaTagToUseToEnsureTableHasLoaded)
.first()
.then(($element) => {
const oldId = $element.text().trim();
cy.getBySel(paginationOptionsDataQa)
.find('.cds--pagination__button--forward')
.click();
cy.getBySel(paginationOptionsDataQa)
.contains(`[data-qa=${dataQaTagToUseToEnsureTableHasLoaded}]`, oldId)
.should('not.exist');
cy.getBySel(paginationOptionsDataQa).contains(/\b34 of \d+/);
cy.getBySel(paginationOptionsDataQa)
.find('.cds--pagination__button--backward')
.click();
cy.getBySel(paginationOptionsDataQa).contains(/\b12 of \d+/);
cy.contains(`[data-qa=${dataQaTagToUseToEnsureTableHasLoaded}]`, oldId);
});
}
);
Cypress.Commands.add('assertAtLeastOneItemInPaginatedResults', () => {
cy.contains(/\b[1-9]\d*[1-9]\d* of [1-9]\d*/);
});
Cypress.Commands.add('assertNoItemInPaginatedResults', () => {
cy.contains(/\b00 of 0 items/);
});
Cypress.Commands.add('deleteProcessModelAndConfirm', (buttonId, groupId) => {
cy.getBySel(buttonId).click();
cy.contains('Are you sure');
cy.getBySel('delete-process-model-button-modal-confirmation-dialog')
.find('.cds--btn--danger')
.click();
cy.url().should(
'include',
`process-groups/${modifyProcessIdentifierForPathParam(groupId)}`
);
});