Scheduler is not working

hi guys
i am trying with this code but scheduler is not working i don’t know why can you please check

scheduler_events = {
“all”: [
“custom_app.custom_app.auto_import.auto_import”,
“custom_app.custom_app.api.testing”
]
}

please help any body
thanks
Eliyas

did you enable the schedular via command line?
bench --site your.site enable-scheduler

If yes, you can see in the logs (both in the server and in erp website) if anything came up.

Then you can make sure your methods works as expected with:
bench --site site1.local execute custom_app.custom_app.auto_import.auto_import

Finally you can trigger it manually to see if the error is with the scheduler or something:
bench --site site1.local trigger-scheduler-event all

2 Likes

i am getting error on bench --site site1.local trigger-scheduler-event all

Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 174, in _run_module_as_main
main”, fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 97, in
main()
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 18, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 764, in call
return self.main(*args, **kwargs)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 717, in main
rv = self.invoke(ctx)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 555, in invoke
return callback(*args, **kwargs)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/init.py”, line 25, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/scheduler.py”, line 30, in trigger_scheduler_event
frappe.utils.scheduler.trigger(site, event, now=True)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/scheduler.py”, line 185, in trigger
scheduler_task(site=site, event=event, handler=handler, now=True)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/scheduler.py”, line 281, in scheduler_task
frappe.get_attr(handler)()
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1019, in get_attr
return getattr(get_module(modulename), methodname)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 800, in get_module
return importlib.import_module(modulename)
File “/usr/lib/python2.7/importlib/init.py”, line 37, in import_module
import(name)
ImportError: No module named auto_importbiometric_attendance.biometric_attendance.api

if your file (which contains your method) is in the same location as your hook.py, then you need to remove your first custom_app:

“all”: [
“custom_app.auto_import.auto_import”,
“custom_app.api.testing”
]

thanks for you support

both file is not in same folder

like for custom app hooks file would be custom_app/custom_app

but my file is in custom_app/custom_app/custom_app
then auto_import and api file

when you’re using the import, you always need to remove 1 custom_app from your path.
so the path would always look like: custom_app.(here we are at the hook.py level:) api.testing
→ usually, the api.py file is at the same level as hook.py.

if you open the bench console, try to import your method as you did before. Check if you can call the method. If you can, then try to do the other step I mention above.

actaully i have tried with another approach for testing purpose i did doc_events before_save so when ever i am clicking button save on given doctype on that time its working fine
so i am using same path for scheduler_event but that’s not working

Well that’s weird because you have an import error somewhere.
Try to search for that line: auto_importbiometric_attendance in your server. I’m sure it’s a typo, but maybe you have a file name like that.

My last option would be to execute this line: bench --site site1.local execute custom_app.custom_app.auto_import.auto_import
Which will run your method and maybe give a more precise log?

yeah i have done bench --site site1.local execute custom_app.custom_app.auto_import.auto_import
both file executed fine

Hi,

Sorry if I budged in here but I just would like to ask, after I run this “bench --site site1.local trigger-scheduler-event all” bench showed me this “Event all does not exist!”?

Looks like you’ve just forgotten a comma somewhere. Python implicitly concatenates strings if comma is missing.

so ["frappe" "erpnext"] becomes ["frappeerpnext"]

Did you get your answer?

I have the same problem with the scheduler. It does not work…

I have enabled the scheduler via bench command
The i have triggered the all an cron event via bench command.
I get the message in the console “Event all does not exist!”

And i have created the events in the hooks.py correctly…

scheduler_events = {
“all”: [
“mas.scheduled_tasks.import_enventa_data”
],
“cron”: {
“0/1 * * * *”: [
“mas.scheduled_tasks.import_enventa_data”
],
}
}

I get the message in the console “Event all does not exist!”

Not Solved Yet

Me too

Please raise a GitHub issue under Frappe repository! Thank you

Double-checking your hooks.py file for correct event definitions and ensuring the syntax in your scheduler_events dictionary is accurate might resolve this issue.

Back in my early days of coding, I often ran into similar challenges. Using an online notepad to jot down my debugging steps and configurations really helped me keep track of what worked and what didn’t.

If the problem persists, it might be worth revisiting the bench commands to ensure the scheduler is properly enabled and events are triggered as expected. Sometimes, older posts or community forums might also have insights or updates that could shed light on your specific issue.