[Python] KEDA ScaledJob with MongoDB _id fails to pass JOB_ID to Python script

Discussão em 'Python' iniciado por Stack, Agosto 27, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to use KEDA ScaledJob to process jobs from a MongoDB collection. Each document has a _id (ObjectId) and a jobStatus field. My Python script requires the job ID as an argument:

    python downloader.py <job_id>

    - name: MONGO_URI
    valueFrom:
    secretKeyRef:
    name: filesure-secrets
    key: MONGO_URI
    - name: AZURE_BLOB_CONN
    valueFrom:
    secretKeyRef:
    name: filesure-secrets
    key: AZURE_BLOB_CONN
    - name: AZURE_CONTAINER
    value: "documents"
    - name: JOB_ID
    valueFrom:
    fieldRef:
    fieldPath: metadata.labels['keda.sh/job-id']
    resources:
    requests:
    memory: "100Mi"
    cpu: "200m"
    limits:
    memory: "512Mi"
    cpu: "500m"
    restartPolicy: Never
    backoffLimit: 2
    completions: 1
    ttlSecondsAfterFinished: 300
    pollingInterval: 30
    successfulJobsHistoryLimit: 5
    failedJobsHistoryLimit: 5
    maxReplicaCount: 10
    triggers:
    - type: mongodb
    metadata:
    connectionStringFromEnv: MONGO_URI
    dbName: filesure
    collection: jobs
    query: '{"jobStatus": "pending"}'
    This is my mongodb jobs
    {"_id":{"$oid":"68a9fb3835b62fc6b0eb250f"},"cin":"L83203AO1996HTR262495","companyName":"CORE SERVICES LIMITED","jobStatus":"pending","processingStages":{"documentDownload":{"status":"pending","totalDocuments":{"$numberInt":"39"},"downloadedDocuments":{"$numberInt":"13"},"pendingDocuments":{"$numberInt":"26"},"lastUpdated":{"$date":{"$numberLong":"1755970747528"}}}},"createdAt":{"$date":{"$numberLong":"1755970360712"}},"updatedAt":{"$date":{"$numberLong":"1755970747528"}}}
    Using queryValue: "1" → doesn’t correctly pass the ObjectId.
    How can I make KEDA pass the MongoDB _id of a pending job to my Python script?

    I’d prefer the solution where each pod fetches a single pending job and runs:
    python downloader.py 68a9fb3835b62fc6b0eb250f

    Continue reading...

Compartilhe esta Página