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

Getting Job Name? #79

Closed dejaentenduu closed 4 years ago

dejaentenduu commented 4 years ago

Is there an easy way to get the job name? I can't seem to figure out how. Any help would be great.

sabw8217 commented 4 years ago

I'm not sure I understand the question. Are you trying to get the job name via an API from inside the job? I think you can get your execution_id, from there look up the particular Execution and get a job_id, and then use apscheduler APIs to look up a particular Job. The datastore extends apscheduler.jobstores.sqlalchemy.SQLAlchemyJobStore.

dejaentenduu commented 4 years ago

Sorry, I should have given more detail and probably didn't ask that correctly. For context, I'm trying to set up an email notification system that alerts you when a job either fails or successfully completes. Right now, I can get the job_id and execution_id, and they would be helpful for an alert, but having the job name as it is written in the UI would great as well.

What you described sounds like what I need, I appreciate the response.

dejaentenduu commented 4 years ago

I was able to get the job name, thanks for the help. Probably relatively simple for most people, but below is how I did it for anyone else struggling like I was:

Code already present in JobBase class: scheduler = scheduler_manager.ScheduleManager.get_instance() datastore = scheduler.get_datastore()

Code needed to get the name: execution = datastore.get_execution(execution_id) # returns a dict with a nested job dict job_name = execution['job']['name']

nbhoj commented 4 years ago

I am still not clear on how to fetch the jobs name within the job. could you tell me which scripts-functions to import?