-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe4e07c
commit 444ffa0
Showing
10 changed files
with
72 additions
and
52 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"context" | ||
_ "embed" | ||
"sync" | ||
"time" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/services" | ||
"github.com/smartcontractkit/chainlink-common/pkg/types/core" | ||
|
@@ -39,51 +40,70 @@ type WorkflowRegistry struct { | |
} | ||
|
||
func (w *WorkflowRegistry) Start(ctx context.Context) error { | ||
w.wg.Add(1) | ||
go func() { | ||
w.Logger.Info("starting hardcoded workflow...") | ||
|
||
// HACK: don't load the workflow if we aren't a workflow node. | ||
_, err := w.Registry.Get(ctx, "[email protected]") | ||
if err != nil { | ||
w.Logger.Info("not a workflow node, skipping hardcoded workflow") | ||
return | ||
} | ||
|
||
moduleConfig := &host.ModuleConfig{Logger: logger.NullLogger, IsUncompressed: true} | ||
spec, err := host.GetWorkflowSpec(ctx, moduleConfig, workflow, config) | ||
if err != nil { | ||
w.Logger.Errorf("failed to get workflow spec", err) | ||
return | ||
} | ||
|
||
cfg := workflows.Config{ | ||
Lggr: w.Logger, | ||
Workflow: *spec, | ||
WorkflowID: workflowID, | ||
WorkflowOwner: workflowOwner, | ||
WorkflowName: workflowName, | ||
Registry: w.Registry, | ||
Store: w.Store, | ||
Config: config, | ||
Binary: workflow, | ||
SecretsFetcher: w, | ||
} | ||
engine, err := workflows.NewEngine(ctx, cfg) | ||
if err != nil { | ||
w.Logger.Errorf("failed to create engine: %w", err) | ||
return | ||
} | ||
err = engine.Start(ctx) | ||
if err != nil { | ||
w.Logger.Errorf("failed to start hardcoded workflow: %w", err) | ||
return | ||
timeout := time.After(5 * time.Minute) | ||
ticker := time.NewTicker(10 * time.Second) | ||
|
||
for { | ||
select { | ||
case <-timeout: | ||
w.Logger.Info("timed out setting up hardcoded workflow") | ||
return | ||
case <-ticker.C: | ||
success := w.trySetup() | ||
if success { | ||
return | ||
} | ||
} | ||
} | ||
w.subServices = []job.ServiceCtx{engine} | ||
}() | ||
return nil | ||
} | ||
|
||
func (w *WorkflowRegistry) trySetup() bool { | ||
ctx := context.Background() | ||
w.Logger.Info("starting hardcoded workflow...") | ||
|
||
// HACK: don't load the workflow if we aren't a workflow node. | ||
_, err := w.Registry.Get(ctx, "[email protected]") | ||
if err != nil { | ||
w.Logger.Info("not a workflow node, skipping hardcoded workflow") | ||
return true | ||
} | ||
|
||
moduleConfig := &host.ModuleConfig{Logger: logger.NullLogger, IsUncompressed: true} | ||
spec, err := host.GetWorkflowSpec(ctx, moduleConfig, workflow, config) | ||
if err != nil { | ||
w.Logger.Errorf("failed to get workflow spec", err) | ||
return false | ||
} | ||
|
||
cfg := workflows.Config{ | ||
Lggr: w.Logger, | ||
Workflow: *spec, | ||
WorkflowID: workflowID, | ||
WorkflowOwner: workflowOwner, | ||
WorkflowName: workflowName, | ||
Registry: w.Registry, | ||
Store: w.Store, | ||
Config: config, | ||
Binary: workflow, | ||
SecretsFetcher: w, | ||
} | ||
engine, err := workflows.NewEngine(ctx, cfg) | ||
if err != nil { | ||
w.Logger.Errorf("failed to create engine: %w", err) | ||
return false | ||
} | ||
err = engine.Start(ctx) | ||
if err != nil { | ||
w.Logger.Errorf("failed to start hardcoded workflow: %w", err) | ||
return false | ||
} | ||
w.subServices = []job.ServiceCtx{engine} | ||
return true | ||
} | ||
|
||
func (w *WorkflowRegistry) Close() error { | ||
for _, s := range w.subServices { | ||
err := s.Close() | ||
|
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
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