Skip to content

Commit

Permalink
Avoid using schedule
Browse files Browse the repository at this point in the history
Execute task directly as there is already code taking care of the
delays.

Fixes #90
  • Loading branch information
nijel committed Apr 28, 2020
1 parent ae0555c commit 8bf8a84
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 20 deletions.
9 changes: 1 addition & 8 deletions cachet_url_monitor/scheduler.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import time
import os

import schedule
from yaml import load, SafeLoader

from cachet_url_monitor.client import CachetClient
Expand Down Expand Up @@ -36,11 +35,6 @@ def execute(self):
for decorator in self.decorators:
decorator.execute(self.configuration)

def start(self):
"""Sets up the schedule based on the configuration file."""
schedule.every(self.configuration.endpoint['frequency']).seconds.do(self.execute)


class Decorator(object):
"""Defines the actions a user can configure to be executed when there's an incident."""

Expand Down Expand Up @@ -77,10 +71,9 @@ def __init__(self, configuration, agent):
self.stop = False

def start(self):
self.agent.start()
self.logger.info('Starting monitor agent...')
while not self.stop:
schedule.run_pending()
self.agent.execute()
time.sleep(self.configuration.endpoint['frequency'])


Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
PyYAML==5.3
requests==2.22.0
schedule==0.6.0
Click==7.0
11 changes: 0 additions & 11 deletions tests/test_scheduler.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import mock

sys.modules['schedule'] = mock.Mock()
from cachet_url_monitor.scheduler import Agent, Scheduler


Expand All @@ -24,14 +23,6 @@ def test_execute(self):
evaluate.assert_called_once()
push_status.assert_not_called()

def test_start(self):
every = sys.modules['schedule'].every
self.configuration.endpoint = {'frequency': 5}

self.agent.start()

every.assert_called_with(5)


class SchedulerTest(unittest.TestCase):
@mock.patch('requests.get')
Expand Down Expand Up @@ -83,5 +74,3 @@ def test_start(self):
# Leaving it as a placeholder.
self.scheduler.stop = True
self.scheduler.start()

self.agent.start.assert_called()

0 comments on commit 8bf8a84

Please sign in to comment.