This commit is contained in:
tree 2023-07-12 16:42:35 +00:00
rodič 36292e9eda
revize 24f6e61dd6
5 změnil soubory, kde provedl 108 přidání a 3 odebrání

Zobrazit soubor

@ -12,4 +12,12 @@ INFLUXDB_TOKEN=XXXX
INFLUXDB_ORG=XXXX
INFLUXDB_BUCKET=XXXX
TYPESENSE_HOST=http://localhost:8108
TYPESENSE_API_KEY=XXXXX
TYPESENSE_API_KEY=XXXXX
ATSCAN_TICK_SANDBOX_HANDLE=tick-sandbox.atscan.net
ATSCAN_TICK_SANDBOX_PASSWORD=XXXXXX
ATSCAN_TICK_BLUESKY_HANDLE=tick.bsky.social
ATSCAN_TICK_BLUESKY_PASSWORD=XXXXXX
ATSCAN_TICK_BLUESKY_PDS=bsky.social
ATSCAN_TICK_BLUESKY_REPO=did:plc:kwmcvt4maab47n7dgvepg4tr
ATSACN_TICK_BLUESKY_POST=3k2djecjpk22c
ATSCAN_TICK_BLUESKY_INTERVAL=5000

Zobrazit soubor

@ -12,7 +12,7 @@ plc-crawl:
deno run --unstable --allow-net --allow-read --allow-env --allow-sys ./backend/plc-crawler.js
index:
deno run --unstable --allow-net --allow-read --allow-env --allow-sys ./backend/indexer.js
deno run --unstable --allow-net --allow-read --allow-env --allow-sys --allow-ffi ./backend/indexer.js
index-daemon:
deno run --unstable --allow-net --allow-read --allow-env --allow-sys ./backend/indexer.js daemon
@ -29,6 +29,9 @@ repo-worker:
firehose:
deno run --unstable --allow-net --allow-read --allow-env --allow-sys --allow-ffi ./backend/firehose.js
tick:
deno run --unstable --allow-net --allow-read --allow-env ./backend/tick.js
fe-rebuild:
cd frontend && npm run build
rm -rf frontend/prod-build

29
backend/lib/interval.js Normal file
Zobrazit soubor

@ -0,0 +1,29 @@
export function Interval(fn, duration, ...args) {
const _this = this;
this.baseline = undefined;
this.run = function (flag) {
if (_this.baseline === undefined) {
_this.baseline = performance.now() - duration;
}
if (flag) {
fn(...args);
}
const end = performance.now();
_this.baseline += duration;
let nextTick = duration - (end - _this.baseline);
if (nextTick < 0) {
nextTick = 0;
}
//console.log(nextTick);
_this.timer = setTimeout(function () {
_this.run(true);
}, nextTick);
};
this.stop = function () {
clearTimeout(_this.timer);
};
}

52
backend/tick.js Normal file
Zobrazit soubor

@ -0,0 +1,52 @@
import * as atprotoApi from "npm:@atproto/api";
import "https://deno.land/std@0.193.0/dotenv/load.ts";
import { Interval } from "./lib/interval.js";
const ENV = Deno.env.get("ATSCAN_TICK_ENV") || "SANDBOX";
const options = {
identifier: Deno.env.get(`ATSCAN_TICK_${ENV}_HANDLE`),
password: Deno.env.get(`ATSCAN_TICK_${ENV}_PASSWORD`),
};
const TICK_INTERVAL = parseInt(
Deno.env.get(`ATSCAN_TICK_${ENV}_INTERVAL`) || 1000,
);
const TICK_PDS = Deno.env.get(`ATSCAN_TICK_${ENV}_PDS`) || "test-pds.gwei.cz";
const TICK_REPO = Deno.env.get(`ATSCAN_TICK_${ENV}_REPO`) ||
"did:plc:pzovq4a22hpji6pfzofgk7gc";
//const TICK_POST = Deno.env.get(`ATSCAN_TICK_${ENV}_POST`) || '3k2bwjgozws2q';
const agent = new atprotoApi.default.BskyAgent({
service: `https://${TICK_PDS}`,
});
await agent.login(options);
console.log(`Logged in as "${options.identifier}" [pds=${TICK_PDS}] ...`);
console.log(`Ticking in interval: ${TICK_INTERVAL}ms ..`);
const repo = TICK_REPO;
//const rkey = TICK_POST;
/*const resp = await agent.getTimeline({ limit: 100 });
for (const { post } of resp.data.feed) {
if (post.author.did === repo) {
await agent.deletePost(post.uri)
}
}*/
const interval = new Interval(async () => {
const time = (new Date()).toISOString();
await agent.com.atproto.repo.createRecord({
repo,
collection: "app.bsky.feed.post",
//rkey,
record: {
$type: "app.bsky.feed.post",
text: time,
createdAt: time,
},
});
/*await agent.app.bsky.feed.post.delete({
repo,
rkey,
})*/
}, TICK_INTERVAL);
interval.run();

Zobrazit soubor

@ -68,7 +68,20 @@ module.exports = {
script: "./backend/repo-worker.js",
interpreter: "mullvad-exclude",
interpreterArgs: "deno run --unstable --allow-net --allow-read --allow-write --allow-env --allow-ffi --allow-sys ./backend/repo-worker.js",
instances: 4,
instances: 6,
}, {
name: "atscan-tick-sandbox",
script: "./backend/tick.js",
interpreter: "deno",
interpreterArgs: "run --unstable --allow-net --allow-read --allow-env"
}, {
name: "atscan-tick-bluesky",
script: "./backend/tick.js",
interpreter: "deno",
interpreterArgs: "run --unstable --allow-net --allow-read --allow-env",
env: {
ATSCAN_TICK_ENV: 'BLUESKY'
}
}, {
name: "bull-ui",
script: "index.js",