Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDESK-7461] - Assignment Delivery async resource & service #2157

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions server/planning/assignments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
from .delivery import DeliveryResource

from .service import AssignmentsAsyncService
from .module import assignments_resource_config
from .delivery_service import DeliveryAsyncService
from .module import assignments_resource_config, delivery_resource_config

__all__ = ["assignments_resource_config", "AssignmentsAsyncService"]
__all__ = ["assignments_resource_config", "AssignmentsAsyncService", "delivery_resource_config", "DeliveryAsyncService"]


def init_app(app):
Expand Down
6 changes: 6 additions & 0 deletions server/planning/assignments/delivery_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from planning.core.service import BasePlanningAsyncService
from planning.types import DeliveryResourceModel


class DeliveryAsyncService(BasePlanningAsyncService[DeliveryResourceModel]):
pass
34 changes: 33 additions & 1 deletion server/planning/assignments/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
ElasticResourceConfig,
)

from planning.types import AssignmentResourceModel
from planning.types import AssignmentResourceModel, DeliveryResourceModel
from .service import AssignmentsAsyncService
from .delivery_service import DeliveryAsyncService

assignments_resource_config = ResourceConfig(
name="assignments",
Expand Down Expand Up @@ -34,3 +35,34 @@
),
elastic=ElasticResourceConfig(),
)

delivery_resource_config = ResourceConfig(
name="delivery",
data_class=DeliveryResourceModel,
service=DeliveryAsyncService,
mongo=MongoResourceConfig(
indexes=[
MongoIndexOptions(
name="planning_id_1",
keys=[("planning_id", 1)],
background=True,
BrianMwangi21 marked this conversation as resolved.
Show resolved Hide resolved
),
MongoIndexOptions(
name="assignment_id_1",
keys=[("assignment_id", 1)],
background=True,
),
MongoIndexOptions(
name="coverage_id_1",
keys=[("coverage_id", 1)],
background=True,
),
MongoIndexOptions(
name="item_id_1",
keys=[("item_id", 1)],
background=True,
),
],
),
elastic=ElasticResourceConfig(),
BrianMwangi21 marked this conversation as resolved.
Show resolved Hide resolved
)
3 changes: 2 additions & 1 deletion server/planning/module.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from superdesk.core.module import Module
from planning.events import events_resource_config
from planning.planning import planning_resource_config
from planning.assignments import assignments_resource_config
from planning.assignments import assignments_resource_config, delivery_resource_config
from planning.published import published_resource_config


Expand All @@ -12,5 +12,6 @@
planning_resource_config,
assignments_resource_config,
published_resource_config,
delivery_resource_config,
],
)
2 changes: 2 additions & 0 deletions server/planning/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from .base import BasePlanningModel
from .common import PlanningSchedule
from .delivery import DeliveryResourceModel
from .event import EventResourceModel
from .planning import PlanningResourceModel
from .assignment import AssignmentResourceModel
Expand All @@ -24,6 +25,7 @@

__all__ = [
"BasePlanningModel",
"DeliveryResourceModel",
"EventResourceModel",
"PlanningResourceModel",
"AssignmentResourceModel",
Expand Down
18 changes: 18 additions & 0 deletions server/planning/types/delivery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from pydantic import Field
from typing import Annotated
from datetime import datetime

from superdesk.core.resources import fields
from superdesk.core.resources.validators import validate_data_relation_async
from .base import BasePlanningModel


class DeliveryResourceModel(BasePlanningModel):
BrianMwangi21 marked this conversation as resolved.
Show resolved Hide resolved
planning_id: Annotated[fields.Keyword, validate_data_relation_async("planning")]
coverage_id: str | None = None
assignment_id: Annotated[fields.ObjectId, validate_data_relation_async("assignments")]
item_id: str | None = None
item_state: str | None = None
sequence_no: int = Field(default=0)
publish_time: datetime | None = None
scheduled_update_id: str | None = None
Loading