Skip to content

Commit

Permalink
fix(feedback): store service id rather than schedule id (#5374)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 authored Oct 29, 2024
1 parent 6b96299 commit 57c7640
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/dispatch/feedback/service/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def send_oncall_shift_feedback_message(
*,
project: Project,
individual: IndividualContact,
schedule_id: str,
service_id: str,
shift_end_at: str,
schedule_name: str,
reminder: Optional[ServiceFeedbackReminder] = None,
Expand Down Expand Up @@ -64,7 +64,7 @@ def send_oncall_shift_feedback_message(
reminder_at=datetime.utcnow() + timedelta(hours=23),
individual_contact_id=individual.id,
project_id=project.id,
schedule_id=schedule_id,
schedule_id=service_id,
schedule_name=schedule_name,
shift_end_at=shift_end_at,
details=[] if details is None else details,
Expand All @@ -75,7 +75,7 @@ def send_oncall_shift_feedback_message(
items = [
{
"individual_name": individual.name,
"oncall_schedule_id": schedule_id,
"oncall_schedule_id": service_id,
"oncall_service_name": schedule_name,
"organization_slug": project.organization.slug,
"project_id": project.id,
Expand Down
19 changes: 11 additions & 8 deletions src/dispatch/feedback/service/scheduled.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import logging
from datetime import datetime

from dispatch.database.core import SessionLocal
from sqlalchemy.orm import Session

from dispatch.decorators import scheduled_project_task, timer
from dispatch.individual import service as individual_service
from dispatch.plugin import service as plugin_service
Expand Down Expand Up @@ -30,20 +31,20 @@
@scheduler.add(every(1).day.at("16:00"), name="oncall-shift-feedback-ucan")
@timer
@scheduled_project_task
def oncall_shift_feedback_ucan(db_session: SessionLocal, project: Project):
def oncall_shift_feedback_ucan(db_session: Session, project: Project):
oncall_shift_feedback(db_session=db_session, project=project, hour=16)
find_expired_reminders_and_send(db_session=db_session, project=project)


@scheduler.add(every(1).day.at("06:00"), name="oncall-shift-feedback-emea")
@timer
@scheduled_project_task
def oncall_shift_feedback_emea(db_session: SessionLocal, project: Project):
def oncall_shift_feedback_emea(db_session: Session, project: Project):
oncall_shift_feedback(db_session=db_session, project=project, hour=6)
find_expired_reminders_and_send(db_session=db_session, project=project)


def find_expired_reminders_and_send(*, db_session: SessionLocal, project: Project):
def find_expired_reminders_and_send(*, db_session: Session, project: Project):
reminders = reminder_service.get_all_expired_reminders_by_project_id(
db_session=db_session, project_id=project.id
)
Expand All @@ -54,7 +55,7 @@ def find_expired_reminders_and_send(*, db_session: SessionLocal, project: Projec
send_oncall_shift_feedback_message(
project=project,
individual=individual,
schedule_id=reminder.schedule_id,
service_id=reminder.schedule_id,
shift_end_at=str(reminder.shift_end_at),
schedule_name=reminder.schedule_name,
reminder=reminder,
Expand All @@ -65,10 +66,11 @@ def find_expired_reminders_and_send(*, db_session: SessionLocal, project: Projec

def find_schedule_and_send(
*,
db_session: SessionLocal,
db_session: Session,
project: Project,
oncall_plugin: PluginInstance,
schedule_id: str,
service_id: str,
hour: int,
):
"""
Expand Down Expand Up @@ -133,15 +135,15 @@ def count_active_participants(participants):
send_oncall_shift_feedback_message(
project=project,
individual=individual,
schedule_id=schedule_id,
service_id=service_id,
shift_end_at=current_oncall["shift_end"],
schedule_name=current_oncall["schedule_name"],
details=details,
db_session=db_session,
)


def oncall_shift_feedback(db_session: SessionLocal, project: Project, hour: int):
def oncall_shift_feedback(db_session: Session, project: Project, hour: int):
"""
Experimental: collects feedback from individuals participating in an oncall service that has health metrics enabled
when their oncall shift ends. For now, only for one project and schedule.
Expand Down Expand Up @@ -174,5 +176,6 @@ def oncall_shift_feedback(db_session: SessionLocal, project: Project, hour: int)
project=project,
oncall_plugin=oncall_plugin,
schedule_id=schedule_id,
service_id=external_id,
hour=hour,
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
<project-combobox v-model="local_project" label="Projects" />
</v-list-item>
<v-list-item>
<service-select v-model="local_service" label="Oncall service" />
<service-select
v-model="local_service"
:health-metrics="true"
:project="local_project"
label="Oncall service"
/>
</v-list-item>
</v-list>
<v-card-actions>
Expand Down
44 changes: 32 additions & 12 deletions src/dispatch/static/dispatch/src/service/ServiceSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
chips
multiple
closable-chips
/>
><template #append-item>
<v-list-item v-if="more" @click="loadMore">
<v-list-item-subtitle>Load More</v-list-item-subtitle>
</v-list-item>
</template>
</v-combobox>
</template>

<script>
import { cloneDeep } from "lodash"
import { debounce } from "lodash"
import SearchUtils from "@/search/utils"
import ServiceApi from "@/service/api"
Expand All @@ -48,9 +53,13 @@ export default {
},
},
project: {
type: [Object],
type: Object,
default: null,
},
healthMetrics: {
type: Boolean,
default: false,
},
},
data() {
Expand All @@ -59,6 +68,9 @@ export default {
search: null,
select: null,
items: [],
more: false,
numItems: 5,
total: 0,
}
},
Expand All @@ -84,30 +96,38 @@ export default {
},
methods: {
fetchData() {
loadMore() {
this.numItems += 5
this.fetchData()
},
fetchData: debounce(function () {
this.error = null
this.loading = "error"
let filterOptions = {
q: this.search,
sortBy: ["name"],
descending: [false],
itemsPerPage: this.numItems,
filters: { is_active: ["true"] },
}
if (this.project) {
filterOptions = {
...filterOptions,
filters: {
project: [this.project],
},
}
filterOptions = SearchUtils.createParametersFromTableOptions({ ...filterOptions })
filterOptions.filters.project_id = this.project.map((p) => p.id)
}
if (this.healthMetrics) {
filterOptions.filters.health_metrics = ["true"]
}
filterOptions = SearchUtils.createParametersFromTableOptions({ ...filterOptions })
ServiceApi.getAll(filterOptions).then((response) => {
this.items = response.data.items
this.total = response.data.total
this.more = this.items.length < this.total
this.loading = false
})
},
}, 300),
},
created() {
this.fetchData()
Expand Down

0 comments on commit 57c7640

Please sign in to comment.