feat(follow-location): init
All checks were successful
/ build (map[dockerfile:./services/watchers/Dockerfile name:watchers]) (push) Successful in 2m23s
/ build (map[dockerfile:./services/hasura/Dockerfile name:hasura]) (push) Successful in 1m10s
/ build (map[dockerfile:./services/app/Dockerfile name:app]) (push) Successful in 1m0s
/ build (map[dockerfile:./services/web/Dockerfile name:web]) (push) Successful in 1m27s
/ build (map[dockerfile:./services/files/Dockerfile name:files]) (push) Successful in 2m40s
/ build (map[dockerfile:./services/tasks/Dockerfile name:tasks]) (push) Successful in 2m33s
/ build (map[dockerfile:./services/api/Dockerfile name:api]) (push) Successful in 2m50s
/ deploy (push) Successful in 15s
All checks were successful
/ build (map[dockerfile:./services/watchers/Dockerfile name:watchers]) (push) Successful in 2m23s
/ build (map[dockerfile:./services/hasura/Dockerfile name:hasura]) (push) Successful in 1m10s
/ build (map[dockerfile:./services/app/Dockerfile name:app]) (push) Successful in 1m0s
/ build (map[dockerfile:./services/web/Dockerfile name:web]) (push) Successful in 1m27s
/ build (map[dockerfile:./services/files/Dockerfile name:files]) (push) Successful in 2m40s
/ build (map[dockerfile:./services/tasks/Dockerfile name:tasks]) (push) Successful in 2m33s
/ build (map[dockerfile:./services/api/Dockerfile name:api]) (push) Successful in 2m50s
/ deploy (push) Successful in 15s
This commit is contained in:
parent
85bc0683a8
commit
91d3258533
10 changed files with 93 additions and 2 deletions
|
@ -30,6 +30,7 @@ module.exports = function () {
|
||||||
callEmergency,
|
callEmergency,
|
||||||
notifyAround,
|
notifyAround,
|
||||||
notifyRelatives,
|
notifyRelatives,
|
||||||
|
followLocation,
|
||||||
level,
|
level,
|
||||||
subject,
|
subject,
|
||||||
accuracy,
|
accuracy,
|
||||||
|
@ -54,8 +55,8 @@ module.exports = function () {
|
||||||
let alertId
|
let alertId
|
||||||
await sql.begin(async () => {
|
await sql.begin(async () => {
|
||||||
const [{ id }] = await sql`
|
const [{ id }] = await sql`
|
||||||
INSERT INTO "alert" ("uuid", "device_id", "user_id", "call_emergency", "notify_around", "notify_relatives", "level", "subject", "location", "accuracy", "altitude", "altitude_accuracy", "heading", "speed", "code", "access_code")
|
INSERT INTO "alert" ("uuid", "device_id", "user_id", "call_emergency", "notify_around", "notify_relatives", "follow_location", "level", "subject", "location", "initial_location", "accuracy", "altitude", "altitude_accuracy", "heading", "speed", "code", "access_code")
|
||||||
VALUES (${uuid}, ${deviceId}, ${userId}, ${callEmergency}, ${notifyAround}, ${notifyRelatives}, ${level}, ${subject}, ST_GeomFromGeoJSON (${locationJSON}), ${accuracy}, ${altitude}, ${altitudeAccuracy}, ${heading}, ${speed}, ${code}, ${accessCode})
|
VALUES (${uuid}, ${deviceId}, ${userId}, ${callEmergency}, ${notifyAround}, ${notifyRelatives}, ${followLocation}, ${level}, ${subject}, ST_GeomFromGeoJSON (${locationJSON}), ST_GeomFromGeoJSON (${locationJSON}), ${accuracy}, ${altitude}, ${altitudeAccuracy}, ${heading}, ${speed}, ${code}, ${accessCode})
|
||||||
ON CONFLICT ("uuid")
|
ON CONFLICT ("uuid")
|
||||||
DO UPDATE SET
|
DO UPDATE SET
|
||||||
"uuid" = EXCLUDED. "uuid"
|
"uuid" = EXCLUDED. "uuid"
|
||||||
|
|
|
@ -14,6 +14,8 @@ requestBody:
|
||||||
type: boolean
|
type: boolean
|
||||||
notifyRelatives:
|
notifyRelatives:
|
||||||
type: boolean
|
type: boolean
|
||||||
|
followLocation:
|
||||||
|
type: boolean
|
||||||
uuid:
|
uuid:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
|
|
|
@ -33,6 +33,12 @@ configuration:
|
||||||
custom_name: deviceId
|
custom_name: deviceId
|
||||||
emergency_calling_notification_sent:
|
emergency_calling_notification_sent:
|
||||||
custom_name: emergencyCallingNotificationSent
|
custom_name: emergencyCallingNotificationSent
|
||||||
|
follow_location:
|
||||||
|
custom_name: followLocation
|
||||||
|
follow_location_ran:
|
||||||
|
custom_name: followLocationRan
|
||||||
|
initial_location:
|
||||||
|
custom_name: initialLocation
|
||||||
keep_open_at:
|
keep_open_at:
|
||||||
custom_name: keepOpenAt
|
custom_name: keepOpenAt
|
||||||
nearest_place:
|
nearest_place:
|
||||||
|
@ -71,6 +77,9 @@ configuration:
|
||||||
created_at: createdAt
|
created_at: createdAt
|
||||||
device_id: deviceId
|
device_id: deviceId
|
||||||
emergency_calling_notification_sent: emergencyCallingNotificationSent
|
emergency_calling_notification_sent: emergencyCallingNotificationSent
|
||||||
|
follow_location: followLocation
|
||||||
|
follow_location_ran: followLocationRan
|
||||||
|
initial_location: initialLocation
|
||||||
keep_open_at: keepOpenAt
|
keep_open_at: keepOpenAt
|
||||||
nearest_place: nearestPlace
|
nearest_place: nearestPlace
|
||||||
notified_count: notifiedCount
|
notified_count: notifiedCount
|
||||||
|
@ -128,8 +137,11 @@ select_permissions:
|
||||||
- closed_at
|
- closed_at
|
||||||
- code
|
- code
|
||||||
- created_at
|
- created_at
|
||||||
|
- follow_location
|
||||||
|
- follow_location_ran
|
||||||
- heading
|
- heading
|
||||||
- id
|
- id
|
||||||
|
- initial_location
|
||||||
- keep_open_at
|
- keep_open_at
|
||||||
- level
|
- level
|
||||||
- location
|
- location
|
||||||
|
@ -166,8 +178,11 @@ select_permissions:
|
||||||
- closed_at
|
- closed_at
|
||||||
- code
|
- code
|
||||||
- created_at
|
- created_at
|
||||||
|
- follow_location
|
||||||
|
- follow_location_ran
|
||||||
- heading
|
- heading
|
||||||
- id
|
- id
|
||||||
|
- initial_location
|
||||||
- keep_open_at
|
- keep_open_at
|
||||||
- level
|
- level
|
||||||
- location
|
- location
|
||||||
|
@ -193,6 +208,7 @@ update_permissions:
|
||||||
permission:
|
permission:
|
||||||
columns:
|
columns:
|
||||||
- alert_tag
|
- alert_tag
|
||||||
|
- follow_location
|
||||||
- level
|
- level
|
||||||
- subject
|
- subject
|
||||||
filter:
|
filter:
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
-- Could not auto-generate a down migration.
|
||||||
|
-- Please write an appropriate down migration for the SQL below:
|
||||||
|
-- alter table "public"."alert" add column "initial_location" geography
|
||||||
|
-- null;
|
|
@ -0,0 +1,2 @@
|
||||||
|
alter table "public"."alert" add column "initial_location" geography
|
||||||
|
null;
|
|
@ -0,0 +1,4 @@
|
||||||
|
-- Could not auto-generate a down migration.
|
||||||
|
-- Please write an appropriate down migration for the SQL below:
|
||||||
|
-- alter table "public"."alert" add column "follow_location" boolean
|
||||||
|
-- not null default 'false';
|
|
@ -0,0 +1,2 @@
|
||||||
|
alter table "public"."alert" add column "follow_location" boolean
|
||||||
|
not null default 'false';
|
|
@ -0,0 +1,4 @@
|
||||||
|
-- Could not auto-generate a down migration.
|
||||||
|
-- Please write an appropriate down migration for the SQL below:
|
||||||
|
-- alter table "public"."alert" add column "follow_location_ran" boolean
|
||||||
|
-- not null default 'false';
|
|
@ -0,0 +1,2 @@
|
||||||
|
alter table "public"."alert" add column "follow_location_ran" boolean
|
||||||
|
not null default 'false';
|
|
@ -0,0 +1,54 @@
|
||||||
|
const async = require("async")
|
||||||
|
|
||||||
|
const { gql } = require("@apollo/client/core")
|
||||||
|
const { ctx } = require("@modjo/core")
|
||||||
|
// const watcherCtx = require("modjo-plugins/core/ctx/watcher")
|
||||||
|
// const tasks = require("~/tasks")
|
||||||
|
|
||||||
|
const ALERT_FOLLOW_LOCATION_SUBSCRIPTION = gql`
|
||||||
|
subscription onAlertFollowLocation($limit: Int) {
|
||||||
|
selectManyAlert(
|
||||||
|
where: { _and: { state: { _eq: "open" }, followLocation: { _eq: true } } }
|
||||||
|
limit: $limit
|
||||||
|
order_by: { id: asc }
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
module.exports = async function () {
|
||||||
|
const logger = ctx.require("logger")
|
||||||
|
const apolloClient = ctx.require("apolloClient")
|
||||||
|
// const { addTask } = ctx.require("amqp")
|
||||||
|
|
||||||
|
// const QUEUE_BATCH_SIZE = null
|
||||||
|
const QUEUE_BATCH_SIZE = 1000
|
||||||
|
|
||||||
|
return async function alertTableFollowLocation() {
|
||||||
|
logger.info("watcher alertTableFollowLocation: daemon started")
|
||||||
|
|
||||||
|
const observable = apolloClient.subscribe({
|
||||||
|
query: ALERT_FOLLOW_LOCATION_SUBSCRIPTION,
|
||||||
|
variables: {
|
||||||
|
limit: QUEUE_BATCH_SIZE,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
observable.subscribe({
|
||||||
|
next: async ({ data }) => {
|
||||||
|
const { selectManyAlert } = data
|
||||||
|
await async.eachOf(selectManyAlert, async ({ id: _id }) => {
|
||||||
|
// TODO
|
||||||
|
})
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
logger.error(
|
||||||
|
{ error, watcher: "alertTableFollowLocation" },
|
||||||
|
`subscription error`
|
||||||
|
)
|
||||||
|
throw error
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue