apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: qserv-ingest-
spec:
  entrypoint: main
  volumes:
  - name: repl-creds
    secret:
      secretName: secret-repl-creds-qserv
  - name: config
    configMap:
      name: config-ingest
  arguments:
    parameters:
    - name: image
      # superTransactions is the number of pods running concurrent super-transactions
    - name: superTransactions
      value: 10
    - name: backoffLimit
      value: 5
  templates:
  - name: ingest-step
    inputs:
      parameters:
      - name: script
    container:
      command:
        - "{{inputs.parameters.script}}"
      image: "{{workflow.parameters.image}}"
      imagePullPolicy: IfNotPresent
      volumeMounts:
        - name: repl-creds
          mountPath: /home/qserv/.lsst
        - name: config
          mountPath: /config
  - name: transactions
    resource:
      action: create
      successCondition: status.succeeded = {{workflow.parameters.superTransactions}}
      failureCondition: status.failed > {{workflow.parameters.backoffLimit}}
      manifest: |
        apiVersion: batch/v1
        kind: Job
        metadata:
          generateName: qserv-ingest-transactions-
        spec:
          parallelism: {{workflow.parameters.superTransactions}}
          template:
            spec:
              containers:
              - name: ingest
                command:
                - ingest-chunks.sh
                args:
                - "{{workflow.parameters.superTransactions}}"
                image: {{workflow.parameters.image}}
                imagePullPolicy: IfNotPresent
                volumeMounts:
                  - name: repl-creds
                    mountPath: /home/qserv/.lsst
                  - name: config
                    mountPath: /config
              restartPolicy: Never
              volumes:
                - name: repl-creds
                  secret:
                    secretName: secret-repl-creds-qserv
                - name: config
                  configMap:
                    name: config-ingest
          backoffLimit: {{workflow.parameters.backoffLimit}}
  - name: index-tables
    steps:
    - - name: index-tables
        template: ingest-step
        arguments:
          parameters: [{name: script, value: index-tables.sh}]
  - name: benchmark
    steps:
    - - name: benchmark
        template: ingest-step
        arguments:
          parameters: [{name: script, value: benchmark.sh}]
  - name: main
    dag:
      tasks:
      - name: queue
        template: ingest-step
        arguments:
          parameters: [{name: script, value: load-queue.sh}]
      - name: register
        template: ingest-step
        arguments:
          parameters: [{name: script, value: register.sh}]
      - name: transactions
        template: transactions
        dependencies: [queue, register]
      - name: check-transactions
        template: ingest-step
        arguments:
          parameters: [{name: script, value: check-transactions.sh}]
        dependencies: [transactions]
      - name: publish
        template: ingest-step
        arguments:
          parameters: [{name: script, value: publish.sh}]
        dependencies: [check-transactions]
      - name: index-tables
        template: index-tables
        dependencies: [publish]
      - name: validate
        template: ingest-step
        arguments:
          parameters: [{name: script, value: validate.sh}]
        dependencies: [index-tables]
      - name: benchmark
        template: benchmark
        dependencies: [validate]
