-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Job scheduler implementation (#1308)
This PR adds support for creating and dropping jobs in evadb based on this [task](#1248). 1. Jobs can be created using the create job query: > CREATE JOB {job_name} AS { > {job_queries; ...} > } > START {start_time} > END {end_time} > EVERY {repeat_period} {repeat_unit} 2. Created jobs can be dropped using: > DROP JOB {job_name} 3. The scheduled jobs will only be triggered if the job scheduler process is started explicitly using: > EvaDBConnection.start_jobs() 4. The job scheduler process can be stopped using: > EvaDBConnection.stop_jobs() --------- Co-authored-by: Gaurav Tarlok Kakkar <[email protected]>
- Loading branch information
1 parent
995f7fe
commit 1fbb74f
Showing
25 changed files
with
1,452 additions
and
10 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# coding=utf-8 | ||
# Copyright 2018-2023 EvaDB | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import datetime | ||
import json | ||
|
||
from sqlalchemy import Boolean, Column, DateTime, Index, Integer, String | ||
from sqlalchemy.orm import relationship | ||
|
||
from evadb.catalog.models.base_model import BaseModel | ||
from evadb.catalog.models.utils import JobCatalogEntry | ||
|
||
|
||
class JobCatalog(BaseModel): | ||
"""The `JobCatalog` catalog stores information about all the created Jobs. | ||
`_row_id:` an autogenerated unique identifier. | ||
`_name:` the job name. | ||
`_queries:` the queries to run as part of this job | ||
`_start_time:` the job's start time | ||
`_end_time:` the job's end time | ||
`_repeat_interval:` the job's repeat interval | ||
`_repeat_period:` the job's repeat period | ||
`_active:` is the job active/deleted | ||
`_next_scheduled_run:` the next trigger time for the job as per the schedule | ||
`_created_at:` entry creation time | ||
`_updated_at:` entry last update time | ||
""" | ||
|
||
__tablename__ = "job_catalog" | ||
|
||
_name = Column("name", String(100), unique=True) | ||
_queries = Column("queries", String, nullable=False) | ||
_start_time = Column("start_time", DateTime, default=datetime.datetime.now) | ||
_end_time = Column("end_ts", DateTime) | ||
_repeat_interval = Column("repeat_interval", Integer) | ||
_active = Column("active", Boolean, default=True) | ||
_next_scheduled_run = Column("next_scheduled_run", DateTime) | ||
|
||
_created_at = Column("created_at", DateTime, default=datetime.datetime.now) | ||
_updated_at = Column( | ||
"updated_at", | ||
DateTime, | ||
default=datetime.datetime.now, | ||
onupdate=datetime.datetime.now, | ||
) | ||
|
||
_next_run_index = Index("_next_run_index", _next_scheduled_run) | ||
_job_history_catalog = relationship("JobHistoryCatalog", cascade="all, delete") | ||
|
||
def __init__( | ||
self, | ||
name: str, | ||
queries: str, | ||
start_time: datetime, | ||
end_time: datetime, | ||
repeat_interval: Integer, | ||
active: bool, | ||
next_schedule_run: datetime, | ||
): | ||
self._name = name | ||
self._queries = queries | ||
self._start_time = start_time | ||
self._end_time = end_time | ||
self._repeat_interval = repeat_interval | ||
self._active = active | ||
self._next_scheduled_run = next_schedule_run | ||
|
||
def as_dataclass(self) -> "JobCatalogEntry": | ||
return JobCatalogEntry( | ||
row_id=self._row_id, | ||
name=self._name, | ||
queries=json.loads(self._queries), | ||
start_time=self._start_time, | ||
end_time=self._end_time, | ||
repeat_interval=self._repeat_interval, | ||
active=self._active, | ||
next_scheduled_run=self._next_scheduled_run, | ||
created_at=self._created_at, | ||
updated_at=self._updated_at, | ||
) |
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,73 @@ | ||
# coding=utf-8 | ||
# Copyright 2018-2023 EvaDB | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import datetime | ||
|
||
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, UniqueConstraint | ||
|
||
from evadb.catalog.models.base_model import BaseModel | ||
from evadb.catalog.models.utils import JobHistoryCatalogEntry | ||
|
||
|
||
class JobHistoryCatalog(BaseModel): | ||
"""The `JobHistoryCatalog` stores the execution history of jobs . | ||
`_row_id:` an autogenerated unique identifier. | ||
`_job_id:` job id. | ||
`_job_name:` job name. | ||
`_execution_start_time:` start time of this run | ||
`_execution_end_time:` end time for this run | ||
`_created_at:` entry creation time | ||
`_updated_at:` entry last update time | ||
""" | ||
|
||
__tablename__ = "job_history_catalog" | ||
|
||
_job_id = Column( | ||
"job_id", Integer, ForeignKey("job_catalog._row_id", ondelete="CASCADE") | ||
) | ||
_job_name = Column("job_name", String(100)) | ||
_execution_start_time = Column("execution_start_time", DateTime) | ||
_execution_end_time = Column("execution_end_time", DateTime) | ||
_created_at = Column("created_at", DateTime, default=datetime.datetime.now) | ||
_updated_at = Column( | ||
"updated_at", | ||
DateTime, | ||
default=datetime.datetime.now, | ||
onupdate=datetime.datetime.now, | ||
) | ||
|
||
__table_args__ = (UniqueConstraint("job_id", "execution_start_time"), {}) | ||
|
||
def __init__( | ||
self, | ||
job_id: int, | ||
job_name: str, | ||
execution_start_time: datetime, | ||
execution_end_time: datetime, | ||
): | ||
self._job_id = job_id | ||
self._job_name = job_name | ||
self._execution_start_time = execution_start_time | ||
self._execution_end_time = execution_end_time | ||
|
||
def as_dataclass(self) -> "JobHistoryCatalogEntry": | ||
return JobHistoryCatalogEntry( | ||
row_id=self._row_id, | ||
job_id=self._job_id, | ||
job_name=self._job_name, | ||
execution_start_time=self._execution_start_time, | ||
execution_end_time=self._execution_end_time, | ||
created_at=self._created_at, | ||
updated_at=self._updated_at, | ||
) |
Oops, something went wrong.