How to pass python api endpoint to Kubernates CronJob

8/18/2020

This is first time I am encountering jobs running in react+python+kubernates project, so please allow me for thinking as a newbie.

Problem statement-

I have created an api endpoint in python and wanted that endpoint run in every 30 minutes as a job. The recommendation is, to use Cronjob by Kubernetes.

Here is some code snippet:

In main.py

@api.post("/fetchAllStudentProfile")
def import_all_student_data():
    
    print("\r\nSchedular starts on - %s" % datetime.now())

 // reads connection string about source(a database) from config.py
    jobConfig = config.read_jobConfig_file()

 // get all data from source and save into local db
   student_data= read_data.get_all_data(jobConfig)

Now I want this to pass to already written cron_job which is expecting in following format:

 <cron_job_name> 
  params= job_name_as_key , start_time

So, I am not getting what/how to pass params ( job_name_as_key and start_time ) in import_all_student_data() method.

References: Cron Jobs in K8s medium link

TIA

-- Chandan
cron
kubernetes
python
python-3.x

0 Answers