This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <ESP8266HTTPClient.h> | |
#define WIFI_NAME "" | |
#define WIFI_PASSWORD "" | |
#define HOST "" | |
#define PATH "/webhooks/electricity/" | |
#define PORT 443 | |
#define CHAT_ID "" | |
#define TIMER_DELAY 60000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { RequestHandler } from 'express'; | |
import { ITelegramBot } from '@/application/telegram-bot'; | |
import { Timer } from '@/application/timer'; | |
import { ITimerStore } from '@/application/timer-store'; | |
import { Controller } from './controller'; | |
const FIVE_MINUTES = 1000 * 60 * 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ITimer } from './timer'; | |
interface ITimerStore { | |
getTimerById(id: string): ITimer | null; | |
addTimer(id: string, timer: ITimer): void; | |
} | |
class TimerStore implements ITimerStore { | |
private timers: Map<string, ITimer>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Callback = () => Promise<void> | void; | |
interface ITimer { | |
reset(): void; | |
refresh(): void; | |
isTimerRunning(): boolean; | |
} | |
class Timer implements ITimer { | |
private callbacks: Callback[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios, { AxiosInstance } from 'axios'; | |
interface ITelegramBot { | |
sendMessage(chatId: string, message: string): Promise<void>; | |
} | |
class TelegramBot implements ITelegramBot { | |
private axiosInstance: AxiosInstance; | |
public constructor(botToken: string) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestHttp extends Http { | |
constructor() { | |
super('http://localhost:5000/'); | |
} | |
public test() { | |
return this.instance.get('/test'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
let counter = 0; | |
app.get('/test', (_, res) => { | |
counter++; | |
console.log(`Incoming request №${counter}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CircuitBreakerWithEmitter implements ICircuitBreakerWithEmitter { | |
private readonly http: IHttp; | |
private readonly timeout: number; | |
private isOpen: boolean = false; | |
private readonly errorHandler: (error: any) => boolean; | |
private readonly eventEmitter: IEventEmitter; | |
constructor(http: IHttp, option: ICircuitBreakerOptions) { | |
this.http = http; | |
this.timeout = option.timeout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventEmitter implements IEventEmitter { | |
private readonly events: Record<string, Function[]>; | |
public constructor() { | |
this.events = {}; | |
} | |
public on(name: string, listener: Function) { | |
if (!this.events[name]) { | |
this.events[name] = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'; | |
class CircuitBreaker implements ICircuitBreaker { | |
private readonly http: IHttp; | |
private readonly timeout: number; | |
private isOpen = false; | |
private errorHandler: (error: any) => boolean; | |
constructor(http: IHttp, options: ICircuitBreakerOptions) { | |
this.http = http; |
NewerOlder