Skip to content

Commit

Permalink
Debug logs added for job clearing & cancelling (#193)
Browse files Browse the repository at this point in the history
Co-authored-by: sijmenhuizenga <sijmenhuizenga@gmail.com>
  • Loading branch information
SijmenHuizenga committed Feb 7, 2021
2 parents 736a6d4 + e35d771 commit dc3780b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ venv

.cache
docs/_build
.idea/

# For Idea (e.g. PyCharm) users
.idea
*.iml
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ Thanks to all the wonderful folks who have contributed to schedule over the year
- gaguirregabiria <https://github.com/gaguirregabiria>
- rhagenaars <https://github.com/RHagenaars>
- Skenvy <https://github.com/skenvy>
- zcking <https://github.com/zcking>
6 changes: 5 additions & 1 deletion docs/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ To receive logs from Schedule, set the logging level to ``DEBUG``.
import schedule
import logging
logging.basicConfig()
schedule_logger = logging.getLogger('schedule')
schedule_logger.setLevel(level=logging.DEBUG)
Expand All @@ -19,13 +20,16 @@ To receive logs from Schedule, set the logging level to ``DEBUG``.
schedule.run_all()
schedule.clear()
This will result in the following log messages:

.. code-block:: text
DEBUG:schedule:Running *all* 1 jobs with 0s delay inbetween
DEBUG:schedule:Running *all* 1 jobs with 0s delay in between
DEBUG:schedule:Running job Job(interval=1, unit=seconds, do=job, args=(), kwargs={})
Hello, Logs
DEBUG:schedule:Deleting *all* jobs
Customize logging
Expand Down
7 changes: 5 additions & 2 deletions schedule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def run_all(self, delay_seconds=0):
:param delay_seconds: A delay added between every executed job
"""
logger.debug('Running *all* %i jobs with %is delay inbetween',
logger.debug('Running *all* %i jobs with %is delay in between',
len(self.jobs), delay_seconds)
for job in self.jobs[:]:
self._run_job(job)
Expand Down Expand Up @@ -131,8 +131,10 @@ def clear(self, tag=None):
jobs to delete
"""
if tag is None:
logger.debug('Deleting *all* jobs')
del self.jobs[:]
else:
logger.debug('Deleting all jobs tagged "%s"', tag)
self.jobs[:] = (job for job in self.jobs if tag not in job.tags)

def cancel_job(self, job):
Expand All @@ -142,9 +144,10 @@ def cancel_job(self, job):
:param job: The job to be unscheduled
"""
try:
logger.debug('Cancelling job "%s"', str(job))
self.jobs.remove(job)
except ValueError:
pass
logger.debug('Cancelling not-scheduled job "%s"', str(job))

def every(self, interval=1):
"""
Expand Down

0 comments on commit dc3780b

Please sign in to comment.