MCPcopy Create free account
hub / github.com/ddev/ddev / ProcessHooks

Method ProcessHooks

pkg/ddevapp/ddevapp.go:1386–1424  ·  view source on GitHub ↗

ProcessHooks executes Tasks defined in Hooks

(hookName string)

Source from the content-addressed store, hash-verified

1384
1385// ProcessHooks executes Tasks defined in Hooks
1386func (app *DdevApp) ProcessHooks(hookName string) error {
1387 if SkipHooks {
1388 output.UserOut.Debugf("Skipping the execution of %s hook...", hookName)
1389 return nil
1390 }
1391 if cmds := app.Hooks[hookName]; len(cmds) > 0 {
1392 output.UserOut.Debugf("Executing %s hook...", hookName)
1393 }
1394
1395 for _, c := range app.Hooks[hookName] {
1396 a := NewTask(app, c)
1397 if a == nil {
1398 return fmt.Errorf("unable to create task from %v", c)
1399 }
1400
1401 if hookName == "pre-start" {
1402 for k := range c {
1403 if k == "exec" || k == "composer" {
1404 return fmt.Errorf("pre-start hooks cannot contain %v", k)
1405 }
1406 }
1407 }
1408
1409 output.UserOut.Debugf("=== Running task: %s, output below", a.GetDescription())
1410
1411 err := a.Execute()
1412
1413 if err != nil {
1414 if app.FailOnHookFail || app.FailOnHookFailGlobal {
1415 output.UserOut.Errorf("Task failed: %v: %v", a.GetDescription(), err)
1416 return fmt.Errorf("task failed: %v", err)
1417 }
1418 output.UserOut.Errorf("Task failed: %v: %v", a.GetDescription(), err)
1419 output.UserOut.Warn("A task failure does not mean that DDEV failed, but your hook configuration has a command that failed.")
1420 }
1421 }
1422
1423 return nil
1424}
1425
1426// GetDBImage uses the available version info
1427func (app *DdevApp) GetDBImage() string {

Callers 15

PullMethod · 0.95
PushMethod · 0.95
DeleteSnapshotMethod · 0.95
RestoreSnapshotMethod · 0.95
ComposerMethod · 0.95
DescribeMethod · 0.95
ImportDBMethod · 0.95
ImportFilesMethod · 0.95
StartMethod · 0.95
ExecMethod · 0.95
PauseMethod · 0.95
SnapshotMethod · 0.95

Calls 5

GetDescriptionMethod · 0.95
ExecuteMethod · 0.95
NewTaskFunction · 0.85
DebugfMethod · 0.80
ErrorfMethod · 0.80

Tested by 1

TestProcessHooksFunction · 0.64