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

Function CreateProjectTask

cmd/cql-proxy/api/project.go:155–212  ·  view source on GitHub ↗

CreateProjectTask handles the project creation process.

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

Source from the content-addressed store, hash-verified

153
154// CreateProjectTask handles the project creation process.
155func CreateProjectTask(ctx context.Context, cfg *config.Config, db *gorp.DbMap, t *model.Task) (r gin.H, err error) {
156 args := struct {
157 NodeCount uint16 `json:"node_count"`
158 }{}
159
160 err = json.Unmarshal(t.RawArgs, &args)
161 if err != nil {
162 err = errors.Wrapf(err, "unmarshal task args failed")
163 return
164 }
165
166 tx, dbID, key, err := createDatabase(db, t.Developer, t.Account, args.NodeCount)
167 if err != nil {
168 err = errors.Wrapf(err, "create database failed")
169 return
170 }
171
172 // wait for transaction to complete in several cycles
173 timeoutCtx, cancelCtx := context.WithTimeout(ctx, 3*time.Minute)
174 defer cancelCtx()
175
176 lastState, err := waitForTxState(timeoutCtx, tx)
177 if err != nil {
178 err = errors.Wrapf(err, "wait for database creation confirmation failed")
179 r = gin.H{
180 "project": dbID,
181 "db": dbID,
182 "tx": tx.String(),
183 "state": lastState.String(),
184 }
185
186 return
187 }
188
189 // wait for projectDB to ready deployed
190 time.Sleep(30 * time.Second)
191
192 _, err = initProjectDB(dbID, key)
193 if err != nil {
194 err = errors.Wrapf(err, "init project database meta tables failed")
195 return
196 }
197
198 // bind database to current developer
199 _, err = model.AddProject(db, dbID, t.Developer, t.Account)
200 if err != nil {
201 err = errors.Wrapf(err, "register project failed")
202 }
203
204 r = gin.H{
205 "tx": tx.String(),
206 "state": lastState.String(),
207 "project": dbID,
208 "db": dbID,
209 }
210
211 return
212}

Callers

nothing calls this directly

Calls 6

AddProjectFunction · 0.92
createDatabaseFunction · 0.85
waitForTxStateFunction · 0.85
initProjectDBFunction · 0.85
UnmarshalMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected