environment/exec: Seperate Exec and Wait
This commit is contained in:
parent
2a308ee03c
commit
a590d93e76
14 changed files with 90 additions and 117 deletions
|
|
@ -18,10 +18,7 @@ func (*SQL) BackupName() string {
|
|||
// Backup makes a backup of all SQL databases into the path dest.
|
||||
func (sql *SQL) Backup(scontext component.StagingContext) error {
|
||||
return scontext.AddFile("", func(ctx context.Context, file io.Writer) error {
|
||||
code, err := sql.Stack(sql.Environment).Exec(ctx, stream.NonInteractive(scontext.Progress()), "sql", "mysqldump", "--all-databases")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
code := sql.Stack(sql.Environment).Exec(ctx, stream.NonInteractive(scontext.Progress()), "sql", "mysqldump", "--all-databases")()
|
||||
if code != 0 {
|
||||
return errSQLBackup
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,7 @@ func (sql *SQL) Snapshot(wisski models.Instance, scontext component.StagingConte
|
|||
|
||||
// SnapshotDB makes a backup of the sql database into dest.
|
||||
func (sql *SQL) SnapshotDB(ctx context.Context, progress io.Writer, dest io.Writer, database string) error {
|
||||
code, err := sql.Stack(sql.Environment).Exec(ctx, stream.NonInteractive(progress), "sql", "mysqldump", "--databases", database)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
code := sql.Stack(sql.Environment).Exec(ctx, stream.NonInteractive(progress), "sql", "mysqldump", "--databases", database)()
|
||||
if code != 0 {
|
||||
return errSQLBackup
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,23 +18,23 @@ import (
|
|||
// Shell runs a mysql shell with the provided databases.
|
||||
//
|
||||
// NOTE(twiesing): This command should not be used to connect to the database or execute queries except in known situations.
|
||||
func (sql *SQL) Shell(ctx context.Context, io stream.IOStream, argv ...string) (int, error) {
|
||||
return sql.Stack(sql.Environment).Exec(ctx, io, "sql", "mysql", argv...)
|
||||
func (sql *SQL) Shell(ctx context.Context, io stream.IOStream, argv ...string) int {
|
||||
return sql.Stack(sql.Environment).Exec(ctx, io, "sql", "mysql", argv...)()
|
||||
}
|
||||
|
||||
// unsafeWaitShell waits for a connection via the database shell to succeed
|
||||
func (sql *SQL) unsafeWaitShell(ctx context.Context) error {
|
||||
n := stream.FromNil()
|
||||
return timex.TickUntilFunc(func(time.Time) bool {
|
||||
code, err := sql.Shell(ctx, n, "-e", "select 1;")
|
||||
return err == nil && code == 0
|
||||
code := sql.Shell(ctx, n, "-e", "select 1;")
|
||||
return code == 0
|
||||
}, ctx, sql.PollInterval)
|
||||
}
|
||||
|
||||
// unsafeQuery shell executes a raw database query.
|
||||
func (sql *SQL) unsafeQueryShell(ctx context.Context, query string) bool {
|
||||
code, err := sql.Shell(ctx, stream.FromNil(), "-e", query)
|
||||
return err == nil && code == 0
|
||||
code := sql.Shell(ctx, stream.FromNil(), "-e", query)
|
||||
return code == 0
|
||||
}
|
||||
|
||||
var errSQLUnableToCreateUser = errors.New("unable to create administrative user")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue