Skip to content

Commit

Permalink
Merge pull request #6 from hyper63/twilson63/feat-connect-mod-to-adap…
Browse files Browse the repository at this point in the history
…ter-5

Twilson63/feat connect mod to adapter 5
  • Loading branch information
twilson63 authored Aug 3, 2021
2 parents 99d4e26 + 2931dcc commit 2408f51
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 8 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Publish

on:
push:
tags:
- "*"

jobs:
publish-egg:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- run: deno install -A -f --unstable --no-check https://x.nest.land/eggs@0.3.6/eggs.ts
- run: |
export PATH="/home/runner/.deno/bin:$PATH"
eggs link ${{ secrets.NESTAPIKEY }}
eggs publish --yes
4 changes: 2 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ image:

tasks:
- command: |
deno cache --lock=deps.js
deno cache --lock=dev_deps.js
deno cache deps.js --lock=deps_lock.json --no-check
deno cache dev_deps.js --lock=dev_deps_lock.json --no-check
github:
prebuilds:
Expand Down
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ This service can provide worker push queues to serverless applications, without
to manage state. This adapter uses an in-memory queue and is designed to work with
local hyper services or services with small workloads.</p>

<p align="center">
<a href="https://nest.land/package/hyper-adapter-queue"><img src="https://nest.land/badge.svg" alt="Nest Badge" /></a>
<a href="https://github.com/hyper63/hyper-adapter-queue/actions/workflows/test.yml"><img src="https://github.com/hyper63/hyper-adapter-queue/actions/workflows/test.yml/badge.svg" alt="Test" /></a>
<a href="https://github.com/hyper63/hyper-adapter-queue/tags/"><img src="https://img.shields.io/github/tag/hyper63/hyper-adapter-queue" alt="Current Version" /></a>
</p>

---

## Table of Contents
Expand All @@ -19,10 +25,77 @@ local hyper services or services with small workloads.</p>

## Getting Started

In order to get started using `hyper-adapter-queue`, you need to setup a hyper instance:

mod.js file:

``` js
import { core } from 'https://x.nest.land/hyper@1.4.2/mod.js'
import config from './hyper.config.js'

core(config)
```

config file:

``` js
import { opine } from "https://x.nest.land/hyper-app-opine@1.2.1/mod.js";
import queue from "https://x.nest.land/hyper-adapter-queue@0.0.1/mod.js";

export default = {
app: opine,
adapters: [
{ port: 'queue', plugins: [queue('/tmp/hyper-queue.db')] },
],
};
```

## Example

// create a queue
``` js
const hyper = 'https://cloud.hyper.io/apps/test/queue/default'
fetch(hyper, {
method: 'PUT',
headers,
body: JSON.stringify({
target: 'https://jsonplaceholder.typicode.com/posts'
})
})
```

// post a job

``` js
const hyper = 'https://cloud.hyper.io/apps/test/queue/default'
fetch(hyper, {
method: 'POST',
headers,
body: JSON.stringify({
hello: 'world'
})
})
```

## Testing

Run Tests...

``` sh
./scripts/test.sh
```

Run Test Harness

``` sh
./scripts/harness.sh
```


## Contributing

Contributions are welcome!

## License

Apache 2.0
23 changes: 23 additions & 0 deletions egg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://x.nest.land/eggs@0.3.8/src/schema.json",
"name": "hyper-adapter-queue",
"entry": "./mod.js",
"description": "Hyper Queue adapter",
"homepage": "https://github.com/hyper63/hyper-adapter-queue",
"repo": "https://github.com/hyper63/hyper-adapter-queue",
"version": "0.0.1",
"unstable": false,
"unlisted": false,
"files": [
"./*"
],
"ignore": [
"./package.json",
"./scripts/*",
"./.git*"
],
"checkFormat": false,
"checkTests": false,
"checkInstallation": false,
"check": false
}
11 changes: 9 additions & 2 deletions mod.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { Datastore } from "./deps.js";
import adapter from "./adapter.js";
import PORT_NAME from "./port_name.js";

export default () => ({
export default (dbFile) => ({
id: "queue",
port: PORT_NAME,
load: () => ({}), // load env
load: () => {
if (!dbFile) {
throw new Error("DB FILE: required for queue adapter");
}
const db = new Datastore({ filename: dbFile, autoload: true });
return { db };
}, // load env
link: (env) => (_) => adapter(env), // link adapter
});
2 changes: 1 addition & 1 deletion scripts/harness.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

deno run --unstable -A ./test/hyper.js
deno run --no-check --unstable -A ./test/hyper.js
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

deno lint
deno fmt --check
deno test -A --unstable --no-check adapter_test.js
deno test -A --unstable --no-check
2 changes: 1 addition & 1 deletion test/adapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assert, validateDataAdapterSchema } from "../dev_deps.js";

import adapterBuilder from "../adapter.js";

const adapter = adapterBuilder();
const adapter = adapterBuilder({db: null});

Deno.test("should implement the port", () => {
assert(validateDataAdapterSchema(adapter));
Expand Down
2 changes: 1 addition & 1 deletion test/hyper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PORT_NAME from "../port_name.js";
const hyperConfig = {
app: appOpine,
adapters: [
{ port: PORT_NAME, plugins: [myAdapter()] },
{ port: PORT_NAME, plugins: [myAdapter('/tmp/hyper-harness.db')] },
],
};

Expand Down

0 comments on commit 2408f51

Please sign in to comment.