Skip to content

Commit 82c9a82

Browse files
chore(firestore-counter): use handlers
1 parent a0cf7cc commit 82c9a82

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

firestore-counter/functions/src/index.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,17 @@ export const controllerCore = functions.handler.pubsub.topic.onPublish(
5656
/**
5757
* Backwards compatible HTTPS function
5858
*/
59-
export const controller = functions.https.onRequest(async (req, res) => {
60-
if (!pubsub) {
61-
pubsub = new PubSub();
59+
export const controller = functions.handler.https.onRequest(
60+
async (req, res) => {
61+
if (!pubsub) {
62+
pubsub = new PubSub();
63+
}
64+
await pubsub
65+
.topic(process.env.EXT_INSTANCE_ID)
66+
.publish(Buffer.from(JSON.stringify({})));
67+
res.status(200).send("Ok");
6268
}
63-
await pubsub
64-
.topic(process.env.EXT_INSTANCE_ID)
65-
.publish(Buffer.from(JSON.stringify({})));
66-
res.status(200).send("Ok");
67-
});
69+
);
6870

6971
/**
7072
* Worker is responsible for aggregation of a defined range of shards. It is controlled
@@ -74,10 +76,8 @@ export const controller = functions.https.onRequest(async (req, res) => {
7476
* ControllerCore is monitoring these metadata documents to detect overload that requires
7577
* resharding and to detect failed workers that need poking.
7678
*/
77-
export const worker = functions.firestore
78-
.document(
79-
process.env.INTERNAL_STATE_PATH + WORKERS_COLLECTION_ID + "/{workerId}"
80-
)
79+
export const worker = functions.handler.firestore
80+
.document
8181
.onWrite(async (change, context) => {
8282
// stop worker if document got deleted
8383
if (!change.after.exists) return;
@@ -91,8 +91,8 @@ export const worker = functions.firestore
9191
* limited to one concurrent run at the time. This helps reduce latency for workloads
9292
* that are below the threshold for workers.
9393
*/
94-
export const onWrite = functions.firestore
95-
.document("/{collection}/{**}/_counter_shards_/{shardId}")
94+
export const onWrite = functions.handler.firestore
95+
.document
9696
.onWrite(async (change, context) => {
9797
const metadocRef = firestore.doc(process.env.INTERNAL_STATE_PATH);
9898
const controller = new ShardedCounterController(

0 commit comments

Comments
 (0)