Job.next_run_time not available form the outside
See original GitHub issueI’m working with the scheduler in a Django App (should not affect behavior)
I create a Job to Backup at specific Intervals and want to log the next execution time. Now i log it with:
logger.info(f"next Backup at {scheduler.get_job(job_id).next_run_time.strftime('%Y-%m-%d %H:%M:%S')}")
this raises an attribute Error:
logger.info(f"next Backup at {scheduler.get_job(job_id).next_run_time.strftime('%Y-%m-%d %H:%M:%S')}")
AttributeError: next_run_time
but when just logging the job i get a right output:
Backup.backup (trigger: interval[0:10:00], next run at: 2020-05-15 17:49:26 CEST)
when looking in the code i see that the job uses self.next_run_time
so the attribute is surely available, but not accessible as it seems in addition to that is the AttributeError incomplete just saying the attribute, not that this attribute does not exist, which seems pretty wierd…
complete relevant code below code below:
def startSubroutine(self)->None:
"""
Start the backup-subroutine
"""
self.start_time = datetime.datetime.now()
self.scheduler = BackgroundScheduler()
interval = self.settings['interval']
self.job_id = self.scheduler.add_job(self.backup, 'interval', **interval).id
# prepare info string to log
info_str = format_interval("Scheduled backup for ", interval)
logger.info(info_str)
# the critical line:
logger.info(f"Next Backup at {self.scheduler.get_job(self.job_id).next_run_time.strftime('%Y-%m-%d %H:%M:%S')}")
# start subroutine
self.scheduler.start()
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Nuxt instance unavailable on all pages · Issue #4287 - GitHub
Are you using useRuntimeConfig at all? Could you locate the code context around the line mentioned in server.mjs in the log you quoted...
Read more >Moving from @nuxtjs/dotenv to runtime config
It's time to migrate from @nuxtjs/dotenv module to use our new runtime config which has been released as of Nuxt v2. 13.
Read more >Why is runtimeConfig doesn't see environment variables in ...
If it's the bridge version, runtimeConfig cannot work. Cause I use @nuxt/bridge, not work. and then it worked on the 3.0.0-rc.3 version.
Read more >Pushing Nuxt.js Static Generation One Step Further - — lihbr
So let's throw target: "static" into our nuxt.config.js file and call it ... There is one case we have not discussed that is...
Read more >Introduction to Nuxt 3 modules - DEV Community
As there is no Nuxt 3 module template repository nor an article how to ... a nuxt.config.js file as well but it will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The job’s scheduled run time is available on v4.0 via
apscheduler.current_job
:Note that the API may change before v4.0 final.
I know this is an old issue but dropping my solution here in case it helps anyone who googles this. I faced a similar problem and have found a solution which seems to work quite nicely.
It looks like
next_run_time
is not available until the job is scheduled (you can check thepending
property on the job instance to see if it’s scheduled or not). The speed at which the job get’s scheduled depends on the scheduler you use.An alternative way to get the
next_run_time
is to calladd_job
with an explicitTrigger
object. Then you can callget_next_fire_time()
on theTrigger
object at any time to get the time theTrigger
will next cause the job to run.A minimal example: