Browse Source

Update Seeker service to use new Database module. Clean up torrent IPC

dev
David Ludwig 4 years ago
parent
commit
145883b8c7
7 changed files with 84 additions and 84 deletions
  1. +1
    -1
      services/seeker/src/Application.ts
  2. +0
    -37
      services/seeker/src/services/Database.ts
  3. +50
    -0
      services/seeker/src/services/TorrentIpc.ts
  4. +23
    -9
      services/seeker/src/services/TorrentManager.ts
  5. +0
    -25
      services/seeker/src/services/TorrentManager/TorrentClientIpc.ts
  6. +0
    -3
      services/seeker/src/services/TorrentManager/index.ts
  7. +10
    -9
      services/seeker/src/services/index.ts

+ 1
- 1
services/seeker/src/Application.ts View File

@ -1,4 +1,4 @@
import services from "./services";
import * as services from "./services";
import { Microservice } from "@autoplex/microservice";
/**


+ 0
- 37
services/seeker/src/services/Database.ts View File

@ -1,37 +0,0 @@
import { Connection } from "typeorm";
import connectToDatabase from "@autoplex/database";
import { env, secret } from "@autoplex/utils";
import { InternalService } from "@autoplex/microservice";
import Application from "../Application";
export default class Database extends InternalService<Application>
{
/**
* The active database connection
*/
protected connection!: Connection;
/**
* The service name
*/
public readonly NAME = "Database";
/**
* Boot the database service
*/
public async boot() {
let host = env("DB_HOST");
let port = parseInt(env("DB_PORT"));
let username = env("DB_USER");
let password = await secret(env("DB_PASSWORD_FILE"));
let database = env("DB_DATABASE");
this.connection = await connectToDatabase(host, port, username, password, database);
}
/**
* Shutdown the database service
*/
public async shutdown() {
await this.connection.close();
}
}

+ 50
- 0
services/seeker/src/services/TorrentIpc.ts View File

@ -0,0 +1,50 @@
import Application from "../Application";
import { IpcClient } from "@autoplex-api/torrent";
interface IResponse {
response?: any,
error?: string | Error
}
/**
* Declare EventEmitter types
*/
interface TorrentIpcEvents {
"connected": () => void
}
/**
* Torrent IPC events
*/
declare interface TorrentIpc {
on<U extends keyof TorrentIpcEvents>(event: U, listener: TorrentIpcEvents[U]): this,
emit<U extends keyof TorrentIpcEvents>(event: U, ...args: Parameters<TorrentIpcEvents[U]>): boolean
}
/**
* The torrent client IPC service
*/
class TorrentIpc extends IpcClient<Application>
{
/**
* Install the message event handlers
*/
protected installMessageHandlers() {
this.addListener("torrent_finished", this.onTorrentFinished);
}
/**
* Invoked when a torrent has finished downloading
*/
protected async onTorrentFinished(infoHash: string) {}
/**
* Emit an event when connected
*/
protected onConnect() {
super.onConnect();
this.emit("connected");
}
}
export default TorrentIpc;

services/seeker/src/services/TorrentManager/TorrentManager.ts → services/seeker/src/services/TorrentManager.ts View File


+ 0
- 25
services/seeker/src/services/TorrentManager/TorrentClientIpc.ts View File

@ -1,25 +0,0 @@
import Application from "../../Application";
import { IpcClient } from "@autoplex-api/torrent";
interface IResponse {
response?: any,
error?: string | Error
}
/**
* The torrent client IPC service
*/
export default abstract class TorrentClientIpc extends IpcClient<Application>
{
/**
* Install the message event handlers
*/
protected installMessageHandlers() {
this.addListener("torrent_finished", this.onTorrentFinished);
}
/**
* Invoked when a torrent has finished downloading
*/
protected async onTorrentFinished(infoHash: string) {}
}

+ 0
- 3
services/seeker/src/services/TorrentManager/index.ts View File

@ -1,3 +0,0 @@
import TorrentManager from "./TorrentManager";
export default TorrentManager;

+ 10
- 9
services/seeker/src/services/index.ts View File

@ -1,15 +1,16 @@
import Database from "./Database";
import IpcInterface from "./IpcInterface";
import MovieSearch from "./MovieSearch";
import PostProcessor from "./PostProcessor";
import Supervisor from "./Supervisor";
import TorrentManager from "./TorrentManager";
export { DatabaseService } from "@autoplex/database";
import IpcInterface from "./IpcInterface";
import MovieSearch from "./MovieSearch";
import PostProcessor from "./PostProcessor";
import Supervisor from "./Supervisor";
import TorrentIpc from "./TorrentIpc";
import TorrentManager from "./TorrentManager";
export default {
Database,
export {
IpcInterface,
MovieSearch,
PostProcessor,
Supervisor,
TorrentManager,
TorrentIpc,
TorrentManager
}

Loading…
Cancel
Save