Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/caw agenda integration #257

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: CI
on: [push, pull_request]
jobs:
test:
name: Node ${{ matrix.node }}, Mongo ${{ matrix.mongodb-version }}, Agenda ${{ matrix.agenda-version }}
name: agendash
runs-on: ubuntu-latest
strategy:
matrix:
node: ['14', '16', '18']
mongodb-version: [ 3.6, 4.0, 4.2, 4.4, 5.0 ]
agenda-version: [ 3.1, 4.0 ]
# agenda-version: [ 3.1, 4.0 ]
steps:
- uses: actions/checkout@v2

Expand All @@ -25,7 +25,7 @@ jobs:
- run: npm install

- name: Install agenda
run: npm i agenda@${{ matrix.agenda-version }}
run: npm i "@cawstudios/agenda"

- run: npm test
env:
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/npm-publish-github-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Node.js Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://npm.pkg.github.com'
scope: '@cawstudios'

- name: Create .npmrc
run: |
echo "@cawstudios:registry=https://npm.pkg.github.com" > .npmrc
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GH_PAT }}" >> .npmrc

- name: Install dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PAT }}

- name: Run tests
run: npm test

publish-gpr:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@cawstudios'

- name: Create .npmrc
run: |
echo "@cawstudios:registry=https://npm.pkg.github.com" > .npmrc
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GH_PAT }}" >> .npmrc

- name: Install dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PAT }}

- name: Publish package
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PAT }}
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@cawstudios:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${MY_NPM_TOKEN}
106 changes: 64 additions & 42 deletions bin/agendash-standalone-fastify.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,83 @@
#!/usr/bin/env node
"use strict";
const Agenda = require("agenda");
const { Agenda, DataSource } = require("@cawstudios/agenda");
const agendash = require("../app");
const { Command } = require("commander");
const Fastify = require("fastify");
const program = require("commander");

const program = new Command();

program
.option(
"-d, --db <db>",
"[required] Mongo connection string, same as Agenda connection string"
)
.option(
"-c, --collection <collection>",
"[optional] Mongo collection, same as Agenda collection name, default agendaJobs",
"agendaJobs"
)
.option(
"-p, --port <port>",
"[optional] Server port, default 3000",
(n, d) => Number(n) || d,
3000
)
.option(
"-t, --title <title>",
"[optional] Page title, default Agendash",
"Agendash"
)
.option(
"-p, --path <path>",
"[optional] Path to bind Agendash to, default /",
"/"
)
.option("-t, --dataSourceType <type>", "Data source type (mongo or postgres)", /^(mongo|postgres)$/i)
.option("-d, --db <connection>", "DB connection string")
.option("-c, --collection <name>", "Mongo collection name", "agendaJobs")
.option("-p, --port <number>", "Server port", parseInt, 3000)
.option("-t, --title <string>", "Page title", "Agendash")
.option("-p, --path <path>", "Path to bind Agendash to", "/")
.parse(process.argv);

if (!program.db) {
const options = program.opts();

// Validation
if (!options.dataSourceType) {
console.error("--dataSourceType required (mongo or postgres)");
process.exit(1);
}

if (!options.db) {
console.error("--db required");
process.exit(1);
}

if (!program.path.startsWith("/")) {
if (!options.path.startsWith("/")) {
console.error("--path must begin with /");
process.exit(1);
}

const fastify = Fastify();
// DB Configuration
const dbConfig = {
[DataSource.POSTGRES]: {
dataSource: DataSource.POSTGRES,
dataSourceOptions: {
db: {
connectionString: options.db
}
}
},
[DataSource.MONGO]: {
dataSource: DataSource.MONGO,
dataSourceOptions: { db: { address: options.db, collection: options.collection } }
}
}[options.dataSourceType];

const agenda = new Agenda().database(program.db, program.collection);
if (!dbConfig) {
console.error("Unsupported data source");
process.exit(1);
}

async function startServer() {
try {
const fastify = Fastify();

const agenda = new Agenda();
await agenda.database(dbConfig);

fastify.register(
agendash(agenda, {
middleware: "fastify",
title: program.title,
})
);
fastify.register(
agendash(agenda, {
middleware: "fastify",
title: program.title,
})
);

fastify.listen({ port: program.port }, function () {
console.log(
`Agendash started http://localhost:${program.port}${program.path}`
);
});
} catch (error) {
console.error("Failed to start Agendash:", error);
process.exit(1);
}
}

fastify.listen({ port: program.port }, function () {
console.log(
`Agendash started http://localhost:${program.port}${program.path}`
);
});
startServer();
70 changes: 46 additions & 24 deletions bin/agendash-standalone-hapi.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,67 @@
#!/usr/bin/env node
"use strict";
const { Agenda } = require("agenda");
const { Agenda, DataSource } = require("@cawstudios/agenda");
const agendash = require("../app");
const Hapi = require("@hapi/hapi");
const program = require("commander");
const { Command } = require("commander");

const program = new Command();
program
.option(
"-d, --db <db>",
"[required] Mongo connection string, same as Agenda connection string"
)
.option(
"-c, --collection <collection>",
"[optional] Mongo collection, same as Agenda collection name, default agendaJobs",
"agendaJobs"
)
.option(
"-p, --port <port>",
"[optional] Server port, default 3000",
(n, d) => Number(n) || d,
3000
)
.option(
"-t, --title <title>",
"[optional] Page title, default Agendash",
"Agendash"
)
.option("-t, --dataSourceType <type>", "Data source type (mongo or postgres)", /^(mongo|postgres)$/i)
.option("-d, --db <connection>", "DB connection string")
.option("-c, --collection <name>", "Mongo collection name", "agendaJobs")
.option("-p, --port <number>", "Server port", parseInt, 3000)
.option("-t, --title <string>", "Page title", "Agendash")
.option("-p, --path <path>", "Path to bind Agendash to", "/")
.parse(process.argv);

if (!program.db) {
const options = program.opts();
// Validation
if (!options.dataSourceType) {
console.error("--dataSourceType required (mongo or postgres)");
process.exit(1);
}

if (!options.db) {
console.error("--db required");
process.exit(1);
}

if (!options.path.startsWith("/")) {
console.error("--path must begin with /");
process.exit(1);
}

// DB Configuration
const dbConfig = {
[DataSource.POSTGRES]: {
dataSource: DataSource.POSTGRES,
dataSourceOptions: {
db: {
connectionString: options.db
}
}
},
[DataSource.MONGO]: {
dataSource: DataSource.MONGO,
dataSourceOptions: { db: { address: options.db, collection: options.collection } }
}
}[options.dataSourceType];

if (!dbConfig) {
console.error("Unsupported data source");
process.exit(1);
}


const init = async () => {
const server = Hapi.server({
port: 3002,
host: "localhost",
});

const agenda = new Agenda().database(program.db, program.collection);
const agenda = new Agenda();
await agenda.database(dbConfig);

await server.register(require("@hapi/inert"));
await server.register(
Expand Down
69 changes: 45 additions & 24 deletions bin/agendash-standalone-koa.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,61 @@
#!/usr/bin/env node
"use strict";
const { Agenda } = require("agenda");
const { Agenda, DataSource } = require("@cawstudios/agenda");
const agendash = require("../app");
const Koa = require("koa");
const program = require("commander");
const { Command } = require("commander");

const program = new Command();
program
.option(
"-d, --db <db>",
"[required] Mongo connection string, same as Agenda connection string"
)
.option(
"-c, --collection <collection>",
"[optional] Mongo collection, same as Agenda collection name, default agendaJobs",
"agendaJobs"
)
.option(
"-p, --port <port>",
"[optional] Server port, default 3000",
(n, d) => Number(n) || d,
3000
)
.option(
"-t, --title <title>",
"[optional] Page title, default Agendash",
"Agendash"
)
.option("-t, --dataSourceType <type>", "Data source type (mongo or postgres)", /^(mongo|postgres)$/i)
.option("-d, --db <connection>", "DB connection string")
.option("-c, --collection <name>", "Mongo collection name", "agendaJobs")
.option("-p, --port <number>", "Server port", parseInt, 3000)
.option("-t, --title <string>", "Page title", "Agendash")
.option("-p, --path <path>", "Path to bind Agendash to", "/")
.parse(process.argv);

if (!program.db) {
const options = program.opts();
// Validation
if (!options.dataSourceType) {
console.error("--dataSourceType required (mongo or postgres)");
process.exit(1);
}

if (!options.db) {
console.error("--db required");
process.exit(1);
}

if (!options.path.startsWith("/")) {
console.error("--path must begin with /");
process.exit(1);
}

// DB Configuration
const dbConfig = {
[DataSource.POSTGRES]: {
dataSource: DataSource.POSTGRES,
dataSourceOptions: {
db: {
connectionString: options.db
}
}
},
[DataSource.MONGO]: {
dataSource: DataSource.MONGO,
dataSourceOptions: { db: { address: options.db, collection: options.collection } }
}
}[options.dataSourceType];

if (!dbConfig) {
console.error("Unsupported data source");
process.exit(1);
}

const init = async () => {
const agenda = new Agenda().database(program.db, program.collection);
const agenda = new Agenda();
await agenda.database(dbConfig);

const app = new Koa();
const middlewares = agendash(agenda, {
Expand Down
Loading