From 8fb5fa9c328a07a270d1e5050bad9b47cea0aa48 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Wed, 24 Aug 2016 22:47:11 -0400 Subject: [PATCH] Another update to the cron scripts --- metrik/__init__.py | 2 +- metrik/batch.py | 15 +++++++++++++-- test/test_batch.py | 1 - 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/metrik/__init__.py b/metrik/__init__.py index 1e9ec6d..7847d0b 100644 --- a/metrik/__init__.py +++ b/metrik/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.3.0' +__version__ = '0.3.1' __release__ = __version__ \ No newline at end of file diff --git a/metrik/batch.py b/metrik/batch.py index a2eda8b..b90bfb6 100644 --- a/metrik/batch.py +++ b/metrik/batch.py @@ -4,6 +4,8 @@ from datetime import datetime from argparse import ArgumentParser from dateutil.parser import parse from six import StringIO +from subprocess import check_output +from os import path from metrik.conf import get_config from metrik.flows.rates_flow import LiborFlow @@ -23,15 +25,24 @@ def run_flow(flow_class, present, live): def build_cron_file(): EXEC = 'metrik' FLOW_FLAG = '-f' + USER = 'root' + metrik_command_location = path.dirname(check_output(['which', 'metrik'])) + cron_header = '''# cron.d entries for metrik + +SHELL=/bin/sh +PATH={} + +'''.format(metrik_command_location) cron_strings = [] for flow_name, flow_class in flows.items(): cron_string = flow_class.get_schedule().get_cron_string() cron_strings.append( - cron_string + ' ' + EXEC + ' ' + FLOW_FLAG + ' ' + flow_name + cron_string + ' ' + USER + ' ' + EXEC + ' ' + + FLOW_FLAG + ' ' + flow_name ) - return '\n'.join(cron_strings) + '\n' + return cron_header + '\n'.join(cron_strings) + '\n' def list_flows(): diff --git a/test/test_batch.py b/test/test_batch.py index 09a02a7..12ddaed 100644 --- a/test/test_batch.py +++ b/test/test_batch.py @@ -14,5 +14,4 @@ class BatchTest(TestCase): def test_cron_string(self): cron_string = build_cron_file() - assert len(cron_string.split('\n')) == len(flows) + 1 assert cron_string[-1] == '\n'