Update cron type with ref pattern
This commit is contained in:
+15
-1
@@ -112,6 +112,16 @@ func createSchema(db database.Database, pollChan chan uuid.UUID) (graphql.Schema
|
||||
return nil, nil
|
||||
},
|
||||
},
|
||||
"pattern": &graphql.Field{
|
||||
Type: graphql.NewNonNull(graphql.String),
|
||||
Description: "A pattern for determining what refs to run the cron on.",
|
||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||
if cron, ok := p.Source.(database.Cron); ok {
|
||||
return cron.Pattern, nil
|
||||
}
|
||||
return nil, nil
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -779,6 +789,9 @@ func createSchema(db database.Database, pollChan chan uuid.UUID) (graphql.Schema
|
||||
"cron": &graphql.ArgumentConfig{
|
||||
Type: graphql.NewNonNull(graphql.String),
|
||||
},
|
||||
"pattern": &graphql.ArgumentConfig{
|
||||
Type: graphql.NewNonNull(graphql.String),
|
||||
},
|
||||
"pipelineId": &graphql.ArgumentConfig{
|
||||
Type: graphql.NewNonNull(graphql.String),
|
||||
},
|
||||
@@ -786,13 +799,14 @@ func createSchema(db database.Database, pollChan chan uuid.UUID) (graphql.Schema
|
||||
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
|
||||
|
||||
cron := params.Args["cron"].(string)
|
||||
pattern := params.Args["pattern"].(string)
|
||||
|
||||
pipelineId, err := uuid.Parse(params.Args["pipelineId"].(string))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = db.AddCronForPipeline(pipelineId, cron)
|
||||
err = db.AddCronForPipeline(pipelineId, cron, pattern)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -194,6 +194,7 @@ CREATE TABLE crons (
|
||||
id UUID PRIMARY KEY,
|
||||
pipeline_id UUID NOT NULL,
|
||||
cron TEXT NOT NULL,
|
||||
pattern TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT fk_pipeline_id
|
||||
FOREIGN KEY(pipeline_id)
|
||||
|
||||
+6
-6
@@ -673,7 +673,7 @@ RETURNING id, name, token;`
|
||||
|
||||
func (db *Database) GetCronsForPipeline(pipelineId uuid.UUID) ([]Cron, error) {
|
||||
query := `
|
||||
SELECT id, cron
|
||||
SELECT id, cron, pattern
|
||||
FROM crons
|
||||
WHERE pipeline_id=$1;`
|
||||
|
||||
@@ -689,7 +689,7 @@ WHERE pipeline_id=$1;`
|
||||
var cron Cron
|
||||
var idStr string
|
||||
if err := cronEntrys.Scan(
|
||||
&idStr, &cron.Cron,
|
||||
&idStr, &cron.Cron, &cron.Pattern,
|
||||
); err != nil {
|
||||
return crons, err
|
||||
}
|
||||
@@ -705,12 +705,12 @@ WHERE pipeline_id=$1;`
|
||||
return crons, nil
|
||||
}
|
||||
|
||||
func (db *Database) AddCronForPipeline(pipelineId uuid.UUID, cron string) error {
|
||||
func (db *Database) AddCronForPipeline(pipelineId uuid.UUID, cron string, pattern string) error {
|
||||
query := `
|
||||
INSERT INTO crons (id, pipeline_id, cron)
|
||||
VALUES (uuid_generate_v4(), $1, $2);`
|
||||
INSERT INTO crons (id, pipeline_id, cron, pattern)
|
||||
VALUES (uuid_generate_v4(), $1, $2, $3);`
|
||||
|
||||
_, err := db.Conn.Exec(context.Background(), query, pipelineId, cron)
|
||||
_, err := db.Conn.Exec(context.Background(), query, pipelineId, cron, pattern)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -83,4 +83,5 @@ type Runner struct {
|
||||
type Cron struct {
|
||||
Id uuid.UUID
|
||||
Cron string
|
||||
Pattern string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user