exit redis client after exit
Some checks failed
Build and push image for doorman / docker (push) Failing after 24s

This commit is contained in:
Martin Dimitrov 2024-05-03 16:08:53 -07:00
parent 79b03574ff
commit 9f5a9be29e
4 changed files with 22 additions and 25 deletions

View File

@ -17,9 +17,9 @@ jobs:
- name: Login and Push Docker image
run: echo -n '${{ secrets.PASSWORD }}' | docker login gitea.chromart.dedyn.io --username ${{ secrets.USERNAME }} --password-stdin && docker image push --all-tags gitea.chromart.dedyn.io/martin/doorman
deploy-portainer:
needs: docker
runs-on: ubuntu-22.04
steps:
- name: Call Portainer stack webhook
run: curl --request POST http://192.168.1.150:9000/api/stacks/webhooks/42b3ae11-45bb-4021-b274-bedcb1250892
# deploy-portainer:
# needs: docker
# runs-on: ubuntu-22.04
# steps:
# - name: Call Portainer stack webhook
# run: curl --request POST http://192.168.1.150:9000/api/stacks/webhooks/42b3ae11-45bb-4021-b274-bedcb1250892

View File

@ -23,29 +23,29 @@ exports.handler = function(context, event, callback) {
return callback(null, response);
}
door = door.toUpperCase();
if (!context['FIXED_PIN_' + door]) {
if (!context['FIXED_PIN_' + door.toUpperCase()]) {
response.setStatusCode(404);
return callback(null, response);
}
let correctPin = context['FIXED_PIN' + door];
let correctPin = context['FIXED_PIN_' + door.toUpperCase()];
if (correctPin !== pin) {
response.setStatusCode(401);
return callback(null, response);
}
let client = new redis.RedisDbClient((err) => console.error(err), { url: context.REDIS_CONNECT_URL });
let client = redis.createClient({ url: context.REDIS_CONNECT_URL });
client.connect()
.then(async () => {
const statusKey = doorStatusKey(door);
const fingerprint = { method: "PIN" };
const timeout = context['OPEN_TIMEOUT_' + door] || 60;
const timeout = context['OPEN_TIMEOUT_' + door.toUpperCase()] || 60;
await client.set(statusKey, JSON.stringify(fingerprint));
await client.expire(statusKey, timeout);
await client.quit();
await client.put(statusKey, JSON.stringify(fingerprint));
await client.getClient().expire(statusKey, timeout);
response
.setStatusCode(200)
.appendHeader('Content-Type', 'application/json')

View File

@ -22,22 +22,18 @@ exports.handler = function(context, event, callback) {
return callback(null, response);
}
door = door.toUpperCase();
const timeout = context['OPEN_TIMEOUT_' + door.toUpperCase()] || 60;
const timeout = context['OPEN_TIMEOUT_' + door] || 60;
res.status(200).json();
let client = new RedisDbClient((err) => console.error(err), { url: context.REDIS_CONNECT_URL });
let client = redis.createClient({ url: context.REDIS_CONNECT_URL });
client.connect()
.then(async () => {
const status = await client.get(doorStatusKey(door)) ? "OPEN": "CLOSED";
await client.quit();
response
.setStatusCode(200)
.appendHeader('Content-Type', 'application/json')
.setBody({ id: doorId, timeout, status });
.setBody({ id: door, timeout, status });
return callback(null, response);
});

View File

@ -22,7 +22,7 @@ exports.handler = function(context, event, callback) {
return callback(null, response);
}
let client = new RedisDbClient((err) => console.error(err), { url: context.REDIS_CONNECT_URL });
let client = redis.createClient({ url: context.REDIS_CONNECT_URL });
client.connect()
.then(async () => {
const isOpen = await client.get(doorStatusKey(door));
@ -37,7 +37,8 @@ exports.handler = function(context, event, callback) {
status: "OPEN",
fingerprint,
});
await client.remove(doorStatusKey(req.params.id));
await client.getDel(doorStatusKey(door));
await client.quit();
return callback(null, response);
}