Skip to content

Commit

Permalink
#55 Added database idle time (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb authored Jun 6, 2024
1 parent ed34701 commit e368cc3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

* #55 Added publicly callable function finding the database id from its name.
* #60: Added download of `openapi.json` when generating python client
* #64: Add an optional idle time parameter to the database factory.

## Documentation

Expand Down
7 changes: 5 additions & 2 deletions exasol/saas/client/api_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,18 @@ def create_database(
name: str,
cluster_size: str = "XS",
region: str = "eu-central-1",
idle_time: timedelta | None = None
) -> Optional[openapi.models.Database]:
def minutes(x: timedelta) -> int:
return x.seconds // 60

idle_time = idle_time or Limits.AUTOSTOP_MIN_IDLE_TIME
cluster_spec = openapi.models.CreateDatabaseInitialCluster(
name="my-cluster",
size=cluster_size,
auto_stop=openapi.models.AutoStop(
enabled=True,
idle_time=minutes(Limits.AUTOSTOP_MIN_IDLE_TIME),
idle_time=minutes(idle_time),
),
)
LOG.info(f"Creating database {name}")
Expand Down Expand Up @@ -225,11 +227,12 @@ def database(
name: str,
keep: bool = False,
ignore_delete_failure: bool = False,
idle_time: timedelta | None = None
):
db = None
start = datetime.now()
try:
db = self.create_database(name)
db = self.create_database(name, idle_time=idle_time)
yield db
wait_for_delete_clearance(start)
finally:
Expand Down

0 comments on commit e368cc3

Please sign in to comment.