Skip to content

Commit

Permalink
global: add tasks endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wgresshoff authored and slint committed May 13, 2024
1 parent be7174e commit c7e82bc
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 7 deletions.
14 changes: 12 additions & 2 deletions invenio_jobs/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
from invenio_i18n import gettext as _

from . import config
from .resources import JobsResource, JobsResourceConfig
from .services import JobsService, JobsServiceConfig
from .resources import (
JobsResource,
JobsResourceConfig,
TasksResource,
TasksResourceConfig,
)
from .services import JobsService, JobsServiceConfig, TasksService, TasksServiceConfig


class InvenioJobs:
Expand All @@ -38,10 +43,14 @@ def init_config(self, app):
def init_services(self, app):
"""Initialize services."""
self.service = JobsService(JobsServiceConfig.build(app))
self.tasks_service = TasksService(TasksServiceConfig.build(app))

def init_resource(self, app):
"""Initialize resources."""
self.jobs_resource = JobsResource(JobsResourceConfig.build(app), self.service)
self.tasks_resource = TasksResource(
TasksResourceConfig.build(app), self.tasks_service
)


def finalize_app(app):
Expand All @@ -51,3 +60,4 @@ def finalize_app(app):

# services
rr_ext.registry.register(ext.service, service_id="jobs")
rr_ext.registry.register(ext.tasks_service, service_id="tasks")
6 changes: 4 additions & 2 deletions invenio_jobs/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

"""Jobs resources."""

from .config import JobsResourceConfig
from .resources import JobsResource
from .config import JobsResourceConfig, TasksResourceConfig
from .resources import JobsResource, TasksResource

__all__ = (
"JobsResource",
"JobsResourceConfig",
"TasksResource",
"TasksResourceConfig",
)
6 changes: 4 additions & 2 deletions invenio_jobs/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

"""Services."""

from .config import JobsServiceConfig
from .config import JobsServiceConfig, TasksServiceConfig
from .schema import JobSchema
from .services import JobsService
from .services import JobsService, TasksService

__all__ = (
"JobSchema",
"JobsService",
"JobsServiceConfig",
"TasksService",
"TasksServiceConfig",
)
16 changes: 15 additions & 1 deletion invenio_jobs/services/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,24 @@

from ..models import Job, Run
from .links import JobLink
from .permissions import JobPermissionPolicy
from .permissions import JobPermissionPolicy, TasksPermissionPolicy
from .schema import JobSchema


class TasksServiceConfig(ServiceConfig, ConfiguratorMixin):
"""TaskService factory configuration."""

# Common configuration
service_id = "tasks"
permission_policy_cls = TasksPermissionPolicy

result_list_cls = RecordList

links_item = {
"self": JobLink("{+api}/tasks"),
}


class JobSearchOptions(SearchOptionsBase):
"""Job search options."""

Expand Down
10 changes: 10 additions & 0 deletions invenio_jobs/services/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
from invenio_records_permissions.policies import BasePermissionPolicy


class TasksPermissionPolicy(BasePermissionPolicy):
"""Access control configuration for tasks."""

can_search = [Administration()]
can_create = [Administration()]
can_read = [Administration()]
can_update = [Administration()]
can_delete = [Administration()]


class JobPermissionPolicy(BasePermissionPolicy):
"""Access control configuration for jobs."""

Expand Down
8 changes: 8 additions & 0 deletions invenio_jobs/services/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
from invenio_records_resources.services.uow import unit_of_work


class TasksService(RecordService):
"""Tasks service."""

def search(self, identity, **kwargs):
"""Search for jobs."""
raise NotImplementedError()


class JobsService(RecordService):
"""Jobs service."""

Expand Down
6 changes: 6 additions & 0 deletions invenio_jobs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ def create_jobs_bp(app):
"""Create jobs blueprint."""
ext = app.extensions["invenio-jobs"]
return ext.jobs_resource.as_blueprint()


def create_tasks_bp(app):
"""Create tasks blueprint."""
ext = app.extensions["invenio-jobs"]
return ext.tasks_resource.as_blueprint()
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ invenio_base.api_apps =
jobs = invenio_jobs:InvenioJobs
invenio_base.api_blueprints =
jobs = invenio_jobs.views:create_jobs_bp
tasks = invenio_jobs.views:create_tasks_bp
invenio_base.finalize_app =
jobs = invenio_jobs.ext:finalize_app
invenio_base.api_finalize_app =
Expand Down

0 comments on commit c7e82bc

Please sign in to comment.