Merge pull request #1200 from RickCarlino/priority
Add "priority" arg to "rpc_request" nodes.pull/1201/head
commit
7b15a8f485
|
@ -218,6 +218,7 @@ module CeleryScriptSettingsBag
|
||||||
op: {
|
op: {
|
||||||
defn: [e(:ALLOWED_OPS)],
|
defn: [e(:ALLOWED_OPS)],
|
||||||
},
|
},
|
||||||
|
priority: { defn: [v(:integer)] },
|
||||||
channel_name: {
|
channel_name: {
|
||||||
defn: [e(:ALLOWED_CHANNEL_NAMES)],
|
defn: [e(:ALLOWED_CHANNEL_NAMES)],
|
||||||
},
|
},
|
||||||
|
@ -402,7 +403,7 @@ module CeleryScriptSettingsBag
|
||||||
tags: [:data],
|
tags: [:data],
|
||||||
},
|
},
|
||||||
rpc_request: {
|
rpc_request: {
|
||||||
args: [:label],
|
args: [:label, :priority],
|
||||||
body: ALLOWED_RPC_NODES,
|
body: ALLOWED_RPC_NODES,
|
||||||
tags: [:*],
|
tags: [:*],
|
||||||
},
|
},
|
||||||
|
|
|
@ -22,10 +22,10 @@ import {
|
||||||
isInactive,
|
isInactive,
|
||||||
sendOutboundPing,
|
sendOutboundPing,
|
||||||
startPinging,
|
startPinging,
|
||||||
PING,
|
buildPing,
|
||||||
ACTIVE_THRESHOLD
|
ACTIVE_THRESHOLD
|
||||||
} from "../ping_mqtt";
|
} from "../ping_mqtt";
|
||||||
import { Farmbot } from "farmbot";
|
import { Farmbot, RpcRequest, RpcRequestBodyItem } from "farmbot";
|
||||||
import { dispatchNetworkDown, dispatchNetworkUp } from "../index";
|
import { dispatchNetworkDown, dispatchNetworkUp } from "../index";
|
||||||
import { FarmBotInternalConfig } from "farmbot/dist/config";
|
import { FarmBotInternalConfig } from "farmbot/dist/config";
|
||||||
|
|
||||||
|
@ -38,6 +38,15 @@ let state: Partial<FarmBotInternalConfig> = {
|
||||||
|
|
||||||
function fakeBot(): Farmbot {
|
function fakeBot(): Farmbot {
|
||||||
const fb: Partial<Farmbot> = {
|
const fb: Partial<Farmbot> = {
|
||||||
|
rpcShim: jest.fn((_: RpcRequestBodyItem[]): RpcRequest => {
|
||||||
|
return {
|
||||||
|
kind: "rpc_request",
|
||||||
|
args: {
|
||||||
|
label: "ping",
|
||||||
|
priority: 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}),
|
||||||
setConfig: jest.fn(),
|
setConfig: jest.fn(),
|
||||||
publish: jest.fn(),
|
publish: jest.fn(),
|
||||||
on: jest.fn(),
|
on: jest.fn(),
|
||||||
|
@ -96,7 +105,7 @@ describe("ping util", () => {
|
||||||
const bot = fakeBot();
|
const bot = fakeBot();
|
||||||
const oldOutbound = readPing(bot, "out");
|
const oldOutbound = readPing(bot, "out");
|
||||||
sendOutboundPing(bot);
|
sendOutboundPing(bot);
|
||||||
expect(bot.publish).toHaveBeenCalledWith(PING);
|
expect(bot.publish).toHaveBeenCalledWith(buildPing(bot));
|
||||||
expect(oldOutbound).toBeLessThanOrEqual(readPing(bot, "out") || NaN);
|
expect(oldOutbound).toBeLessThanOrEqual(readPing(bot, "out") || NaN);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Farmbot, RpcRequest } from "farmbot";
|
import { Farmbot } from "farmbot";
|
||||||
import { dispatchNetworkDown, dispatchNetworkUp } from "./index";
|
import { dispatchNetworkDown, dispatchNetworkUp } from "./index";
|
||||||
import { isNumber } from "lodash";
|
import { isNumber } from "lodash";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
@ -9,10 +9,14 @@ import { FarmBotInternalConfig } from "farmbot/dist/config";
|
||||||
export const PING_INTERVAL = 3000;
|
export const PING_INTERVAL = 3000;
|
||||||
export const ACTIVE_THRESHOLD = PING_INTERVAL * 2;
|
export const ACTIVE_THRESHOLD = PING_INTERVAL * 2;
|
||||||
|
|
||||||
const label = "ping";
|
const PING_LABEL = "ping";
|
||||||
export const LAST_IN: keyof FarmBotInternalConfig = "LAST_PING_IN";
|
export const LAST_IN: keyof FarmBotInternalConfig = "LAST_PING_IN";
|
||||||
export const LAST_OUT: keyof FarmBotInternalConfig = "LAST_PING_OUT";
|
export const LAST_OUT: keyof FarmBotInternalConfig = "LAST_PING_OUT";
|
||||||
export const PING: Readonly<RpcRequest> = { kind: "rpc_request", args: { label } };
|
export function buildPing(bot: Farmbot) {
|
||||||
|
const rpc = bot.rpcShim([]);
|
||||||
|
rpc.args.label = PING_LABEL;
|
||||||
|
return rpc;
|
||||||
|
}
|
||||||
|
|
||||||
type Direction = "in" | "out";
|
type Direction = "in" | "out";
|
||||||
|
|
||||||
|
@ -40,7 +44,7 @@ export function isInactive(last: number, now: number): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendOutboundPing(bot: Farmbot) {
|
export function sendOutboundPing(bot: Farmbot) {
|
||||||
bot.publish(PING);
|
bot.publish(buildPing(bot));
|
||||||
const now = timestamp();
|
const now = timestamp();
|
||||||
const lastPing = readPing(bot, "in");
|
const lastPing = readPing(bot, "in");
|
||||||
lastPing && (isInactive(lastPing, now) ? markStale() : markActive());
|
lastPing && (isInactive(lastPing, now) ? markStale() : markActive());
|
||||||
|
@ -49,7 +53,7 @@ export function sendOutboundPing(bot: Farmbot) {
|
||||||
|
|
||||||
export function startPinging(bot: Farmbot) {
|
export function startPinging(bot: Farmbot) {
|
||||||
setInterval(() => sendOutboundPing(bot), PING_INTERVAL);
|
setInterval(() => sendOutboundPing(bot), PING_INTERVAL);
|
||||||
bot.on(label, () => writePing(bot, "in"));
|
bot.on(PING_LABEL, () => writePing(bot, "in"));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pingAPI() {
|
export function pingAPI() {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const mockDevice = {
|
const mockDevice = {
|
||||||
send: jest.fn(() => { return Promise.resolve(); }),
|
send: jest.fn(() => Promise.resolve()),
|
||||||
|
rpcShim: jest.fn(() => Promise.resolve()),
|
||||||
};
|
};
|
||||||
|
|
||||||
jest.mock("../../../device", () => ({
|
jest.mock("../../../device", () => ({
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { Farmbot, rpcRequest } from "farmbot";
|
import { Farmbot } from "farmbot";
|
||||||
import { createTransferCert } from "./create_transfer_cert";
|
import { createTransferCert } from "./create_transfer_cert";
|
||||||
import { toPairs } from "../../util";
|
import { toPairs } from "../../util";
|
||||||
|
import { getDevice } from "../../device";
|
||||||
|
|
||||||
export interface TransferProps {
|
export interface TransferProps {
|
||||||
email: string;
|
email: string;
|
||||||
|
@ -14,7 +15,9 @@ export async function transferOwnership(input: TransferProps): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const secret = await createTransferCert(input);
|
const secret = await createTransferCert(input);
|
||||||
const body = toPairs({ email, secret });
|
const body = toPairs({ email, secret });
|
||||||
await device.send(rpcRequest([{ kind: "change_ownership", args: {}, body }]));
|
await device.send(getDevice().rpcShim([{
|
||||||
|
kind: "change_ownership", args: {}, body
|
||||||
|
}]));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
"coveralls": "3.0.3",
|
"coveralls": "3.0.3",
|
||||||
"enzyme": "3.9.0",
|
"enzyme": "3.9.0",
|
||||||
"enzyme-adapter-react-16": "1.13.0",
|
"enzyme-adapter-react-16": "1.13.0",
|
||||||
"farmbot": "7.1.0",
|
"farmbot": "8.0.0-rc1",
|
||||||
"farmbot-toastr": "1.0.3",
|
"farmbot-toastr": "1.0.3",
|
||||||
"i18next": "15.1.1",
|
"i18next": "15.1.1",
|
||||||
"jest": "24.8.0",
|
"jest": "24.8.0",
|
||||||
|
|
Loading…
Reference in New Issue