use-task.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import { useFlink } from './tasks/use-flink'
  18. import { useShell } from './tasks/use-shell'
  19. import { useSubProcess } from './tasks/use-sub-process'
  20. import { usePython } from './tasks/use-python'
  21. import { useSpark } from './tasks/use-spark'
  22. import { useMr } from './tasks/use-mr'
  23. import { IJsonItem, INodeData, ITaskData } from './types'
  24. export function useTask({
  25. data,
  26. projectCode,
  27. from,
  28. readonly
  29. }: {
  30. data: ITaskData
  31. projectCode: number
  32. from?: number
  33. readonly?: boolean
  34. }): { json: IJsonItem[]; model: INodeData } {
  35. const { taskType = 'SHELL' } = data
  36. let node = {} as { json: IJsonItem[]; model: INodeData }
  37. if (taskType === 'SHELL') {
  38. node = useShell({
  39. projectCode,
  40. from,
  41. readonly,
  42. data
  43. })
  44. }
  45. if (taskType === 'SUB_PROCESS') {
  46. node = useSubProcess({
  47. projectCode,
  48. from,
  49. readonly,
  50. data
  51. })
  52. }
  53. if (taskType === 'PYTHON') {
  54. node = usePython({
  55. projectCode,
  56. from,
  57. readonly,
  58. data
  59. })
  60. }
  61. if (taskType === 'SPARK') {
  62. node = useSpark({
  63. projectCode,
  64. from,
  65. readonly,
  66. data
  67. })
  68. }
  69. if (taskType === 'MR') {
  70. node = useMr({
  71. projectCode,
  72. from,
  73. readonly,
  74. data
  75. })
  76. }
  77. if (taskType === 'FLINK') {
  78. node = useFlink({
  79. projectCode,
  80. from,
  81. readonly,
  82. data
  83. })
  84. }
  85. return node
  86. }