99// taskRule visits one kind of path value of a job task.
1010type taskRule struct {
1111 mode TranslateMode
12- skip func (string ) bool
1312 visit func (task * jobs.Task , c * taskCursor ) error
1413}
1514
@@ -25,54 +24,55 @@ type taskCursor struct {
2524
2625// yield visits the value s, the field key of owner, at the parts below the task.
2726func (c * taskCursor ) yield (owner any , key string , s * string , parts ... any ) error {
27+ // Most candidates (e.g. the whl, jar and requirements of every library) are empty.
28+ if ! present (owner , key , s ) {
29+ return nil
30+ }
31+ p := structpath .NewPath (resourcePath ("jobs" , c .name ), "tasks" , c .index )
32+ if c .nested {
33+ p = structpath .NewPath (p , "for_each_task" , "task" )
34+ }
2835 return visit (c .fn , visitArgs {
2936 owner : owner ,
3037 field : key ,
3138 value : s ,
3239 mode : c .rule .mode ,
33- skip : c .rule .skip ,
34- path : func () * structpath.PathNode {
35- p := structpath .NewPath (resourcePath ("jobs" , c .name ), "tasks" , c .index )
36- if c .nested {
37- p = structpath .NewPath (p , "for_each_task" , "task" )
38- }
39- return structpath .NewPath (p , parts ... )
40- },
40+ path : structpath .NewPath (p , parts ... ),
4141 })
4242}
4343
4444var jobTaskRules = []taskRule {
45- {TranslateModeNotebook , nil , func (t * jobs.Task , c * taskCursor ) error {
45+ {TranslateModeNotebook , func (t * jobs.Task , c * taskCursor ) error {
4646 if t .NotebookTask == nil {
4747 return nil
4848 }
4949 return c .yield (t .NotebookTask , "notebook_path" , & t .NotebookTask .NotebookPath , "notebook_task" , "notebook_path" )
5050 }},
51- {TranslateModeFile , nil , func (t * jobs.Task , c * taskCursor ) error {
51+ {TranslateModeFile , func (t * jobs.Task , c * taskCursor ) error {
5252 if t .SparkPythonTask == nil {
5353 return nil
5454 }
5555 return c .yield (t .SparkPythonTask , "python_file" , & t .SparkPythonTask .PythonFile , "spark_python_task" , "python_file" )
5656 }},
57- {TranslateModeDirectory , nil , func (t * jobs.Task , c * taskCursor ) error {
57+ {TranslateModeDirectory , func (t * jobs.Task , c * taskCursor ) error {
5858 if t .DbtTask == nil {
5959 return nil
6060 }
6161 return c .yield (t .DbtTask , "project_directory" , & t .DbtTask .ProjectDirectory , "dbt_task" , "project_directory" )
6262 }},
63- {TranslateModeFile , nil , func (t * jobs.Task , c * taskCursor ) error {
63+ {TranslateModeFile , func (t * jobs.Task , c * taskCursor ) error {
6464 if t .SqlTask == nil || t .SqlTask .File == nil {
6565 return nil
6666 }
6767 return c .yield (t .SqlTask .File , "path" , & t .SqlTask .File .Path , "sql_task" , "file" , "path" )
6868 }},
69- {TranslateModeFile , nil , func (t * jobs.Task , c * taskCursor ) error {
69+ {TranslateModeFile , func (t * jobs.Task , c * taskCursor ) error {
7070 if t .AlertTask == nil {
7171 return nil
7272 }
7373 return c .yield (t .AlertTask , "workspace_path" , & t .AlertTask .WorkspacePath , "alert_task" , "workspace_path" )
7474 }},
75- {TranslateModeFile , nil , func (t * jobs.Task , c * taskCursor ) error {
75+ {TranslateModeFile , func (t * jobs.Task , c * taskCursor ) error {
7676 for i := range t .Libraries {
7777 if err := c .yield (& t .Libraries [i ], "requirements" , & t .Libraries [i ].Requirements , "libraries" , i , "requirements" ); err != nil {
7878 return err
@@ -83,7 +83,7 @@ var jobTaskRules = []taskRule{
8383 // The AI Runtime task runs this bash script on each node; the backend reads it as
8484 // a workspace file, so translate the local path to its remote (or
8585 // immutable-snapshot) location like any other file.
86- {TranslateModeFile , nil , func (t * jobs.Task , c * taskCursor ) error {
86+ {TranslateModeFile , func (t * jobs.Task , c * taskCursor ) error {
8787 if t .AiRuntimeTask == nil {
8888 return nil
8989 }
@@ -154,9 +154,7 @@ func VisitJobPaths(root *config.Root, fn VisitFunc) error {
154154 if err := visit (fn , visitArgs {
155155 value : & ev .Spec .Files [j ],
156156 mode : TranslateModeFile ,
157- path : func () * structpath.PathNode {
158- return structpath .NewPath (resourcePath ("jobs" , name ), "environment_variables" , i , "spec" , "files" , j )
159- },
157+ path : structpath .NewPath (resourcePath ("jobs" , name ), "environment_variables" , i , "spec" , "files" , j ),
160158 }); err != nil {
161159 return err
162160 }
@@ -177,9 +175,7 @@ func VisitJobPaths(root *config.Root, fn VisitFunc) error {
177175 field : "project_environment" ,
178176 value : & env .Spec .ProjectEnvironment ,
179177 mode : TranslateModeFile ,
180- path : func () * structpath.PathNode {
181- return structpath .NewPath (resourcePath ("jobs" , name ), "environments" , i , "spec" , "project_environment" )
182- },
178+ path : structpath .NewPath (resourcePath ("jobs" , name ), "environments" , i , "spec" , "project_environment" ),
183179 }); err != nil {
184180 return err
185181 }
0 commit comments