Skip to content

Commit

Permalink
Slow down time polling to 1m intervals. Implement new logging package
Browse files Browse the repository at this point in the history
  • Loading branch information
mwalters committed Oct 15, 2020
1 parent 3fed621 commit dd4c129
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=0.2.0
VERSION=0.2.1

fmt:
@find . -type f -name \*.py -print0 | xargs -0 black && \
Expand Down
23 changes: 11 additions & 12 deletions src/pytaskr
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import sys, os, time, datetime, argparse, pprint, asyncio, threading, glob
from crontab import CronTab
from yapsy.PluginManager import PluginManager
from pylioshelpers.logging import logging

CRON_CHECK_INTERVAL = 10
log = logging.log

CRON_CHECK_INTERVAL = 60
_loop = {}

pprint = pprint.PrettyPrinter(indent=4).pprint
Expand All @@ -15,7 +18,7 @@ args = parser.parse_args()

def main():
print()
log("Loading plugins ...")
log("Loading plugins ...", "info")
# Load the plugins from the plugins directory
manager = PluginManager()
manager.setPluginInfoExtension("plugin")
Expand All @@ -26,9 +29,9 @@ def main():
manager.collectPlugins()

plugins = manager.getAllPlugins()
log("Plugins loaded:")
log("Plugins loaded:", "info")
for plugin in plugins:
log("- " + plugin.name)
log("- " + plugin.name, "info")

print()

Expand All @@ -39,7 +42,7 @@ def main():
task_time = CronTab(plugin.plugin_object.get_schedule())
task_until = round(task_time.next(None, default_utc=True))

if task_until <= CRON_CHECK_INTERVAL:
if task_until < CRON_CHECK_INTERVAL:
log(
"Plugin: {plugin_name} - Executing".format(
plugin_name=plugin.name
Expand All @@ -53,14 +56,15 @@ def main():
plugin_name=plugin.name,
next_event=task_until,
crontab=plugin.plugin_object.get_schedule(),
)
),
"info",
)

sys.stdout.flush()
time.sleep(CRON_CHECK_INTERVAL)

except (KeyboardInterrupt, SystemExit):
log("KeyboardInterrupt received. Exiting...")
log("KeyboardInterrupt received. Exiting...", "warn")
print()
exit()

Expand All @@ -82,10 +86,5 @@ def get_plugin_directories(base_dir: str):
return plugin_directories


def log(message: str):
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print("[{timestamp}] {message}".format(timestamp=timestamp, message=message))


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
crontab==0.22.9
Yapsy==1.12.2
pylioshelpers==0.1.0

0 comments on commit dd4c129

Please sign in to comment.