PythonTask
¶
Task
¶
Base class for tasks in SAYN.
Attributes:
Name | Type | Description |
---|---|---|
name |
str |
Name of the task as defined in the task group. |
group |
str |
Name of the task group where the task was defined. |
run_arguments |
dict |
Dictionary containing the values for the arguments specified in the cli. |
task_parameters |
dict |
Provides access to the parameters specified in the task. |
project_parameters |
dict |
Provides access to the global parameters of the project. |
parameters |
dict |
Convinience property joining project and task parameters. |
connections |
dict |
Dictionary of connections specified for the project. |
tracker |
sayn.logging.TaskEventTracker |
Message tracker for the current task. |
jinja_env |
jinja2.Environment |
Jinja environment for this task. The environment comes pre-populated with the parameter values relevant to the task. |
add_run_steps(self, steps)
¶
Adds new steps to the list of run steps for the task, allowing the CLI to indicate task execution progress.
compile_obj(self, obj, **params)
¶
Compiles the object into a string using the task jinja environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
str/Path/Template |
The object to compile. If the object is not a Jinja template object, |
required |
params |
dict |
An optional dictionary of additional values to use for compilation. Note: Project and task parameters values are already set in the environment, so there's no need to pass them on |
{} |
debug(self, message, details=None)
¶
Print a debug message when executing sayn in debug mode (sayn run -d
)
error(self, message, details=None)
¶
Prints an error message which will be persisted on the screen after the task concludes execution.
Executing this method doesn't abort the task or changes the task status. Use return self.fail
for that instead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str |
An optinal error message to print to the screen. |
required |
fail(self, msg=None)
¶
Returned on failure in any stage.
finish_current_step(self, result=Result.Ok: None)
¶
Specifies the end of the current step
get_test_breakdown(self, breakdown)
¶
Return list breakdown of: test status, test type and column.
Usage:
breakdown = self.get_test_breakdown(self.test_breakdown)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
breakdown |
list |
test_breakdown list given by db method _construct_tests |
required |
info(self, message, details=None)
¶
Prints an info message.
ready(self)
¶
(Deprecated: use success
instead) Returned on successful execution.
set_run_steps(self, steps)
¶
Sets the run steps for the task, allowing the CLI to indicate task execution progress.
start_step(self, step)
¶
Specifies the start of a task step
step(self, step)
¶
Step context
Usage:
with self.step('Generate Data'):
data = generate_data()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step |
str |
name of the step being executed. |
required |
success(self)
¶
Returned on successful execution.
test_failure(self, breakdown, result, run_argument)
¶
CLI outputs on failed test execution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
breakdown |
list |
output of get_test_breakdown class method. |
required |
result |
dict |
output of test query. |
required |
run_argument |
str |
"debug" entry in class run_arguments. |
required |
test_sucessful(self, breakdown)
¶
CLI outputs on successful test execution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
breakdown |
list |
output of get_test_breakdown class method. |
required |
warning(self, message, details=None)
¶
Prints a warning message which will be persisted on the screen after the task concludes execution.
write_compilation_output(self, content, suffix=None, extension='sql')
¶
Writes text content into the compilation folder
The file will be stored in a folder with the name of the group the task belongs to and the name of the file will be that of the task name.