CreateDatabaseTask handles the database creation process.
(ctx context.Context, _ *config.Config, db *gorp.DbMap, t *model.Task)
| 356 | |
| 357 | // CreateDatabaseTask handles the database creation process. |
| 358 | func CreateDatabaseTask(ctx context.Context, _ *config.Config, db *gorp.DbMap, t *model.Task) (r gin.H, err error) { |
| 359 | args := struct { |
| 360 | NodeCount uint16 `json:"node_count"` |
| 361 | }{} |
| 362 | |
| 363 | err = json.Unmarshal(t.RawArgs, &args) |
| 364 | if err != nil { |
| 365 | err = errors.Wrapf(err, "unmarshal task args failed") |
| 366 | return |
| 367 | } |
| 368 | |
| 369 | tx, dbID, _, err := createDatabase(db, t.Developer, t.Account, args.NodeCount) |
| 370 | if err != nil { |
| 371 | err = errors.Wrapf(err, "create database failed") |
| 372 | return |
| 373 | } |
| 374 | |
| 375 | // wait for transaction to complete in several cycles |
| 376 | timeoutCtx, cancelCtx := context.WithTimeout(ctx, 3*time.Minute) |
| 377 | defer cancelCtx() |
| 378 | |
| 379 | lastState, _ := waitForTxState(timeoutCtx, tx) |
| 380 | r = gin.H{ |
| 381 | "db": dbID, |
| 382 | "tx": tx.String(), |
| 383 | "state": lastState.String(), |
| 384 | } |
| 385 | |
| 386 | return |
| 387 | } |
| 388 | |
| 389 | // TopUpTask handles the database balance/advance payments top-up process. |
| 390 | func TopUpTask(ctx context.Context, cfg *config.Config, db *gorp.DbMap, t *model.Task) (r gin.H, err error) { |
nothing calls this directly
no test coverage detected