Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Conversation

@mfix22
Copy link
Contributor

@mfix22 mfix22 commented Jul 11, 2018

(Moved PR #487 here)

This is a WIP PR that adds cronInterval support to the frontend πŸ‘

We will shortly add the backend support and merge it in with this branch. We just wanted to get this up for @n-riesco to review before doing so.

TODO:

  • Add backend support for scheduling
  • Finish off unit testing components
  • Run Prettier

mfix22 added 7 commits July 10, 2018 15:46
    Fix linting from Prettier

    get initial cron mode id from query

    Add login button to preview modal

    Move getInitialCronMode to cron-helpers

    Fix linting from Prettier

    get initial cron mode id from query

    Add login button to preview modal

    Move getInitialCronMode to cron-helpers
@mfix22 mfix22 requested a review from n-riesco July 11, 2018 23:37
@mfix22 mfix22 mentioned this pull request Jul 11, 2018
3 tasks
import ReactDataGrid from 'react-data-grid';
import ms from 'ms';
import matchSorter from 'match-sorter';
import * as prettyCron from 'prettycron';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use something lighter that doesn't depend on later: https://www.npmjs.com/package/cronstrue


const initialModeId = getInitialCronMode(props.query);

const canEdit = this.props.currentRequestor && this.props.currentRequestor === props.query.requestor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

.simulate('click');

// onSubmit is asynchronous
await wait();
Copy link
Contributor

@n-riesco n-riesco Jul 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i remember correctly, our webpack/babel/mocha setup isn't ready to use await.

Copy link
Contributor Author

@mfix22 mfix22 Jul 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. This worked for me though. Should i remove it and use setTimeout directly instead?

Copy link
Contributor

@n-riesco n-riesco Jul 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, ignore my comment. It doesn't apply any longer. We upgraded to Node 8 recently.

package.json Outdated
},
"dependencies": {
"alasql": "^0.4.5",
"cronstrue": "^1.31.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to devDependencies

});
});

it('should throw GraphQL errors on failure', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

graphQL?

});

describe('Creating Queries', () => {
it('should handle success cases', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about should schedule a query only if logged in?

});

describe('Updating Queries', () => {
it('should handle success cases', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about should update a scheduled query only if logged in?

});
});

it('should throw GraphQL errors on failure', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

garphQL?

@n-riesco
Copy link
Contributor

Looks good so far. I'd suggest the following changes:

  1. I've tested if it's possible for the Log In button to navigate directly to the Login page and it doesn't seem to break anything:

    --- a/app/components/Settings/Settings.react.js
    +++ b/app/components/Settings/Settings.react.js
    @@ -25,7 +25,7 @@ class Settings extends Component {
             this.renderSettingsForm = this.renderSettingsForm.bind(this);
             this.updateSelectedPanel = this.updateSelectedPanel.bind(this);
             this.openScheduler = this.openScheduler.bind(this);
    -        this.openLogin = this.updateSelectedPanel.bind(this, 3);
    +        this.openLogin = () => window.location.assign('/login');
             this.state = {
                 editMode: true,
                 selectedPanel: {},
  2. (after the on-prem release) I'd like to use a better default than DEFAULT_REFRESH_INTERVAL (I know that the monthly case isn't possible, but we use the maximum value setInterval can take).


How's the work on the backend progressing?

const spy = sinon.spy();
const refreshInterval = 1; // second
const refreshInterval = 5; // 5 seconds
const cronInterval = `*/${refreshInterval} * * * * *`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should keep the units for testing the old format (i.e. undefined cronInterval).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with keeping refreshInterval is that it is handled differently in the queryScheduler.scheduleQuery call. Currently, refresh intervals are mapped to their corresponding cron expression before being scheduled. If they match one of the supported values, they're converted accordingly, but if they're not recognized as a supported value (as is the case of the value passed in the test), they default to a schedule of every week.

But I can update the code to accept a small enough refreshInterval to test if you'd like? I had assumed you wouldn't want me to alter the desired logic of the scheduler solely to conform to an existing test, which is why I originally opted to update the test units instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, I updated the tests to use fake timers which eliminates this issue. The original refereshInterval format has been restored.

@nicolaskruchten
Copy link
Contributor

Cool. Just glancing at the code, there's a WAITING_MESSAGE constant that contains text I've never seen in the UI... when does that show up?

@briandennis
Copy link
Contributor

It shows up after taking more than 5 seconds to save/update. If you're trying to test it, we've been adding wait functions to our queries to force longer runtime.

@briandennis briandennis changed the title WIP: Scheduler Stage 3 (Cron support) Scheduler Stage 3 Jul 21, 2018
"pg-hstore": "^2.3.2",
"restify": "^4.3.2",
"sequelize": "^3.30.4",
"sequelize": "3.30.4",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

"bunyan": "^1.8.12",
"chai": "^4.1.2",
"chromedriver": "^2.33.2",
"chromedriver": "2.33.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the situation with sequelize, Chromedriver pulled in a minor patch which was throwing on CI (for example here). Freezing the version at 2.33.2 resolved the error.

@n-riesco
Copy link
Contributor

@briandennis

  • about this failure on circleCI: I've recently noticed this failure. It's not a persistent failure. It goes away after a rebuild. I reckon this is an issue with out connector for redshift.

  • Thank you for fixing the overflow in SQLTable!

  • I've noticed a small issue while editing queries with a multi-selection of weekdays. See screen capture below:

peek 2018-07-23 15-25

@briandennis
Copy link
Contributor

@n-riesco re the circleCI failure: I tried rebuilding a few times and it continued to break on that specific Redshift test with that error. I then tried connecting to redshift manually and also hit the column "typarray" does not exist in pg_type error while connecting.

After some googling, it looks like this was a backwards compatibility issue with the Postgres version Redshift uses under the hood. The issue was introduced in a minor version of sequelize which is why it got pulled in when updating the yarn.lock in this PR.

Freezing the version at 3.30.4 fixed the problem, but let me know if you think there's a better solution!

@briandennis
Copy link
Contributor

@n-riesco the weekday input initialization has been fixed!

I think this PR is at a stage where it's ready to be merged into master. Keep in mind, we're doing at least one more PR after this that addresses any UX updates and bug fixes found while doing final polish and testing before the code freeze. I think we should handle any additional changes there.

What do you think? Are we good to merge this in?

</Row>
{ModeComponent ? <ModeComponent onChange={this.props.onChange} /> : null}
{ModeComponent ? (
// eslint-disable-next-line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the initialTime is null, we want to avoid overriding the default props for the mode by passing undefined. Setting anything to undefined however causes a lint error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll defer the decision onthis one to @nicolaskruchten .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with this, perhaps with a comment above the disable one to explain the reason, as it's not obvious.

}

export function mapCronToHourFormat(cronExpression) {
if (!cronExpression) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about validating the cron expressions using cronstrue (untested)?

try {
    cronstrue.toString(cronExpression);
} catch (_) {
    return null;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome idea! I added that in

@n-riesco
Copy link
Contributor

I'll have another go at testing the last changes tomorrow, but the code looks good to me other than the use of eslint-disable-next-line.

See also the suggestion that cronstrue is used to validate the input to mapCronToHourFormat.

@nicolaskruchten
Copy link
Contributor

OK, let's merge this in and have all new changes go into a cleanup commit.

Perhaps in the future when doing multi-stage work like this it would make sense to create a new branch to represent the whole feature and then do small PRs into that branch and then one final review on the branch before it hits master?

@nicolaskruchten
Copy link
Contributor

(Could we get the tests to pass first though?)

@n-riesco n-riesco merged commit 35b029e into master Jul 24, 2018
@mfix22 mfix22 deleted the features/scheduler-stage-3 branch August 8, 2018 01:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants