-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pipeline: add local weighted semaphores
- Loading branch information
Showing
12 changed files
with
142 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ processingDir = "" | |
processingConfig = "automated" | ||
# transferLocationID = "88f6b517-c0cc-411b-8abf-79544ce96f54" | ||
storageServiceURL = "http://test:[email protected]:62081" | ||
capacity = 5 | ||
|
||
[[hooks."hari"]] | ||
baseURL = "" # E.g.: "https://192.168.1.50:8080/api" | ||
|
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
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 pipeline | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestPipelineSemaphore(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx := context.Background() | ||
|
||
p, err := NewPipeline(Config{Capacity: 3}) | ||
assert.ErrorContains(t, err, "error during pipeline identification") | ||
|
||
tryAcquire := func(n int64) bool { | ||
ctx, cancel := context.WithTimeout(ctx, 10*time.Millisecond) | ||
defer cancel() | ||
return p.Acquire(ctx) == nil | ||
} | ||
|
||
tries := []bool{} | ||
|
||
// These three should succeed right away. | ||
tries = append(tries, tryAcquire(1)) | ||
tries = append(tries, tryAcquire(1)) | ||
tries = append(tries, tryAcquire(1)) | ||
|
||
// And the one too because we've released once. | ||
p.Release() | ||
tries = append(tries, tryAcquire(1)) | ||
|
||
// But this will fail because all the slots are taken. | ||
tries = append(tries, tryAcquire(1)) | ||
|
||
assert.DeepEqual(t, tries, []bool{true, true, true, true, false}) | ||
} |
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,26 @@ | ||
package activities | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/artefactual-labs/enduro/internal/workflow/manager" | ||
) | ||
|
||
// AcquirePipelineActivity acquires a lock in the weighted semaphore associated | ||
// to a particular pipeline. | ||
type AcquirePipelineActivity struct { | ||
manager *manager.Manager | ||
} | ||
|
||
func NewAcquirePipelineActivity(m *manager.Manager) *AcquirePipelineActivity { | ||
return &AcquirePipelineActivity{manager: m} | ||
} | ||
|
||
func (a *AcquirePipelineActivity) Execute(ctx context.Context, name string) error { | ||
p, err := a.manager.Pipelines.ByName(name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return p.Acquire(ctx) | ||
} |
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package activities | ||
|
||
const ( | ||
DownloadActivityName = "download-activity" | ||
BundleActivityName = "bundle-activity" | ||
TransferActivityName = "transfer-activity" | ||
PollTransferActivityName = "poll-transfer-activity" | ||
PollIngestActivityName = "poll-ingest-activity" | ||
CleanUpActivityName = "clean-up-activity" | ||
HidePackageActivityName = "hide-package-activity" | ||
DeleteOriginalActivityName = "delete-original-activity" | ||
AcquirePipelineActivityName = "acquire-pipeline-activity" | ||
DownloadActivityName = "download-activity" | ||
BundleActivityName = "bundle-activity" | ||
TransferActivityName = "transfer-activity" | ||
PollTransferActivityName = "poll-transfer-activity" | ||
PollIngestActivityName = "poll-ingest-activity" | ||
CleanUpActivityName = "clean-up-activity" | ||
HidePackageActivityName = "hide-package-activity" | ||
DeleteOriginalActivityName = "delete-original-activity" | ||
) |
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