Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/01-hello-world/hello-job.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable no-console */

import { Job } from "sidequest";

export class HelloJob extends Job {
run(name: string) {
const msg = `hello ${name}`;
console.log(msg);
return msg;
}
}
6 changes: 6 additions & 0 deletions examples/01-hello-world/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Sidequest } from "sidequest";
import { HelloJob } from "./hello-job.js";

await Sidequest.start();

await Sidequest.build(HelloJob).enqueue("Jhon");
7 changes: 7 additions & 0 deletions examples/02-recurring-job/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Sidequest } from "sidequest";
import { SampleJob } from "./sample-job.js";

await Sidequest.start();

// every 10 minutes
await Sidequest.build(SampleJob).schedule("*/10 * * * * *");
11 changes: 11 additions & 0 deletions examples/02-recurring-job/sample-job.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable no-console */

import { Job } from "sidequest";

export class SampleJob extends Job {
run() {
const msg = "sample job";
console.log(msg);
return msg;
}
}
6 changes: 6 additions & 0 deletions examples/03-snooze-job/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Sidequest } from "sidequest";
import { SnoozeJob } from "./snooze-job.js";

await Sidequest.start();

await Sidequest.build(SnoozeJob).enqueue();
8 changes: 8 additions & 0 deletions examples/03-snooze-job/snooze-job.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Job } from "sidequest";

export class SnoozeJob extends Job {
run() {
// Pauses the job for 10 seconds before retrying — can be used to wait for external conditions.
return this.snooze(10_000);
}
}
20 changes: 20 additions & 0 deletions examples/04-enqueue-job-from-api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable no-console */

import { Sidequest } from "sidequest";

import express from "express";
import { SendEmailJob } from "./send-email-job.js";

const app = express();

app.get("/send-email", (req, res) => {
const email = req.query.email ?? "[email protected]";
void Sidequest.build(SendEmailJob).enqueue(email as string);
res.send(204);
});

await Sidequest.start();

app.listen(3000, () => {
console.log("call http://localhost:3000/[email protected]");
});
11 changes: 11 additions & 0 deletions examples/04-enqueue-job-from-api/send-email-job.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable no-console */

import { Job } from "sidequest";

export class SendEmailJob extends Job {
run(email: string) {
const msg = `sending email to ${email}`;
console.log(msg);
return msg;
}
}
20 changes: 20 additions & 0 deletions examples/05-web-scrapping/count-word-job.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable no-console */

import { load } from "cheerio";
import { Job } from "sidequest";

export class CountWordJob extends Job {
async run(url: string, word: string) {
const response = await fetch(url);
const html = await response.text();

const $ = load(html);
const text = $("body").text();

const regex = new RegExp(`\\b${word}\\b`, "gi");
const matches = text.match(regex);
const count = matches ? matches.length : 0;

console.log(`The word "${word}" appears ${count} times on the page ${url}`);
}
}
6 changes: 6 additions & 0 deletions examples/05-web-scrapping/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Sidequest } from "sidequest";
import { CountWordJob } from "./count-word-job.js";

await Sidequest.start();

await Sidequest.build(CountWordJob).enqueue("https://en.wikipedia.org/wiki/Node.js", "package");
18 changes: 18 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "examples",
"version": "1.0.0",
"type": "module",
"private": true,
"scripts": {
"build": "tsc"
},
"dependencies": {
"cheerio": "^1.1.2",
"express": "^5.1.0",
"sidequest": "workspace:*"
},
"devDependencies": {
"@types/express": "^5",
"typescript": "^5.8.3"
}
}
20 changes: 20 additions & 0 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ES2022"],
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"outDir": "dist",
"rootDir": ".",
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true
},
"include": ["."],
"exclude": ["dist", "node_modules"]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"workspaces": [
"packages/*",
"packages/backends/*"
"packages/backends/*",
"examples"
],
"scripts": {
"build": "cross-env NODE_ENV=production turbo run build",
Expand Down
Loading
Loading