title: Using APScheduler in clock.py on Heroku to call def send_email_reminder from main app
body: <p>I have an app that tracks users borrowing equipment. In the application I have an app "tool_req". In the views.py file I have a def called "send_email_reminder". I want this to run once a day to send emails to the borrower that the rental period is over. I have installed APScheduler and have a file "clock.py" to run in the background on Heroku. My Procfile looks like this:</p>
  
  <p>Procfile.py
  ...</p>
  
  <pre><code>web: gunicorn trydjango.wsgi
  clock: python clock.py
  </code></pre>
  
  <p>...</p>
  
  <p>When I push the app using the following clock.py file I see the message every 3 minutes in my logs.</p>
  
  <p>clock.py</p>
  
  <pre><code>from apscheduler.schedulers.blocking import BlockingScheduler
  sched = BlockingScheduler()
  @sched.scheduled_job('interval', minutes=3)
  def timed_job():
      print('This job is run every three minutes.')
  sched.start()
  </code></pre>
  
  <p>So far so good.
  However, when I put in the code to run the send_email_reminder, i.e.,:</p>
  
  <p>clock.py</p>
  
  <pre><code>from apscheduler.schedulers.blocking import BlockingScheduler
  from tool_req.views import send_email_reminder
  sched = BlockingScheduler()
  @sched.scheduled_job('interval', minutes=3)
  def timed_job():
      send_email_reminder('request')
  sched.start()
  </code></pre>
  
  <p>I get this error:</p>
  
  <p><strong>app[clock.1]: ModuleNotFoundError: No module named '/app/trydjango/settings'</strong></p>
  
  <p>I have tried a lot of things including various combinations of the following in my clock.py file, to no avail.</p>
  
  <pre><code>import os
  from apscheduler.schedulers.blocking import BlockingScheduler
  from tool_req.views import send_email_reminder
  from django.contrib.auth.models import User
  from tools.models import Tool, Literature
  from pages.models import Person
  from tool_req.models import RequestPost, LiteratureRequestPost
  from django.conf import settings
  os.environ['DJANGO_SETTINGS_MODULE'] = 'trydjango.settings'
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "trydjango.settings")
  from django.db import models
  import django
  django.setup()
  from trydjango import settings
  from django.conf import settings
  from trydjango import trydjango_defaults
  settings.configure()
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>