12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import JobContext from "@/JobContext";
- import { UniqueMethods } from "@/types/Modules";
- import BaseModule from "@/BaseModule";
- export default class StationsModule extends BaseModule {
- /**
- * Station Module
- */
- public constructor() {
- super("stations");
- this._dependentModules = ["data"];
- }
- /**
- * startup - Startup station module
- */
- public override async startup() {
- await super.startup();
- this.log("Station Startup");
- await super._started();
- }
- /**
- * shutdown - Shutdown station module
- */
- public override async shutdown() {
- await super.shutdown();
- await super._stopped();
- }
- /**
- * addToQueue - Add media to queue
- *
- * @param payload - Payload
- */
- public async addToQueue(context: JobContext, payload: { songId: string }) {
- const { songId } = payload;
- context.log(`Adding song ${songId} to the queue.`);
- await new Promise((resolve, reject) => {
- setTimeout(() => {
- if (Math.round(Math.random())) reject(new Error("Test321"));
- else resolve(true);
- }, Math.random() * 1000);
- });
- }
- public async addA(context: JobContext) {
- context.log("ADDA");
- await context.jobQueue.runJob("stations", "addB", {}, { priority: 5 });
- return { number: 123 };
- }
- public async addB(context: JobContext) {
- context.log("ADDB");
- await context.jobQueue.runJob("stations", "addToQueue", {
- songId: "test"
- });
- await context.jobQueue.runJob("stations", "addC", {});
- }
- public async addC(context: JobContext) {
- context.log("ADDC");
- // await new Promise(() => {});
- }
- }
- export type StationsModuleJobs = {
- [Property in keyof UniqueMethods<StationsModule>]: {
- payload: Parameters<UniqueMethods<StationsModule>[Property]>[1];
- returns: Awaited<ReturnType<UniqueMethods<StationsModule>[Property]>>;
- };
- };
|