We currently have two separate systems for dealing with pending tasks (which either failed before or take too much time on larger sites to do in a single request) – server tasks and index tasks. Both have much the same functionality, and the former is even somewhat extensible, but they still lack flexibility and duplicate a lot of code.
We should instead have a single task system for dealing with any Search API-related tasks and rewrite those two previous systems to build on the new one as far as possible.
One application for this should then be to also add task integration for config changes in a content entity datasource (where we currently might add thousands or even millions of new items to the tracking system in a single request – or, rather, fail horribly while trying to do that).
Estimated Value and Story Points
This issue was identified as a Beta Blocker for Drupal 8. We sat down and figured out the value proposition and amount of work (story points) for this issue.
Value and Story points are in the scale of fibonacci. Our minimum is 1, our maximum is 21. The higher, the more value or work a certain issue has.
Value : 3
Story Points: 8
| Comment | File | Size | Author |
|---|---|---|---|
| #49 | 2574611-49--fix_postgres.patch | 574 bytes | drunken monkey |
| #36 | 2574611-36--task_system_overhaul.patch | 133.2 KB | drunken monkey |
Comments
Comment #2
nick_vhComment #3
drunken monkeyTackling this now, but currently in the process of succumbing to another onset of megalomania. (I.e., I'm revamping the two task systems into a single, more flexible one.)
Comment #4
drunken monkeySomething like the attached. It uses events to execute the different types of tasks, thus staying fully flexible.
Still to do:
Still setting to "Needs review" to a) see whether the test bot is happy so far (the new functionality still needs tests, though) and b) to maybe get some feedback on what I've got so far. Will probably not work on it again until Monday or Tuesday.
Comment #5
borisson_I'd love to provide feedback on this, but I think you forgot to attach a patch.
Comment #6
drunken monkeySo I did.
Damn.
Updated patch coming soon anyways, but I'm still interested in the test results here.
Comment #7
drunken monkeyAh, now I get it! Forgot the ".patch" extension for the patch file so it got rejected. (Blame my thousands of small scripts which usually take care of this for me.)
Comment #10
borisson_At first glance, this looks great, I'd think that maybe we'd want to create a value object for
executeSingleTask's argument instead of just using an array? Not sure though.I'll look in more detail at this when there's less failures.
Comment #11
drunken monkeyI don't think so. First of all, we'd need to do this for all
$conditionsarguments for the class's methods. And second, I don't think this is done anywhere in Drupal Core. Conditions on properties are still expressed with associative arrays, as far as I can see (e.g.,\Drupal\Core\Entity\EntityStorageInterface::loadByProperties()).The failures mostly seem to be a single syntax error in
services.yml– which PhpStorm doesn't spot, for some reason. But you might as well wait for a thorough review until I have a patch I'd call RTBC. As long as you agree that the basic direction makes sense, nothing major will hopefully pop up then.Comment #14
drunken monkeyAnd several more small mistakes, ranging from tricky to dilettantish.
Comment #17
drunken monkeyThis adds the original objective of integration with datasource item tracking and also passes all PhpUnit tests, at least locally.
To do: local action, status report and tests.
Comment #20
drunken monkeyComment #23
drunken monkeyDiscovered #2727667: Subsequent submit callbacks are handled incorrectly after batch is added and #2727697: Changes to the index are discarded when it is serialized, but in the end they both don't really apply here, since it's a bad idea to create the batch as soon as
$datasource->setConfiguration()is called anyways – we should change the tracking only once the index has actually been saved, not just when a property is changed (which might not be saved after all).This was, by the way, wrong before, too. However, I have to say this solution is a lot less elegant, with relying on a hook implementation completely separated from the rest of the datasource code. But to solve that, we'd have to either add some "index save" reaction method for datasources (or all index plugins), which might be a bit overkill (or pretty nice to have in general, too – would have to be determined) or re-think the whole "write property changes only on index save" mechanism (and we're not doing that unless we really have to – was enough effort getting it to work in the first place).
Anyways, worked the whole day on this, and still not finished. But the attached patch at least changes the local task and status report functionality to encompass all kinds of tasks, and should also fix a few more bugs. Hopefully I'll be able to finish this tomorrow, by fixing the remaining test fails and adding a few tests for the new functionality.
Comment #26
drunken monkeyHad to fix #2574881: Fix tracking race conditions by making tracker ignore duplicate inserts at the same time, too.
But at least that's also a beta blocker, so we get two for one here.
Comment #29
borisson_Awesome that we're going to fix the other issue in here as well, that's great. Reviewed the interdiff in #26 and had one small remark.
Wait, huh? This looks weird. Can we do $this->batchTracking++ instead? I had no idea this even worked.
I recently got a comment that we shouldn't introduce new objects while throwing exceptions. see #2722271: Make sure as little code as possible is triggered when throwing an exception.
Again, same thing as .1
So much better.
Again, much more expressive, love this!
Comment #30
drunken monkeyI dislike the postfix increment operators, and precedence-wise there shouldn't be any problem since
->has always had highest operator precedence, as far as I know (even though it's unfortunately not listed in the PHP docs). I didn't even really think about it, to be honest.However, if it looks weird to you, it probably also does for others, so I changed it. Better I find it ugly than anyone finding it confusing. ;)
Oh, you're right, apparently this has even been in our coding standards for several months now! Created #2728399: Do not use FormattableMarkup in exceptions to take care of this project-wide.
But fixed it in this patch, too. Thanks!
Thanks, glad to hear it. I thought so, too, and it fixes nested calls elegantly (though they're probably an edge case anyways).
The attached patch implements those changes and should also, finally, fix all tests. (Additional tests are still needed, though.)
Comment #31
drunken monkeyDamn Postgres tests …
Here's to hoping #2709899: php7 + postgres throws AlreadyInstalledException randomly. will get fixed soon!
Comment #32
drunken monkeyTests added, both for the general task manager functionality and the content entity datasource-specific code.
From my point of view, this is RTBC – eager to hear other comments, though, of course.
Comment #33
borisson_Only briefly looked at the interdiff, will look at the big patch again later today. Everything looks solid.
I don't understand why this change is needed?
{@inheritdoc} should work as well
{@inheritdoc}
Is there a reason why these aren't in order?
Comment #34
drunken monkeySo PhpStorm doesn't complain, since
condition()is documented to return\Drupal\Core\Database\Query\ConditionInterface, and not$this– therefore, PhpStorm doesn't think it has anexecute()method.Yes, because we want to make sure the correct ones are skipped when we apply conditions. If we just create them in the order they should be executed, we wouldn't really test the
$conditionsparameter at all.But it probably deserves some explanation in a comment.
Comment #35
andypostuseless change
the same, should be FQDN
Comment #36
drunken monkeyFirst off, no, it changes
server_idto allowNULL.Secondly, the order makes more sense this way, now that we always have a type, but the server might be missing. It's no functional difference, sure, but why should that stop us?
Ah, yes, thanks for spotting that!
Comment #37
borisson_Comment #39
drunken monkeyGreat to hear, thanks for reviewing!
Committed.
Comment #40
drunken monkeyPostgres is failing (apparently for real, this time) after this commit. The attached patch completely reverts the commit – let's see whether that would fix it.
Comment #41
drunken monkeyNow a dummy patch to see the apparent test failures.
Comment #42
drunken monkeyMaybe this is the culprit?
Comment #43
andypostProbably that's a pg related issue, suppose better to file follow-up
Also core itself as random failures on pg https://www.drupal.org/node/3060/qa
Comment #44
drunken monkeyOf course it's a Postgres-related issue – that's why all tests pass in the other two environments. And yes, we're aware of the random fails: #2709899: php7 + postgres throws AlreadyInstalledException randomly.. But this is something different, the tests are really failing, and I'd like to fix that as soon as possible to avoid adding even more Postgres fails on top of those.
I have now managed to finally install Postgres locally and am in the process of debugging this issue.
Comment #45
drunken monkeyFrom what I can tell, there is just a glaring bug in Core's Entity Query implementation for Postgres. Switching to a normal DB query solved it for me locally (at least one test). Let's see what the test bot says.
Comment #48
drunken monkeyOh, er, like this, I mean.
But anyways, not a proper solution anyways.
Comment #49
drunken monkeyThis might actually be an option until the Core bug gets fixed.
(Gotta reproduce it with a Core entity type and then file it, first, though.)
Comment #50
drunken monkeyCouldn't reproduce it properly, unfortunately, but created the issue: #2734445: Postgres entity queries doesn't treat multiple IN conditions correctly.
And if no-one objects I'd like to just commit this workaround for now and then go on to more productive issues.
Comment #51
borisson_Sounds good.
Comment #53
drunken monkeyOK, good. Then: committed.
Thanks for your feedback!