Nextdoor / ndscheduler

A flexible python library for building your own cron-like system, with REST APIs and a Web UI.
BSD 2-Clause "Simplified" License
1.08k stars 202 forks source link

Job Name - Again #83

Closed nbhoj closed 4 years ago

nbhoj commented 4 years ago

I have multiple jobs setup in my scheduler, I am having some trouble on how to fetch the job names within in the job. I am doing some logging for my own use. Would like log every job along with its name and time stamps.

dejaentenduu commented 4 years ago

@nbhoj I added it to the JobBase class in job.pyso that it was available to all of my jobs. First step is to find the ndscheduler folder. Depending on how you downloaded it, it may be adjacent to your other files or it may in your virtual environment folder (assuming you made one). For me ndscheduler is in "venv/lib/python3.6/site-packages/". Once you've found job.py find the "run_job.py" function.

In the run_job function you should see a line of code like: scheduler = schedule_manager.ScheduleManager.get_instance()

You can get a job and it's name with the following: job = scheduler.get_job(job_id) cls.job_name = job.name

Above I made job_name a class attribute. Basically, if you are in another job of your own that is subclassed from JobBase you can get the name of the current job by using self.job_name in that job.