-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
13 changed files
with
271 additions
and
26 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
from .operators import JobOperator, JobCleanupOperator, ReportOperator, PapermillOperator, NBConvertOperator, ReportPostOperator | ||
from .common import JobOperator, JobCleanupOperator, ReportOperator | ||
from .dokku import DokkuOperator | ||
from .nbconvert import NBConvertOperator | ||
from .papermill import PapermillOperator | ||
from .post import ReportPostOperator | ||
from .voila import VoilaOperator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from airflow.models import BaseOperator | ||
from airflow.utils.decorators import apply_defaults | ||
from paperboy.utils import name_to_class | ||
|
||
|
||
class JobOperator(BaseOperator): | ||
@apply_defaults | ||
def __init__(self, job, *args, **kwargs): | ||
super(JobOperator, self).__init__(*args, **kwargs) | ||
self.job = job | ||
|
||
def execute(self, context): | ||
self.log.critical('job') | ||
|
||
|
||
class JobCleanupOperator(BaseOperator): | ||
@apply_defaults | ||
def __init__(self, job, *args, **kwargs): | ||
super(JobCleanupOperator, self).__init__(*args, **kwargs) | ||
self.job = job | ||
|
||
def execute(self, context): | ||
self.log.critical('job-cleanup') | ||
|
||
|
||
class ReportOperator(BaseOperator): | ||
@apply_defaults | ||
def __init__(self, report, *args, **kwargs): | ||
super(ReportOperator, self).__init__(*args, **kwargs) | ||
self.report = report | ||
|
||
def execute(self, context): | ||
self.log.critical('report') | ||
|
||
|
||
class ReportPostOperator(BaseOperator): | ||
@apply_defaults | ||
def __init__(self, report, config, *args, **kwargs): | ||
super(ReportPostOperator, self).__init__(*args, **kwargs) | ||
self.report = report | ||
self.nbconvert_task_id = self.task_id.replace('ReportPost', 'ReportNBConvert') | ||
|
||
self.config = name_to_class(config.get('config')).from_json(config) | ||
|
||
def execute(self, context): | ||
self.log.critical('report-post') | ||
|
||
task_instance = context['task_instance'] | ||
output_nb = task_instance.xcom_pull(task_ids=self.nbconvert_task_id, key=self.task_id) | ||
self.log.critical(output_nb) | ||
|
||
outputter = self.config.clazz(self.config) | ||
outputter.write(self.report, output_nb, task_id=self.task_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from airflow.models import BaseOperator | ||
from airflow.utils.decorators import apply_defaults | ||
from paperboy.utils import name_to_class | ||
|
||
|
||
class DokkuOperator(BaseOperator): | ||
@apply_defaults | ||
def __init__(self, report, config, *args, **kwargs): | ||
super(DokkuOperator, self).__init__(*args, **kwargs) | ||
self.report = report | ||
self.nbconvert_task_id = self.task_id.replace('ReportPost', 'ReportNBConvert') | ||
|
||
self.config = name_to_class(config.get('config')).from_json(config) | ||
|
||
def execute(self, context): | ||
self.log.critical('report-post') | ||
|
||
task_instance = context['task_instance'] | ||
output_nb = task_instance.xcom_pull(task_ids=self.nbconvert_task_id, key=self.task_id) | ||
self.log.critical(output_nb) | ||
|
||
outputter = self.config.clazz(self.config) | ||
outputter.write(self.report, output_nb, task_id=self.task_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from airflow.models import BaseOperator | ||
from airflow.utils.decorators import apply_defaults | ||
|
||
|
||
class NBConvertOperator(BaseOperator): | ||
@apply_defaults | ||
def __init__(self, report, *args, **kwargs): | ||
super(NBConvertOperator, self).__init__(*args, **kwargs) | ||
self.report = report | ||
self.papermill_task_id = self.task_id.replace('ReportNBConvert', 'ReportPapermill') | ||
self.report_post_task_iud = self.task_id.replace('ReportNBConvert', 'ReportPost') | ||
|
||
def execute(self, context): | ||
self.log.critical('nbconvert') | ||
|
||
task_instance = context['task_instance'] | ||
papermilled = task_instance.xcom_pull(task_ids=self.papermill_task_id, key=self.task_id) | ||
|
||
if self.report['meta']['output'] != 'notebook': | ||
from paperboy.worker import run_nbconvert | ||
|
||
template = self.report['meta'].get('template', '') | ||
|
||
ret = run_nbconvert(self.report['meta']['notebook'], | ||
papermilled, | ||
self.report['meta']['output'], | ||
template, | ||
self.report['meta']['strip_code'], | ||
) | ||
else: | ||
ret = papermilled | ||
|
||
task_instance.xcom_push(key=self.report_post_task_iud, value=ret) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from airflow.models import BaseOperator | ||
from airflow.utils.decorators import apply_defaults | ||
|
||
|
||
class PapermillOperator(BaseOperator): | ||
@apply_defaults | ||
def __init__(self, report, *args, **kwargs): | ||
super(PapermillOperator, self).__init__(*args, **kwargs) | ||
self.report = report | ||
self.nbconvert_task_id = self.task_id.replace('ReportPapermill', 'ReportNBConvert') | ||
|
||
def execute(self, context): | ||
self.log.critical('papermill') | ||
|
||
from paperboy.worker import run_papermill | ||
ret = run_papermill(self.report['meta']['notebook'], | ||
self.report['meta']['notebook_text'], | ||
self.report['meta']['parameters'], | ||
self.report['meta']['strip_code']) | ||
|
||
task_instance = context['task_instance'] | ||
task_instance.xcom_push(key=self.nbconvert_task_id, value=ret) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from airflow.models import BaseOperator | ||
from airflow.utils.decorators import apply_defaults | ||
from paperboy.utils import name_to_class | ||
|
||
|
||
class ReportPostOperator(BaseOperator): | ||
@apply_defaults | ||
def __init__(self, report, config, *args, **kwargs): | ||
super(ReportPostOperator, self).__init__(*args, **kwargs) | ||
self.report = report | ||
self.nbconvert_task_id = self.task_id.replace('ReportPost', 'ReportNBConvert') | ||
|
||
self.config = name_to_class(config.get('config')).from_json(config) | ||
|
||
def execute(self, context): | ||
self.log.critical('report-post') | ||
|
||
task_instance = context['task_instance'] | ||
output_nb = task_instance.xcom_pull(task_ids=self.nbconvert_task_id, key=self.task_id) | ||
self.log.critical(output_nb) | ||
|
||
outputter = self.config.clazz(self.config) | ||
outputter.write(self.report, output_nb, task_id=self.task_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from airflow.models import BaseOperator | ||
from airflow.utils.decorators import apply_defaults | ||
from paperboy.utils import name_to_class | ||
|
||
|
||
class VoilaOperator(BaseOperator): | ||
@apply_defaults | ||
def __init__(self, report, config, *args, **kwargs): | ||
super(VoilaOperator, self).__init__(*args, **kwargs) | ||
self.report = report | ||
self.nbconvert_task_id = self.task_id.replace('ReportPost', 'ReportNBConvert') | ||
|
||
self.config = name_to_class(config.get('config')).from_json(config) | ||
|
||
def execute(self, context): | ||
self.log.critical('report-post') | ||
|
||
task_instance = context['task_instance'] | ||
output_nb = task_instance.xcom_pull(task_ids=self.nbconvert_task_id, key=self.task_id) | ||
self.log.critical(output_nb) | ||
|
||
outputter = self.config.clazz(self.config) | ||
outputter.write(self.report, output_nb, task_id=self.task_id) |
Oops, something went wrong.