Skip to content

Commit a4fe395

Browse files
committed
add helper to build job definitions
1 parent ca4d505 commit a4fe395

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

dataikuapi/dss/project.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ def start_job_and_wait(self, definition, no_fail=False):
304304
raise DataikuException("Job run did not finish. Status: %s" % (job_state))
305305
return job_state
306306

307+
def new_job_definition_builder(self, job_type='NON_RECURSIVE_FORCED_BUILD'):
308+
return JobDefinitionBuilder(self.project_key, job_type)
309+
307310
########################################################
308311
# Variables
309312
########################################################
@@ -571,3 +574,45 @@ def set_tags(self, tags={}):
571574
@param obj: must be a modified version of the object returned by list_tags
572575
"""
573576
return self.client._perform_empty("PUT", "/projects/%s/tags" % self.project_key, body = tags)
577+
578+
579+
class JobDefinitionBuilder(object):
580+
def __init__(self, project_key, job_type="NON_RECURSIVE_FORCED_BUILD"):
581+
"""
582+
Create a helper to build a job definition
583+
584+
:param project_key: the project in which the job is launched
585+
:param job_type: the build type for the job RECURSIVE_BUILD, NON_RECURSIVE_FORCED_BUILD,
586+
RECURSIVE_FORCED_BUILD, RECURSIVE_MISSING_ONLY_BUILD
587+
588+
"""
589+
self.project_key = project_key
590+
self.definition = {'type':job_type, 'refreshHiveMetastore':False, 'outputs':[]}
591+
592+
def with_type(self, job_type):
593+
"""
594+
Sets the build type
595+
596+
:param job_type: the build type for the job RECURSIVE_BUILD, NON_RECURSIVE_FORCED_BUILD,
597+
RECURSIVE_FORCED_BUILD, RECURSIVE_MISSING_ONLY_BUILD
598+
"""
599+
self.definition['type'] = job_type
600+
return self
601+
602+
def with_refresh_metastore(self, refresh_metastore):
603+
"""
604+
Sets whether the hive tables built by the job should have their definitions
605+
refreshed after the corresponding dataset is built
606+
"""
607+
self.definition['refreshHiveMetastore'] = refresh_metastore
608+
return self
609+
610+
def with_output(self, name, object_type=None, object_project_key=None, partition=None):
611+
"""
612+
Adds an item to build in the definition
613+
"""
614+
self.definition['outputs'].append({'type':object_type, 'id':name, 'projectKey':object_project_key, 'partition':partition})
615+
return self
616+
617+
def get_definition(self):
618+
return self.definition

0 commit comments

Comments
 (0)