Skip to content

Commit

Permalink
remove mode subscribe, legacy common.wakeup and legacy common.subscri…
Browse files Browse the repository at this point in the history
…be (#2634)

* remove mode subscribe, legacy common.wakeup and legacy common.subscribe

- closes #2607

* some cleanup and jsdoc

* remove never called code

* start listening to logs before doing async operations

* remove subscribe mode from readme
  • Loading branch information
foxriver76 committed Mar 25, 2024
1 parent 7729e47 commit 938507b
Show file tree
Hide file tree
Showing 8 changed files with 404 additions and 500 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,6 @@ ioBroker supports multiple Adapter modes. These are:
* `deamon`: The adapter is started and runs all the time. If the process gets killed, it will be restarted automatically. This adapter type is mainly used for all situations where communications or actions are done continuously. These adapters also support a restart schedule where the controller restarts the instances. The adapter needs RAM and some CPU resources also when doing nothing.
* `schedule`: The adapter is started based on a defined schedule (e.g., once per hour, once a day, all 10 minutes ...), then is doing its work and is stopping itself when finished. The adapter is only using RAM and CPU when needed.
* `once`: The adapter ist started only once after it's object got modified. No restarting happens after the adapter stops.
* `subscribe`: The adapter is started when a defined state ID gets set to true, and stopped when set to false
* `none`: The adapter is officially not having any process, but could be a webExtension (so iis included by a web instance on the same host or is only running client side and so offering www files)

#### Start adapter instances as normal processes
Expand Down
776 changes: 379 additions & 397 deletions packages/adapter/src/lib/adapter/adapter.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/cli/src/lib/setup/setupInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ export class Install {

let objs: ioBroker.StateObject[];
if (!instanceObj.common.onlyWWW && instanceObj.common.mode !== 'once') {
objs = tools.getInstanceIndicatorObjects(`${adapter}.${instance}`, !!instanceObj.common.wakeup);
objs = tools.getInstanceIndicatorObjects(`${adapter}.${instance}`);
} else {
objs = [];
}
Expand Down
23 changes: 3 additions & 20 deletions packages/common/src/lib/common/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3309,11 +3309,11 @@ export function removePreservedProperties(
* Returns the array of system.adapter.<namespace>.* objects which are created for every instance
*
* @param namespace - adapter namespace + id, e.g., hm-rpc.0
* @param createWakeup - indicator to create a wakeup object too
*/
export function getInstanceIndicatorObjects(namespace: string, createWakeup: boolean): ioBroker.StateObject[] {
export function getInstanceIndicatorObjects(namespace: string): ioBroker.StateObject[] {
const id = `system.adapter.${namespace}`;
const objs: ioBroker.StateObject[] = [

return [
{
_id: `${id}.alive`,
type: 'state',
Expand Down Expand Up @@ -3498,23 +3498,6 @@ export function getInstanceIndicatorObjects(namespace: string, createWakeup: boo
native: {}
}
];

if (createWakeup) {
objs.push({
_id: `${id}.wakeup`,
type: 'state',
common: {
name: `${namespace}.wakeup`,
read: true,
write: true,
type: 'boolean',
role: 'adapter.wakeup'
},
native: {}
});
}

return objs;
}

export type InternalLogger = Omit<ioBroker.Logger, 'level'>;
Expand Down
68 changes: 1 addition & 67 deletions packages/controller/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,7 @@ function createObjects(onConnect: () => void): void {
hostAdapter[id] = hostAdapter[id] || {};
hostAdapter[id].config = obj;
}
if (
proc.process ||
proc.config.common.mode === 'schedule' ||
proc.config.common.mode === 'subscribe'
) {
if (proc.process || proc.config.common.mode === 'schedule') {
proc.restartExpected = true;
await stopInstance(id, false);
if (!procs[id]) {
Expand Down Expand Up @@ -3752,10 +3748,6 @@ async function startInstance(id: ioBroker.ObjectIDs.Instance, wakeUp = false): P
mode = 'daemon';
}

if (instance.common.wakeup) {
// TODO
}

// Check if all required adapters installed and have a valid version
if (instance.common.dependencies || instance.common.globalDependencies) {
try {
Expand Down Expand Up @@ -3913,28 +3905,6 @@ async function startInstance(id: ioBroker.ObjectIDs.Instance, wakeUp = false): P
}
}

if (instance.common.subscribe || instance.common.wakeup) {
proc.subscribe = instance.common.subscribe || `${instance._id}.wakeup`;
const parts = instance._id.split('.');
const instanceId = parts[parts.length - 1];
proc.subscribe = proc.subscribe!.replace('<INSTANCE>', instanceId);

if (subscribe[proc.subscribe]) {
if (!subscribe[proc.subscribe].includes(id)) {
subscribe[proc.subscribe].push(id);
}
} else {
subscribe[proc.subscribe] = [id];

// Subscribe on changes
if (proc.subscribe.startsWith('messagebox.')) {
states!.subscribeMessage(proc.subscribe.substring('messagebox.'.length));
} else {
states!.subscribe(proc.subscribe);
}
}
}

proc.startedInCompactMode = false;
proc.startedAsCompactGroup = false;

Expand Down Expand Up @@ -4721,7 +4691,6 @@ async function startInstance(id: ioBroker.ObjectIDs.Instance, wakeUp = false): P
break;
}
case 'extension':
case 'subscribe':
break;

default:
Expand Down Expand Up @@ -4949,41 +4918,6 @@ async function stopInstance(id: string, force: boolean): Promise<void> {
}
break;

case 'subscribe':
if (proc.subscribe) {
// Remove this id from subscribed on this message
if (subscribe[proc.subscribe] && subscribe[proc.subscribe].includes(id as any)) {
subscribe[proc.subscribe].splice(subscribe[proc.subscribe].indexOf(id as any), 1);

// If no one subscribed
if (!subscribe[proc.subscribe].length) {
// Delete item
delete subscribe[proc.subscribe];

// Unsubscribe
if (proc.subscribe.startsWith('messagebox.')) {
states!.unsubscribeMessage(proc.subscribe.substring('messagebox.'.length));
} else {
states!.unsubscribe(proc.subscribe);
}
}
}
}

if (!proc.process) {
return;
} else {
logger.info(`${hostLogPrefix} stopInstance ${instance._id} killing pid ${proc.process.pid}`);
proc.stopping = true;
try {
proc.process.kill('SIGKILL'); // call stop directly in adapter.js
} catch (e) {
logger.error(`${hostLogPrefix} Cannot stop ${id}: ${JSON.stringify(e)}`);
}
delete proc.process;
}
break;

default:
}
}
Expand Down
19 changes: 19 additions & 0 deletions packages/db-states-redis/src/lib/states/statesInRedisClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,18 @@ export class StateRedisClient {
return this.getState(id);
}

getStates(keys: string[], callback?: undefined, dontModify?: boolean): Promise<(ioBroker.State | null)[]>;
getStates(
keys: string[],
callback: (err: Error | undefined | null, states?: (ioBroker.State | null)[]) => void,
dontModify?: boolean
): Promise<void>;
getStates(
keys: string[],
callback: (err: Error | undefined | null, states?: (ioBroker.State | null)[]) => void,
dontModify?: boolean
): Promise<void>;

async getStates(
keys: string[],
callback?: (err: Error | undefined | null, states?: (ioBroker.State | null)[]) => void,
Expand Down Expand Up @@ -1053,6 +1065,13 @@ export class StateRedisClient {
}
}

getKeys(
pattern: string,
callback?: undefined,
dontModify?: boolean
): Promise<ioBroker.CallbackReturnTypeOf<ioBroker.GetKeysCallback>>;
getKeys(pattern: string, callback: ioBroker.GetKeysCallback, dontModify?: boolean): Promise<void>;

async getKeys(
pattern: string,
callback?: ioBroker.GetKeysCallback,
Expand Down
5 changes: 1 addition & 4 deletions packages/types-dev/objects.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ declare global {
custom?: undefined;
}

type InstanceMode = 'none' | 'daemon' | 'subscribe' | 'schedule' | 'once' | 'extension';
type InstanceMode = 'none' | 'daemon' | 'schedule' | 'once' | 'extension';

interface AdminUi {
/** UI type of config page inside admin UI */
Expand Down Expand Up @@ -662,7 +662,6 @@ declare global {
/** Overrides the default timeout that ioBroker will wait before force-stopping the adapter */
stopTimeout?: number;
subscribable?: boolean;
subscribe?: any; // ?
/** If `true`, this adapter provides custom per-state settings. Requires a `custom_m.html` file in the `admin` directory. */
supportCustoms?: boolean;
/** @deprecated Use @see supportedMessages up from controller v5 */
Expand All @@ -678,8 +677,6 @@ declare global {
/** The available version in the ioBroker repo. */
version: string;
visWidgets?: Record<string, VisWidget>;
/** If `true`, the adapter will be started if any value is written into `system.adapter.<name>.<instance>.wakeup. Normally, the adapter should stop after processing the event. */
wakeup?: boolean;
/** Include the adapter version in the URL of the web adapter, e.g. `http://ip:port/1.2.3/material` instead of `http://ip:port/material` */
webByVersion?: boolean;
/** Whether the web server in this adapter can be extended with plugin/extensions */
Expand Down
10 changes: 0 additions & 10 deletions schemas/io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,6 @@
"enum": [
"none",
"daemon",
"subscribe",
"schedule",
"once",
"extension"
Expand Down Expand Up @@ -1213,7 +1212,6 @@
"enum": [
"none",
"daemon",
"subscribe",
"schedule",
"once",
"extension"
Expand Down Expand Up @@ -1336,10 +1334,6 @@
"description": "Variables of this adapter must be subscribed with sendTo to enable updates",
"type": "boolean"
},
"subscribe": {
"description": "Name of variable, that is subscribed automatically",
"type": "string"
},
"supportCustoms": {
"description": "If the adapter support settings for every state. It has to have custom.html file in admin. Sample can be found in ioBroker.history",
"type": "boolean"
Expand Down Expand Up @@ -1417,10 +1411,6 @@
}
}
},
"wakeup": {
"description": "Adapter will be started if some value is written into system.adapter.NAME.x.wakeup. Normally the adapter should stop after processing of event.",
"type": "boolean"
},
"webByVersion": {
"description": "Show version as prefix in web adapter (usually - ip:port/material, webByVersion - ip:port/1.2.3/material)",
"type": "boolean"
Expand Down

0 comments on commit 938507b

Please sign in to comment.