-
Notifications
You must be signed in to change notification settings - Fork 137
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 job scheduler to make it easier to test #719
Comments
Just a quick thought: I've used a couple of queuing/scheduling libraries with other programming languages. Most of them are well-architected and support all listed requirements. It might be worth checking out if there is something for Go, too, which we can leverage? |
I did actually use one library early on, but it didn't support priority queues. ef82870 but there isn't that many out there that I'm aware of. This is probably because Go actually offers decent primitives in the standard library (go routine + synchronization via While the requirements apply to the whole solution, lots of them are in fact satisfied by memdb, which means that the implementation of the scheduler can be relatively simple - all it needs to know is what the "next" job is and run that job in a go routine. Much of the existing complexity IMO comes from wanting to satisfy all the requirements within the scheduler and I'm hoping to get rid of that complexity by decoupling the code, as proposed. |
This functionality has been released in v0.26.0 of the language server. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Problem Statement
Currently we have at least one test which has to have
time.Sleep
due to the fact that we run certain operations inDefer
which is in a separate goroutine and we don't have any synchronization to allow the test to wait for the completion.Ideally tests should not have to implement
time.Sleep
to test regular scenarios with multiple modules.terraform-ls/internal/langserver/handlers/complete_test.go
Lines 720 to 724 in 371d8fd
Requirements Summary
The scheduler has a number of requirements:
didOpen
ordidChange
events are not affected by background indexing workload of a large workspaceworkspace/didChangeWorkspaceFolders
is receivedProposal
In order to be able to effectively sort tasks (based on dependencies or document state open/closed), dequeue tasks by path and block in handlers, it would be reasonable to store certain data in memdb. Two new tables are proposed for creation.
documents
Currently documents metadata is stored as a map and is tightly coupled with the
filesystem
package:terraform-ls/internal/filesystem/filesystem.go
Lines 20 to 21 in 88734ad
A new memdb table can be created within
state
package to hold the following structure:jobs
Currently job data is maintained as a queue (internally a slice) within the
terraform/module
package:https://github.com/hashicorp/terraform-ls/blob/main/internal/terraform/module/module_ops_queue.go
A new memdb table can be created within
state
package to hold the following structure:The same
"jobs"
table can hold jobs submitted "on the background" from the watcher/walker and fromdidOpen
/didChange
handlers, to enable deduplication. Two different "indexer" implementations can be exposed with different criteria of how to pull the next (if any) job from the table.Notes / Open Questions
txn.FirstWatch
method to block until next job is availableThe text was updated successfully, but these errors were encountered: