-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor job scheduler to use memdb for jobs (#782)
* internal/job: Introduce Job & related types * internal/state: Introduce new 'jobs' table * internal/scheduler: Introduce general-purpose job scheduler * internal/terraform/module(watcher+walker): Update references * internal/langserver/handlers: Update references * internal/terraform/module: Remove module manager & loader & queue * internal/terraform/module: Repurpose old mod mgr test cases In the old test we would be checking what *all* schemas are available for a given path after indexing via walker. This part of API is however being deprecated in favour of more straightforward one (see state.ProviderSchemaStore -> ProviderSchema()) which picks the single most appropriate schema from a list of candidates and retains the decision logic as an implementation detail within it, so the whole list of candidates is not really available from the outside (by design), hence not something we should test from the outside. ProviderSchemaStore itself already has plenty of tests testing the decision logic within, which is better place for testing this anyway. * jobs benchmarks
- Loading branch information
1 parent
726a5fb
commit 99e30e1
Showing
68 changed files
with
2,532 additions
and
1,538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package job | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-ls/internal/document" | ||
) | ||
|
||
type Job struct { | ||
// Func represents the job to execute | ||
Func func(ctx context.Context) error | ||
|
||
// Dir describes the directory which the job belongs to, | ||
// which is used for deduplication of queued jobs (along with Type) | ||
// and prioritization | ||
Dir document.DirHandle | ||
|
||
// Type describes type of the job (e.g. GetTerraformVersion), | ||
// which is used for deduplication of queued jobs along with Dir. | ||
Type string | ||
|
||
// Defer is a function to execute after Func is executed | ||
// and before the job is marked as done (StateDone). | ||
// This can be used to schedule jobs dependent on the main job. | ||
Defer DeferFunc | ||
} | ||
|
||
// DeferFunc represents a deferred function scheduling more jobs | ||
// based on jobErr (any error returned from the main job). | ||
// Newly queued job IDs should be returned to allow for synchronization. | ||
type DeferFunc func(ctx context.Context, jobErr error) IDs | ||
|
||
func (job Job) Copy() Job { | ||
return Job{ | ||
Func: job.Func, | ||
Dir: job.Dir, | ||
Type: job.Type, | ||
Defer: job.Defer, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package job | ||
|
||
type ID string | ||
|
||
func (id ID) String() string { | ||
return string(id) | ||
} | ||
|
||
type IDs []ID | ||
|
||
func (ids IDs) Copy() IDs { | ||
newIds := make([]ID, len(ids)) | ||
|
||
for i, id := range ids { | ||
newIds[i] = id | ||
} | ||
|
||
return newIds | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package job | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
type JobStore interface { | ||
EnqueueJob(newJob Job) (ID, error) | ||
WaitForJobs(ctx context.Context, ids ...ID) error | ||
} | ||
|
||
type jobStoreCtxKey struct{} | ||
|
||
func WithJobStore(ctx context.Context, js JobStore) context.Context { | ||
return context.WithValue(ctx, jobStoreCtxKey{}, js) | ||
} | ||
|
||
func JobStoreFromContext(ctx context.Context) (JobStore, error) { | ||
js, ok := ctx.Value(jobStoreCtxKey{}).(JobStore) | ||
if !ok { | ||
return nil, fmt.Errorf("not found JobStore in context") | ||
} | ||
return js, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package command | ||
|
||
import "github.com/hashicorp/terraform-ls/internal/state" | ||
|
||
type CmdHandler struct { | ||
StateStore *state.StateStore | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.