ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Unable to run scheduled tasks mentioned in hooks?


#1

Hi,

I am in a kind of problem which I am unable to debug, I have created a scheduled task in my custom app and want it to run hourly. The task would run just fine with the command bench --site [site_name] execute [file-to-run] and they also send the email but somehow these tasks don’t run on schedule. There is no scheduler log or any kind of error snapshot for these tasks.

Can anyone help me what seems to be wrong, I have also checked the Enable Scheduled Jobs option is also checked in my system settings.

The hooks entry is:

And the task is below:


Scheduler not working for custom apps?
#2

That is odd…Are your other scheduled tasks running fine? Also what version of erpnext / frappe are you on?


#3

well I am facing this problem in both v7 and v6. I am sure that there is something missing.
I have never created a scheduled task but my standard scheduled tasks from daily emails are running fine.

v7 == test environment and v6 == production environment.


#4

Does the task run when you call : bench trigger-scheduler-event rigpl_erpnext.rigpl_erpnext.scheduled_tasks.communication.daily


#5

Well here is the situation:

bench --site [sitename] execute rigpl_erpnext.rigpl_erpnext.scheduled_tasks.communication.daily - Works perfectly fine

Whereas
bench --site [sitename] trigger-scheduler-eventrigpl_erpnext.rigpl_erpnext.scheduled_tasks.communication.daily is not working :confused:


#6

@adityaduggal I am also facing the similar problem. My Scheduled task is not running. Did you find the solution to your problem. I am using V6.

bench --site [sitename] execute erpnext.controllers.update_item_class.execute - Works perfectly fine

Whereas
bench --site [sitename] trigger-scheduler-event erpnext.controllers.update_item_class.execute is not working

Please suggest me how to run a event on particular time.i.e hourly?


#7

I have same problem, the scheduled jobs and the scheduled backup are not running ??


#8

@hfarid you can you can set the new cronjob


#9

What do you mean “new cronjob” ?


#10

I found that only the backup is not working while other scheduled jobs like recurring invoices are running fine.


#11

@adityaduggal You were able solve this?


#12

Hi!, Same issue here. Did you solve it?


#13

Just trying to answer this query since alot of us face this issue and kind of are out of wits to know the real cause.
First of all thanks to @saurabh6790 for resolving this issue reference: WN-SUP29014.

This is how I have resolved this issue:

Step1:

  1. First Check if your code is working by `bench --site [site_name] execute [path_to_file]
  2. If your scheduled task code is fine then check if scheduler is working bench --site [site-name] trigger-scheduler-event all/hourly/daily/monthly
  3. Most probably this would not work since schedulers are not working
  4. Now try bench --site all clear-cache (and most probably this won’t work too)
  5. Now get into site console where the problem is bench --site [site-name] console
  6. Enter this command frappe.cache().get_value('scheduler_events'), this would show the events in your cache for scheduler and in my case the custom_app tasks were missing as below:
In [2]: frappe.cache().get_value('scheduler_events')
Out[2]: 
{u'all': [u'frappe.email.queue.flush',
  u'frappe.email.doctype.email_account.email_account.pull',
  u'frappe.email.doctype.email_account.email_account.notify_unreplied',
  u'frappe.oauth.delete_oauth2_data',
  u'frappe.integrations.doctype.razorpay_settings.razorpay_settings.capture_payment',
  u'frappe.twofactor.delete_all_barcodes_for_users'],
 u'daily': [u'frappe.email.queue.clear_outbox',
  u'frappe.desk.notifications.clear_notifications',
  u'frappe.core.doctype.error_log.error_log.set_old_logs_as_seen',
  u'frappe.desk.doctype.event.event.send_event_digest',
  u'frappe.sessions.clear_expired_sessions',
  u'frappe.email.doctype.email_alert.email_alert.trigger_daily_alerts',
  u'frappe.async.remove_old_task_logs',
  u'frappe.utils.scheduler.disable_scheduler_on_expiry',
  u'frappe.utils.scheduler.restrict_scheduler_events_if_dormant',
  u'frappe.email.doctype.auto_email_report.auto_email_report.send_daily',
  u'frappe.core.doctype.feedback_request.feedback_request.delete_feedback_request',
  u'frappe.core.doctype.authentication_log.authentication_log.clear_authentication_logs'],
 u'daily_long': [u'frappe.integrations.doctype.dropbox_settings.dropbox_settings.take_backups_daily',
  u'frappe.integrations.doctype.s3_backup_settings.s3_backup_settings.take_backups_daily'],
 u'hourly': [u'frappe.model.utils.link_count.update_link_count',
  u'frappe.model.utils.user_settings.sync_user_settings',
  u'frappe.utils.error.collect_error_snapshots',
  u'frappe.desk.page.backups.backups.delete_downloadable_backups',
  u'frappe.limits.update_space_usage'],
 u'monthly': [u'frappe.email.doctype.auto_email_report.auto_email_report.send_monthly'],
 u'monthly_long': [u'frappe.integrations.doctype.s3_backup_settings.s3_backup_settings.take_backups_monthly'],
 u'weekly_long': [u'frappe.integrations.doctype.dropbox_settings.dropbox_settings.take_backups_weekly',
  u'frappe.integrations.doctype.s3_backup_settings.s3_backup_settings.take_backups_weekly']}

  1. Now since the tasks were missing do sudo supervisorctl restart all now I got an issue here as some processes exited with error as below:
[frappe@www frappe-bench]$ sudo supervisorctl restart all
frappe-bench-workers:frappe-bench-frappe-schedule: stopped
frappe-bench-workers:frappe-bench-frappe-default-worker-0: stopped
frappe-bench-workers:frappe-bench-frappe-long-worker-0: stopped
frappe-bench-workers:frappe-bench-frappe-short-worker-0: stopped
frappe-bench-web:frappe-bench-frappe-web: stopped
frappe-bench-web:frappe-bench-node-socketio: stopped
frappe-bench-redis:frappe-bench-redis-queue: stopped
frappe-bench-redis:frappe-bench-redis-cache: stopped
frappe-bench-redis:frappe-bench-redis-socketio: stopped
frappe-bench-workers:frappe-bench-frappe-schedule: started
frappe-bench-workers:frappe-bench-frappe-default-worker-0: ERROR (abnormal termination)
frappe-bench-workers:frappe-bench-frappe-long-worker-0: started
frappe-bench-workers:frappe-bench-frappe-short-worker-0: started
frappe-bench-web:frappe-bench-frappe-web: started
frappe-bench-redis:frappe-bench-redis-cache: started
frappe-bench-redis:frappe-bench-redis-socketio: started
frappe-bench-web:frappe-bench-node-socketio: started
frappe-bench-redis:frappe-bench-redis-queue: started
[frappe@www frappe-bench]$ 
  1. Now do run this command to restart the failed process sudo supervisorctl restart frappe-bench-workers:frappe-bench-frappe-default-worker-0 see how we referenced the process name.
  2. Now again in site console after restarting the processes check with frappe.cache().get_value('scheduler_events')

Now if all the frappe-bench workers were started properly then you should be able to see your custom_app processes in the console output.


#14

Unfortunately, this did not work for me when I run
$ frappe.cache().get_value('scheduler_events')
in the console I do not get any schedule tasks however running:
$ bench --site [site-name] trigger-scheduler-event all
for example works perfectly, Another help, please