tigawana
deno deploy queues
is there a special flag or setting required for queues in deno deploy , i ceated a very simple example that works locally but not on deploy
app.get('/test', async(c) => {
try {
const env = await load();
const db = await Deno.openKv();
db.listenQueue(async(msg) => {
const data = msg as { channel: string; text: string };
console.log("=== QUEUE MESSAGE === ",data);
await db.set(["test-queues", data.channel], data.text);
});
await db.enqueue({ channel: "C123456", text: "Slack message" }, {
delay: 0,
});
return c.json({
env,
})
} catch (error) {
return c.text("error with queues === "+error.message, 401);
}
})
app.get('/test', async(c) => {
try {
const env = await load();
const db = await Deno.openKv();
db.listenQueue(async(msg) => {
const data = msg as { channel: string; text: string };
console.log("=== QUEUE MESSAGE === ",data);
await db.set(["test-queues", data.channel], data.text);
});
await db.enqueue({ channel: "C123456", text: "Slack message" }, {
delay: 0,
});
return c.json({
env,
})
} catch (error) {
return c.text("error with queues === "+error.message, 401);
}
})
4 replies
Queues in production not working
here's the main queue code , works locally
the rest of the code it is at https://github.com/tigawanna/library-stats
import { getOneRepoPackageJson } from "./getOneRepoLibraries.ts";
import { getGithubViewer } from "./getViewer.ts";
import { Edge } from "./getViewerRepos.ts";
interface EnqueueRepoPackagesCompoutemprops {
repos: Edge[];
viewer_token: string;
}
export async function enqueueRepoPackagesCompute(
{ repos, viewer_token }: EnqueueRepoPackagesCompoutemprops,
) {
try {
const kv = await Deno.openKv();
const viewer = await getGithubViewer(viewer_token);
console.log("-======= enqueueing repos for ====== ", viewer.name);
const enqueueItems = async () => {
for await (const [index, item] of repos.entries()) {
const hundrecth = Math.floor(index / 50);
// const delay = 1000 * 60 * (index + 1);
if ("documentation_url" in item && "message" in item) return;
const delay = Math.max(1, 100 * (index + 1) * (hundrecth + 1));
console.log("=== QUEUE ITEM ==== ", item);
console.log("=== DELAY === ", delay);
await kv.enqueue({ message: "repo_pkgjson_queue", value: item }, {
delay,
});
}
};
await enqueueItems();
kv.listenQueue(async (msg) => {
const data = msg as { message: string; value: Edge };
if (!data.value) {
return;
}
if (!data.message) {
return;
}
if (data.message === "repo_pkgjson_queue") {
console.log("writing data ==== ", data.value);
const pkgjson = await getOneRepoPackageJson(
data.value.node.nameWithOwner,
viewer_token,
);
if (!pkgjson) return;
if ("documentation_url" in pkgjson || "message" in pkgjson) return;
await kv.set([
"repo_pkgjson",
viewer.name,
data.value.node.nameWithOwner,
], pkgjson);
}
return;
});
} catch (error) {
throw error;
}
}
import { getOneRepoPackageJson } from "./getOneRepoLibraries.ts";
import { getGithubViewer } from "./getViewer.ts";
import { Edge } from "./getViewerRepos.ts";
interface EnqueueRepoPackagesCompoutemprops {
repos: Edge[];
viewer_token: string;
}
export async function enqueueRepoPackagesCompute(
{ repos, viewer_token }: EnqueueRepoPackagesCompoutemprops,
) {
try {
const kv = await Deno.openKv();
const viewer = await getGithubViewer(viewer_token);
console.log("-======= enqueueing repos for ====== ", viewer.name);
const enqueueItems = async () => {
for await (const [index, item] of repos.entries()) {
const hundrecth = Math.floor(index / 50);
// const delay = 1000 * 60 * (index + 1);
if ("documentation_url" in item && "message" in item) return;
const delay = Math.max(1, 100 * (index + 1) * (hundrecth + 1));
console.log("=== QUEUE ITEM ==== ", item);
console.log("=== DELAY === ", delay);
await kv.enqueue({ message: "repo_pkgjson_queue", value: item }, {
delay,
});
}
};
await enqueueItems();
kv.listenQueue(async (msg) => {
const data = msg as { message: string; value: Edge };
if (!data.value) {
return;
}
if (!data.message) {
return;
}
if (data.message === "repo_pkgjson_queue") {
console.log("writing data ==== ", data.value);
const pkgjson = await getOneRepoPackageJson(
data.value.node.nameWithOwner,
viewer_token,
);
if (!pkgjson) return;
if ("documentation_url" in pkgjson || "message" in pkgjson) return;
await kv.set([
"repo_pkgjson",
viewer.name,
data.value.node.nameWithOwner,
], pkgjson);
}
return;
});
} catch (error) {
throw error;
}
}
3 replies
Remote KV access error : Missing DENO_KV_ACCESS_TOKEN environment variable
i wen through the recomnded steps of adding a .env to the root of the project and adding
but it's still giving that env not found error
DENO_KV_ACCESS_TOKEN=ddp_an_access_token
DENO_KV_ACCESS_TOKEN=ddp_an_access_token
6 replies
List kv items using a partial key
Hey guys am trying to figure out kv and how to get stuffout of it
how do i get iteme that have the key ["repo_pkgjson",reponame]
example
returns
but this
returns an empty array , waht am i doing wrong?
const repos = await kv.get(["repo_pkgjson","tigawanna/all-emps-web"]);
const repos = await kv.get(["repo_pkgjson","tigawanna/all-emps-web"]);
{
"key": [
"repo_pkgjson",
"tigawanna/all-emps-web"
],
"value": {
"name": "all-emps-vite",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --port 3000",
"build": "tsc && vite build ",
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^4.16.1",
"@tanstack/react-query-devtools": "^4.16.1",
"dayjs": "^1.11.6",
"pocketbase": "^0.8.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.6.0",
"react-intersection-observer": "^9.4.1",
"react-router-dom": "^6.4.3",
"tailwind-scrollbar": "^2.0.1"
},
"devDependencies": {
},
"pkg_type": "React+Vite",
"favdeps": [
"tailwindcss",
"typescript",
"react-router-dom",
"react-icons",
"dayjs",
"pocketbase"
]
},
"versionstamp": "000000000000046d0000"
}
{
"key": [
"repo_pkgjson",
"tigawanna/all-emps-web"
],
"value": {
"name": "all-emps-vite",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --port 3000",
"build": "tsc && vite build ",
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^4.16.1",
"@tanstack/react-query-devtools": "^4.16.1",
"dayjs": "^1.11.6",
"pocketbase": "^0.8.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.6.0",
"react-intersection-observer": "^9.4.1",
"react-router-dom": "^6.4.3",
"tailwind-scrollbar": "^2.0.1"
},
"devDependencies": {
},
"pkg_type": "React+Vite",
"favdeps": [
"tailwindcss",
"typescript",
"react-router-dom",
"react-icons",
"dayjs",
"pocketbase"
]
},
"versionstamp": "000000000000046d0000"
}
const repos = await kv.list({prefix: ["repo_pkgjson"]});
const repos = await kv.list({prefix: ["repo_pkgjson"]});
6 replies