@@ -58,42 +58,12 @@ func (pge *PgEngine) LoadYamlChains(ctx context.Context, filePath string, replac
5858 return fmt .Errorf ("chain '%s' already exists (use --replace flag to overwrite)" , yamlChain .ChainName )
5959 }
6060
61- // Use existing add_job function for single-task chains
62- if len (yamlChain .Tasks ) == 1 {
63- task := yamlChain .Tasks [0 ]
64- params , _ := task .ToSQLParameters ()
65- var paramsValue interface {}
66- if params == "" {
67- paramsValue = nil
68- } else {
69- paramsValue = params
70- }
71-
72- _ , err := pge .ConfigDb .Exec (ctx , `
73- SELECT timetable.add_job($1, $2, $3, $4::jsonb, $5::timetable.command_kind, $6, $7, $8, $9, $10, $11, $12)` ,
74- yamlChain .ChainName ,
75- yamlChain .Schedule ,
76- task .Command ,
77- paramsValue ,
78- task .Kind ,
79- nullString (yamlChain .ClientName ),
80- yamlChain .MaxInstances ,
81- yamlChain .Live ,
82- yamlChain .SelfDestruct ,
83- task .IgnoreError ,
84- yamlChain .ExclusiveExecution ,
85- nullString (yamlChain .OnError ))
86- if err != nil {
87- return fmt .Errorf ("failed to create chain %s: %w" , yamlChain .ChainName , err )
88- }
89- } else {
90- // Multi-task chain - use direct SQL
91- chainID , err := pge .createChainFromYaml (ctx , & yamlChain )
92- if err != nil {
93- return fmt .Errorf ("failed to create multi-task chain %s: %w" , yamlChain .ChainName , err )
94- }
95- pge .l .WithField ("chain" , yamlChain .ChainName ).WithField ("chain_id" , chainID ).Info ("Created multi-task chain" )
61+ // Multi-task chain - use direct SQL
62+ chainID , err := pge .createChainFromYaml (ctx , & yamlChain )
63+ if err != nil {
64+ return fmt .Errorf ("failed to create multi-task chain %s: %w" , yamlChain .ChainName , err )
9665 }
66+ pge .l .WithField ("chain" , yamlChain .ChainName ).WithField ("chain_id" , chainID ).Info ("Created multi-task chain" )
9767 }
9868
9969 pge .l .WithField ("chains" , len (yamlConfig .Chains )).WithField ("file" , filePath ).Info ("Successfully imported YAML chains" )
@@ -167,7 +137,7 @@ func (pge *PgEngine) createChainFromYaml(ctx context.Context, yamlChain *YamlCha
167137}
168138
169139// nullString returns nil for empty strings, otherwise returns the string
170- func nullString (s string ) interface {} {
140+ func nullString (s string ) any {
171141 if s == "" {
172142 return nil
173143 }
@@ -185,10 +155,16 @@ func (c *YamlChain) ValidateChain() error {
185155 }
186156
187157 // Validate cron format
188- switch c .Schedule {
189- case "" , "@reboot" , "@after" , "@every" :
190- // Valid special schedules
191- default :
158+ specialSchedules := []string {"@reboot" , "@after" , "@every" }
159+ isSpecial := false
160+ for _ , s := range specialSchedules {
161+ if strings .HasPrefix (c .Schedule , s ) {
162+ isSpecial = true
163+ break
164+ }
165+ }
166+
167+ if ! isSpecial {
192168 fields := strings .Fields (c .Schedule )
193169 if len (fields ) != 5 {
194170 return fmt .Errorf ("invalid cron format: %s (expected 5 fields)" , c .Schedule )
0 commit comments