# kubectl apply -f helm/cron_jobs/devnet-txn-burst-cronjob.yaml
# the above command, with this accompanying file, needs only be run once.  it does not get run in CI.  this file is provided here for future reference
# make sure you're in the devnet2 namespace
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: devnet-txn-burst-cronjob
spec:
  concurrencyPolicy: Replace
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - command:
            - /bin/bash
            - -c
            - '
echo "booting mina daemon";
mina daemon --generate-genesis-proof true --peer-list-url https://storage.googleapis.com/seed-lists/devnet_seeds.txt --background;
sleep 480;
echo "done sleeping";
while true; do
  STATUS=$(mina client status | grep "Sync status");
  echo "$STATUS" | grep "Synced";
  RESULT=$?;
  if [ $RESULT -eq 0 ]; then
    echo "daemon is synced";
    break;
  else
    echo "waiting for daemon to sync";
    sleep 60;
  fi;
done;


mkdir /tmpkeys;
chmod 700 /tmpkeys;

cp /keys/whale-key/online-whale-account-1-key /tmpkeys;
chmod 600 /tmpkeys/online-whale-account-1-key;
cp /keys/fish-key/online-fish-account-1-key /tmpkeys;
chmod 600 /tmpkeys/online-fish-account-1-key;

./_build/default/src/app/batch_txn_tool/batch_txn_tool.exe gen-there-and-back-txns --num-txn-per-acct 100 --rate-limit-level 1 --rate-limit-interval 5000 --origin-sender-sk-path "/tmpkeys/online-whale-account-1-key" --origin-sender-sk-pw "naughty blue worm" --returner-sk-path "/tmpkeys/online-fish-account-1-key" --returner-sk-pw "naughty blue worm";

echo "ran batch txns";

while true; do echo looping; sleep 120; done;
            '
            
            env:
            - name: MINA_PRIVKEY_PASS
              value: ""
            - name: GCLOUD_KEYFILE
              value: /gcloud/keyfile.json
            image: gcr.io/o1labs-192920/mina-txn-burst-app@sha256:8c4a7e0c092dcdbe0f5d8bebefb374181012dfb08e7cd60f99ee88969f1b26e8
            imagePullPolicy: IfNotPresent
            name: devnet-txn-burst-cronjob
            resources: {}
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
            volumeMounts:
            - mountPath: /keys/whale-key/
              name: whale-key
            - mountPath: /keys/fish-key/
              name: fish-key
          dnsPolicy: ClusterFirst
          restartPolicy: Never
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
          volumes: [
            {
              "name": "whale-key",
              "secret": {
                "defaultMode": 0600,
                "items": [
                  {
                    "key": "key",
                    "path": "online-whale-account-1-key"
                  },
                  {
                    "key": "pub",
                    "path": "online-whale-account-1-key.pub"
                  }
                ],
                "secretName": "online-whale-account-1-key"
              }
            },
            {
              "name": "fish-key",
              "secret": {
                "defaultMode": 0600,
                "items": [
                  {
                    "key": "key",
                    "path": "online-fish-account-1-key"
                  },
                  {
                    "key": "pub",
                    "path": "online-fish-account-1-key.pub"
                  }
                ],
                "secretName": "online-fish-account-1-key"
              }
            }

          ]
  schedule: 0 13 * * * 
  # every day at 1pm GMT, which is 6am PST
  successfulJobsHistoryLimit: 3
  suspend: false
