Move Task queuing to Taskhubs - #80
Conversation
Codecov ReportBase: 90.87% // Head: 91.10% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #80 +/- ##
==========================================
+ Coverage 90.87% 91.10% +0.22%
==========================================
Files 42 42
Lines 3300 3416 +116
==========================================
+ Hits 2999 3112 +113
- Misses 301 304 +3
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
|
@dotsdl did you push the changes from our pair session ? |
|
Apologies, I didn't. Just pushed now. |
|
I don't know why I don't see the commits here. |
|
I see them on the branch: https://github.com/hmacdope/alchemiscale/tree/taskhub |
|
Oh nevermind, it's further up because the commits were 18 hours ago. 🤦 |
|
I can go ahead and fix the merge conflicts here, unless you'd prefer to? |
|
Yep please go ahead. let me know if anything is unclear as we did a bit of renaming.
|
|
Okay, think I've got the merge conflicts sorted. Seeing test failures in the claiming method in statestore. Can you address? |
|
Yep for sure. |
|
@dotsdl My tests are hanging locally, I'll investigate |
| assert task_sks2 == all_task_sks[1:] | ||
| assert task_sks[0] in all_task_sks | ||
|
|
||
| # TODO: Currently we only allow tasks to be added to a taskhub with an EXTENDS |
There was a problem hiding this comment.
This had to be modified due to #84 blocking adding of :EXTENDS tasks using action_tasks. Will be fixed in a separate PR.
There was a problem hiding this comment.
I added the first task in the chain for each of the three transformations in the n4js_preloaded fixture, so now we have multiple tasks to work with for this test.
|
@dotsdl I think this is probably ready for another review 😃 |
Simplified where possible, adjustments to docs, grouping queries under transactions, etc.
| depth = lambda L: isinstance(L, list) and max(map(depth, L)) + 1 | ||
| if depth(tasks) > 1: | ||
| raise ValueError( | ||
| "tasks must be a flat list of ScopedKeys, list with depth > 1 not allowed" | ||
| ) |
There was a problem hiding this comment.
Not sure this is strictly necessary, since we say we need a List[ScopedKey] for tasks in the signature; I think this is fast though so should be okay?
There was a problem hiding this comment.
Also this is deep in the storage layer, so by this point we shouldn't have to make too many sanity checks here; just adds expense.
There was a problem hiding this comment.
Yeah I agree, too internal to need this kind of sanity checking.
| SET ar.weight = {w} | ||
| RETURN ar | ||
| """ | ||
| with self.transaction() as tx: |
There was a problem hiding this comment.
Moved transaction outside of loop to use a single transaction for all operations.
| with self.transaction() as tx: | ||
| tx.run(q) | ||
|
|
||
| # TODO: add exception for nothing returned for matches, or some Tasks missing |
There was a problem hiding this comment.
Added return of Tasks we set weights for; None for those we did not.
|
|
||
| def get_task_weights( | ||
| self, tasks: List[ScopedKey], taskhub: ScopedKey | ||
| ) -> Dict[ScopedKey, float]: |
There was a problem hiding this comment.
Switched this over to return List[Union[float, None]] to allow for case where a Task ScopedKey is given but doesn't resolve to an actual Task.
|
|
||
| def claim_taskqueue_tasks( | ||
| self, taskqueue: ScopedKey, claimant: str, count: int = 1 | ||
| def get_taskhub_unclaimed_tasks( |
There was a problem hiding this comment.
Do we have a use case for this method in mind? I'm fine with leaving it in, but not sure we use it anywhere yet?
There was a problem hiding this comment.
Ah, we do use it in tests; this is fine.
There was a problem hiding this comment.
I was anticipating it might be useful for tests as you saw, but also possibly if one wanted to query what tasks are still waiting on the TaskHub eg for checks on the total volume of work etc. Can always YAGNI it away if not needed.
| assert task_sks2 == all_task_sks[1:] | ||
| assert task_sks[0] in all_task_sks | ||
|
|
||
| # TODO: Currently we only allow tasks to be added to a taskhub with an EXTENDS |
There was a problem hiding this comment.
I added the first task in the chain for each of the three transformations in the n4js_preloaded fixture, so now we have multiple tasks to work with for this test.
| assert all([i is None for i in task_sks_fail]) | ||
|
|
||
| def test_cancel_task(self, n4js, network_tyk2, scope_test): | ||
| def test_action_task_nested_fails(self, n4js: Neo4jStore, network_tyk2, scope_test): |
There was a problem hiding this comment.
Not sure we really need this test; see comments on action_tasks check.
We'll probably rework this into a relationship instead pretty soon.
Fixes #78
Moves task queuing from a linked list with deterministic ordering to a hub-spoke model with stochastic pickup of tasks based on
weights.@dotsdl one key question is that currently the [:ACTIONS] relationships are built only when the tasks are queued (makes sense), meaning weights cannot be set or interrogated before then. This is not explicitly checked for at this stage but are we happy with this limitation?