Skip to content

Commit

Permalink
Add method documentation:
Browse files Browse the repository at this point in the history
  • Loading branch information
SirOibaf committed Oct 15, 2023
1 parent 0cb29cf commit f50f5d5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 3 additions & 2 deletions python/hopsworks/core/job_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,12 @@ def _update_job(self, name: str, config: dict):
def _schedule_job(self, name, schedule_config):
_client = client.get_instance()
path_params = ["project", self._project_id, "jobs", name, "schedule", "v2"]

headers = {"content-type": "application/json"}
method = "PUT" if schedule_config["id"] else "POST"

return job_schedule.JobSchedule.from_response_json(
_client._send_request(
"POST", path_params, headers=headers, data=json.dumps(schedule_config)
method, path_params, headers=headers, data=json.dumps(schedule_config)
)
)

Expand Down
28 changes: 27 additions & 1 deletion python/hopsworks/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,33 @@ def delete(self):
self._job_api._delete(self)

def schedule(self, cron_expression, start_time=None, end_time=None):
"""Schedule the execution of the job.
If a schedule for this job already exists, the method updates it.
```python
# Schedule the job
job.schedule(
cron_expression="0 */5 * ? * * *",
start_time=datetime.datetime.now(tz=timezone.utc)
)
# Retrieve the next execution time
print(job.job_schedule.next_execution_date_time)
```
# Arguments
cron_expression: str. The quartz cron expression
start_time: datetime, optional. The schedule start time in UTC.
If None, the current time is used. The start_time can be a value in the past.
end_time: datetime, optional. The schedule end time in UTC.
If None, the schedule will continue running indefinitely.
The end_time can be a value in the past.
# Returns
`JobSchedule`. The schedule of the job
"""
job_schedule = js.JobSchedule(
id=self._job_schedule.id if self._job_schedule else None,
start_date_time=start_time if start_time else datetime.now(tz=timezone.utc),
cron_expression=cron_expression,
end_time=end_time,
Expand All @@ -206,9 +232,9 @@ def schedule(self, cron_expression, start_time=None, end_time=None):
return self._job_schedule

def unschedule(self):
"""Unschedule the exceution of a Job"""
self._job_api._delete_schedule_job(self._name)
self._job_schedule = None
return self._job_schedule

def json(self):
return json.dumps(self, cls=util.Encoder)
Expand Down

0 comments on commit f50f5d5

Please sign in to comment.