Add cron job to add coins to a user every 30 minutes #219
3 changed files with 7 additions and 5 deletions
|
@ -1,11 +1,12 @@
|
||||||
import { CronJob } from "cron";
|
import { CronJob } from "cron";
|
||||||
import { v4 } from "uuid";
|
import { v4 } from "uuid";
|
||||||
|
import { Primitive } from "../type/primitive";
|
||||||
|
|
||||||
interface Timer {
|
interface Timer {
|
||||||
id: string;
|
id: string;
|
||||||
job: CronJob;
|
job: CronJob;
|
||||||
context: Map<string, any>;
|
context: Map<string, Primitive>;
|
||||||
onTick: ((context: Map<string, any>) => void) | ((context: Map<string, any>) => Promise<void>);
|
onTick: ((context: Map<string, Primitive>) => void) | ((context: Map<string, Primitive>) => Promise<void>);
|
||||||
runOnStart: boolean;
|
runOnStart: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,9 +20,9 @@ export default class TimerHelper {
|
||||||
public AddTimer(
|
public AddTimer(
|
||||||
cronTime: string,
|
cronTime: string,
|
||||||
timeZone: string,
|
timeZone: string,
|
||||||
onTick: ((context: Map<string, any>) => void) | ((context: Map<string, any>) => Promise<void>),
|
onTick: ((context: Map<string, Primitive>) => void) | ((context: Map<string, Primitive>) => Promise<void>),
|
||||||
runOnStart: boolean = false): string {
|
runOnStart: boolean = false): string {
|
||||||
const context = new Map<string, any>();
|
const context = new Map<string, Primitive>();
|
||||||
|
|
||||||
const job = new CronJob(
|
const job = new CronJob(
|
||||||
cronTime,
|
cronTime,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import AppLogger from "../client/appLogger";
|
import AppLogger from "../client/appLogger";
|
||||||
import User from "../database/entities/app/User";
|
import User from "../database/entities/app/User";
|
||||||
|
|
||||||
export default async function GiveCurrency(context: Map<string, any>) {
|
export default async function GiveCurrency() {
|
||||||
AppLogger.LogInfo("Timers/GiveCurrency", "Giving currency to every known user");
|
AppLogger.LogInfo("Timers/GiveCurrency", "Giving currency to every known user");
|
||||||
|
|
||||||
const users = await User.FetchAll(User);
|
const users = await User.FetchAll(User);
|
||||||
|
|
1
src/type/primitive.ts
Normal file
1
src/type/primitive.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export type Primitive = string | number | boolean;
|
Loading…
Reference in a new issue