Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Apr 23, 2024
1 parent 0bcef7e commit 593a8e2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class Cache {
for (const cache of Object.values(this.CACHES)){
await cache.commit();
}
setTimeout(()=>this._commit(),10000);
setTimeout(()=>this._commit(),10*60000);
}

async get(name: string): Promise<CacheDisk> {
Expand Down
32 changes: 18 additions & 14 deletions src/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ export default class Job implements _Job {
acceptedBy: "",
timestamp: 0,
};
expireAfter: number;
maxEventDuration: number;
maxExecutionTime: number;
outputFormat: string = "application/json";
nodeId: string = "";
assignedTo: string[] = [];
constructor(
expireAfter: number,
maxEventDuration: number,
runOn: string,
description: string,
input: JobInput[] | undefined,
Expand All @@ -58,9 +59,9 @@ export default class Job implements _Job {
nodeId?: string
) {
this.timestamp = Date.now();
this.expireAfter = expireAfter;
this.expiration = this.timestamp + expireAfter;
this.maxExecutionTime = maxExecutionTime;
this.maxEventDuration = Math.min(maxEventDuration,1000*60*2);
this.expiration = this.timestamp + maxEventDuration;
this.maxExecutionTime = Math.min(maxExecutionTime,1000*60*2);
this.nodeId = nodeId || "";

if (outputFormat) {
Expand Down Expand Up @@ -104,10 +105,10 @@ export default class Job implements _Job {
const runOn: string = Utils.getTagVars(event, ["param", "run-on"])[0][0] || "generic";
const customerPublicKey: string = event.pubkey;
const timestamp: number = Number(event.created_at) * 1000;
const expiration: number = Math.max(
const expiration: number = Math.min(
Number(Utils.getTagVars(event, ["expiration"])[0][0] || "0") * 1000 ||
timestamp + this.expireAfter,
timestamp + this.expireAfter
timestamp + this.maxEventDuration,
timestamp + this.maxEventDuration
);
const nodeId = Utils.getTagVars(event, ["d"])[0][0] || "";

Expand Down Expand Up @@ -233,7 +234,7 @@ export default class Job implements _Job {
}
}

if (state.timestamp < timestamp) {
if(state.status!=JobStatus.SUCCESS){
if (status == "success") {
state.status = JobStatus.SUCCESS;
} else if (status == "processing") {
Expand All @@ -247,14 +248,17 @@ export default class Job implements _Job {
}
state.timestamp = timestamp;
}

} else {
// result
const result = this.result;
if(!this.result.timestamp){
const result = this.result;

if (result.timestamp < timestamp) {
result.content = content;
result.timestamp = timestamp;
result.id = event.id;
if (result.timestamp < timestamp) {
result.content = content;
result.timestamp = timestamp;
result.id = event.id;
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/NostrConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export default class NostrConnector {
secretKey: string,
relays: Array<string>,
filterProvider: ((provider: string) => boolean) | undefined,
maxEventDuration: number = 1000 * 60 * 60,
maxJobExecutionTime: number = 1000 * 60 * 10,
announcementTimeout: number = 1000 * 60 * 10
maxEventDuration: number = 1000 * 60 * 10,
maxJobExecutionTime: number = 1000 * 60 * 5,
announcementTimeout: number = 1000 * 60 * 5
) {
this.jobs = [];
this.customSubscriptions = new Map();
Expand Down Expand Up @@ -347,7 +347,7 @@ export default class NostrConnector {
job.id = id;
this.jobs.push(job);
}
console.log(this.jobs.length, "jobs");
// console.log(this.jobs.length, "jobs");
if (job) {
await this._resolveJobInputs(nodeId, job);
if (!job.areInputsAvailable()) {
Expand Down Expand Up @@ -444,7 +444,7 @@ export default class NostrConnector {
if (kind && !((kind >= 5000 && kind <= 5999) || (kind >= 6000 && kind <= 6999)))
throw new Error("Invalid kind " + kind);
const job = new Job(
expireAfter,
Math.min(expireAfter,this.maxEventDuration),
runOn,
description,
input,
Expand Down
1 change: 1 addition & 0 deletions src/RPCServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ class RpcConnector implements IPoolConnector {
try {
const nodeId = this.getNodeId(context);
const job = await this.getJob(request, context);

if (job && job.state.status == JobStatus.SUCCESS) {
return {
isDone: true,
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function main(){
const PORT = Number(process.env.GRPC_BINDING_PORT || 5000);
const DESCRIPTOR_PATH= process.env.GRPC_PROTO_DESCRIPTOR_PATH || "./docs/descriptor.pb";
const SECRET_KEY = process.env.NOSTR_SECRET_KEY || bytesToHex(generateSecretKey());
const RELAYS = (process.env.NOSTR_RELAYS || "wss://nostr.rblb.it:7777").split(",");
const RELAYS = (process.env.NOSTR_RELAYS || "wss://nostr.rblb.it:7777,wss://openagents.forkforge.net:7777").split(",");
const WEBHOOKS = (process.env.WEBHOOKS || "").split(",");
const PUBLIC_KEY = getPublicKey(hexToBytes(SECRET_KEY));

Expand Down

0 comments on commit 593a8e2

Please sign in to comment.