Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor async.queue behaviour affected by upgrade #93

Merged
merged 8 commits into from
Sep 13, 2019

Conversation

josebolos
Copy link
Member

Fixes an issue with the cron job not launching any pa11y tasks when triggered.


try {
const tasks = await app.model.task.getAll();
runPa11yOnTasks(tasks, app);
Copy link
Member

Choose a reason for hiding this comment

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

I think that as runPa11yOnTasks is using async.queue which in turn is using setImmediate internally, the try/catch won't capture the error.

async/queue has a .error handler though. runPa11yOnTasks would need to be changed to return a Promise which the .error handler would reject. Then await runPa11yOnTasks in this try/catch.

http://caolan.github.io/async/v3/docs.html#queue

Copy link
Member

Choose a reason for hiding this comment

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

Given that this broke and we had no idea, we should really add some unit tests for this. It shouldn't be too bad as the app is passed in so the model can have task.getAll and task.runById mocked out.

We'd need a cron string to make it run every 1 sec or something. Probably wouldn't be the prettiest looking test....

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right in that this needs tests as none of this code is being tested at the moment, which is why we didn't realise it's broken.

That said, we're trying to get a fix released ASAP as dashboard is broken because of this so we probably want to add the tests later. Jon has been looking at them already.

I'm not familiar with promises, but I will have a look now and see if I can make it work that way.

Copy link

Choose a reason for hiding this comment

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

Joey you are correct, but 😁

  • runPa11yOnTasks is exported by this module so we were not keen on changing what it returns, as we don't know what other code uses it as yet (without more refactoring).
  • the try/catch should never catch as long as runPa11yOnTasks doesn't change. This is "illogical" or belt & braces, depending on ones opinion. It also reproduces the original behaviour of the code IIRC which we didn't want to change as this isn't adequately tested yet.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, fair enough. I've created #94 to add osme unit tests around this so we have a bit of stability.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks everyone! Can we merge then?

@josebolos josebolos merged commit b278bad into master Sep 13, 2019
@josebolos josebolos deleted the get-tasks-refactor branch September 13, 2019 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants