MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / CreateDatabaseTask

Function CreateDatabaseTask

cmd/cql-proxy/api/database.go:358–387  ·  view source on GitHub ↗

CreateDatabaseTask handles the database creation process.

(ctx context.Context, _ *config.Config, db *gorp.DbMap, t *model.Task)

Source from the content-addressed store, hash-verified

356
357// CreateDatabaseTask handles the database creation process.
358func 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.
390func TopUpTask(ctx context.Context, cfg *config.Config, db *gorp.DbMap, t *model.Task) (r gin.H, err error) {

Callers

nothing calls this directly

Calls 4

createDatabaseFunction · 0.85
waitForTxStateFunction · 0.85
UnmarshalMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected