Skip to content

Commit

Permalink
this
Browse files Browse the repository at this point in the history
  • Loading branch information
zoe-codez committed Apr 11, 2024
1 parent 4f301ef commit 62a7e75
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@digital-alchemy/grocy",
"repository": "https://github.com/Digital-Alchemy-TS/grocy",
"homepage": "https://docs.digital-alchemy.app/Grocy",
"version": "0.3.4",
"version": "0.3.5",
"scripts": {
"build": "tsc",
"lint": "eslint src",
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/chores.extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function Chores({ grocy, logger }: TServiceParams) {

async recalculateAssignments() {
logger.trace("recalculateAssignments");
return await this.grocy({
return await grocy.fetch({
url: `/chores/executions/calculate-next-assignments`,
});
},
Expand Down
26 changes: 17 additions & 9 deletions src/extensions/system.extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,32 @@ import dayjs, { Dayjs } from "dayjs";

import { GROCY_DATABASE_UPDATED } from "../helpers";

export function System({ lifecycle, grocy, logger }: TServiceParams) {
export function System({
lifecycle,
grocy,
logger,
event,
config,
}: TServiceParams) {
let LAST_CHANGED_TIME: Dayjs;

lifecycle.onBootstrap(async () => {
try {
this.LAST_CHANGED_TIME = await this.getSystemDbChangedTime();
LAST_CHANGED_TIME = await grocy.system.getSystemDbChangedTime();
} catch {
this.logger.fatal("Cannot contact grocy");
logger.fatal("Cannot contact grocy");
}
setInterval(async () => {
try {
const last = await this.getSystemDbChangedTime();
if (last.isAfter(this.LAST_CHANGED_TIME)) {
this.LAST_CHANGED_TIME = last;
this.event.emit(GROCY_DATABASE_UPDATED);
const last = await grocy.system.getSystemDbChangedTime();
if (last.isAfter(LAST_CHANGED_TIME)) {
LAST_CHANGED_TIME = last;
event.emit(GROCY_DATABASE_UPDATED);
}
} catch (error) {
this.logger.error({ error }, "Grocy database time poll failed");
logger.error({ error }, "Grocy database time poll failed");
}
}, this.pollInterval);
}, config.grocy.POLL_INTERVAL);
});

return {
Expand Down

0 comments on commit 62a7e75

Please sign in to comment.