mirror of
https://github.com/bspeice/metrik
synced 2024-11-23 15:48:10 -05:00
Switch live
to a BoolParameter
Instead of constructor argument
This commit is contained in:
parent
495a491096
commit
49953e9da4
@ -3,7 +3,7 @@ from __future__ import print_function
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from luigi import Task
|
from luigi import Task
|
||||||
from luigi.parameter import DateMinuteParameter
|
from luigi.parameter import DateMinuteParameter, BoolParameter
|
||||||
|
|
||||||
from metrik.targets.mongo import MongoTarget
|
from metrik.targets.mongo import MongoTarget
|
||||||
from metrik.targets.noop import NoOpTarget
|
from metrik.targets.noop import NoOpTarget
|
||||||
@ -38,19 +38,20 @@ class MongoNoBackCreateTask(MongoCreateTask):
|
|||||||
# Have one parameter to make sure that the MongoTarget created by `super`
|
# Have one parameter to make sure that the MongoTarget created by `super`
|
||||||
# doesn't blow up.
|
# doesn't blow up.
|
||||||
current_datetime = DateMinuteParameter()
|
current_datetime = DateMinuteParameter()
|
||||||
|
live = BoolParameter()
|
||||||
|
|
||||||
def __init__(self, live=False, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(MongoNoBackCreateTask, self).__init__(*args, **kwargs)
|
super(MongoNoBackCreateTask, self).__init__(*args, **kwargs)
|
||||||
self.live = live
|
|
||||||
child_name = type(self).__name__
|
child_name = type(self).__name__
|
||||||
if not live:
|
if not self.live:
|
||||||
logging.warning('Trying to create {child_name} without running'
|
logging.warning('Trying to create {} without running'
|
||||||
' live, errors potentially to ensue.'.format(child_name))
|
' live, errors potentially to ensue.'.format(child_name))
|
||||||
|
|
||||||
def output(self):
|
def output(self):
|
||||||
if self.live:
|
if self.live:
|
||||||
return super(MongoNoBackCreateTask, self).output()
|
return super(MongoNoBackCreateTask, self).output()
|
||||||
else:
|
else:
|
||||||
|
# TODO: return target closest to self.current_datetime
|
||||||
return NoOpTarget()
|
return NoOpTarget()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
11
test/tasks/test_base.py
Normal file
11
test/tasks/test_base.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from unittest import TestCase
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from metrik.tasks.base import MongoNoBackCreateTask
|
||||||
|
|
||||||
|
|
||||||
|
class BaseTaskTest(TestCase):
|
||||||
|
|
||||||
|
def test_mongo_no_back_live_false(self):
|
||||||
|
task = MongoNoBackCreateTask(current_datetime=datetime.now())
|
||||||
|
assert not task.live
|
Loading…
Reference in New Issue
Block a user