Merge pull request #1200 from RickCarlino/priority

Add "priority" arg to "rpc_request" nodes.
pull/1201/head
Rick Carlino 2019-05-19 12:21:24 -05:00 committed by GitHub
commit 7b15a8f485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 13 deletions

View File

@ -218,6 +218,7 @@ module CeleryScriptSettingsBag
op: {
defn: [e(:ALLOWED_OPS)],
},
priority: { defn: [v(:integer)] },
channel_name: {
defn: [e(:ALLOWED_CHANNEL_NAMES)],
},
@ -402,7 +403,7 @@ module CeleryScriptSettingsBag
tags: [:data],
},
rpc_request: {
args: [:label],
args: [:label, :priority],
body: ALLOWED_RPC_NODES,
tags: [:*],
},

View File

@ -22,10 +22,10 @@ import {
isInactive,
sendOutboundPing,
startPinging,
PING,
buildPing,
ACTIVE_THRESHOLD
} from "../ping_mqtt";
import { Farmbot } from "farmbot";
import { Farmbot, RpcRequest, RpcRequestBodyItem } from "farmbot";
import { dispatchNetworkDown, dispatchNetworkUp } from "../index";
import { FarmBotInternalConfig } from "farmbot/dist/config";
@ -38,6 +38,15 @@ let state: Partial<FarmBotInternalConfig> = {
function fakeBot(): Farmbot {
const fb: Partial<Farmbot> = {
rpcShim: jest.fn((_: RpcRequestBodyItem[]): RpcRequest => {
return {
kind: "rpc_request",
args: {
label: "ping",
priority: 0
}
};
}),
setConfig: jest.fn(),
publish: jest.fn(),
on: jest.fn(),
@ -96,7 +105,7 @@ describe("ping util", () => {
const bot = fakeBot();
const oldOutbound = readPing(bot, "out");
sendOutboundPing(bot);
expect(bot.publish).toHaveBeenCalledWith(PING);
expect(bot.publish).toHaveBeenCalledWith(buildPing(bot));
expect(oldOutbound).toBeLessThanOrEqual(readPing(bot, "out") || NaN);
});

View File

@ -1,4 +1,4 @@
import { Farmbot, RpcRequest } from "farmbot";
import { Farmbot } from "farmbot";
import { dispatchNetworkDown, dispatchNetworkUp } from "./index";
import { isNumber } from "lodash";
import axios from "axios";
@ -9,10 +9,14 @@ import { FarmBotInternalConfig } from "farmbot/dist/config";
export const PING_INTERVAL = 3000;
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_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";
@ -40,7 +44,7 @@ export function isInactive(last: number, now: number): boolean {
}
export function sendOutboundPing(bot: Farmbot) {
bot.publish(PING);
bot.publish(buildPing(bot));
const now = timestamp();
const lastPing = readPing(bot, "in");
lastPing && (isInactive(lastPing, now) ? markStale() : markActive());
@ -49,7 +53,7 @@ export function sendOutboundPing(bot: Farmbot) {
export function startPinging(bot: Farmbot) {
setInterval(() => sendOutboundPing(bot), PING_INTERVAL);
bot.on(label, () => writePing(bot, "in"));
bot.on(PING_LABEL, () => writePing(bot, "in"));
}
export function pingAPI() {

View File

@ -1,5 +1,6 @@
const mockDevice = {
send: jest.fn(() => { return Promise.resolve(); }),
send: jest.fn(() => Promise.resolve()),
rpcShim: jest.fn(() => Promise.resolve()),
};
jest.mock("../../../device", () => ({

View File

@ -1,6 +1,7 @@
import { Farmbot, rpcRequest } from "farmbot";
import { Farmbot } from "farmbot";
import { createTransferCert } from "./create_transfer_cert";
import { toPairs } from "../../util";
import { getDevice } from "../../device";
export interface TransferProps {
email: string;
@ -14,7 +15,9 @@ export async function transferOwnership(input: TransferProps): Promise<void> {
try {
const secret = await createTransferCert(input);
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();
} catch (error) {
return Promise.reject(error);

View File

@ -43,7 +43,7 @@
"coveralls": "3.0.3",
"enzyme": "3.9.0",
"enzyme-adapter-react-16": "1.13.0",
"farmbot": "7.1.0",
"farmbot": "8.0.0-rc1",
"farmbot-toastr": "1.0.3",
"i18next": "15.1.1",
"jest": "24.8.0",