import chalk from "chalk";
export function getQueueName(endpoint) {
    return new URL(endpoint).pathname;
}
export class DxLogger {
    started(address = "localhost:9181", telemetryEnabled = true) {
        console.log(chalk `
{yellow Quirrel}
{yellow =======}
Welcome to the Quirrel development server.

Open your browser and go to
    {yellow http://${address}}
to get a better overview over pending jobs.
${telemetryEnabled
            ? chalk `
Quirrel collects {black completely anonymous}
telemetry data about general usage,
opt-out by setting the {yellow DISABLE_TELEMETRY}
environment variable.
`
            : ""}
Listening on {yellow ${address}}.`.trim());
    }
    executionErrored(job, error) {
        console.error("Caught error during execution:", error, job);
    }
    jobCreated(job) {
        var _a;
        if (job.id === "@cron") {
            console.log(chalk `
⏰Registered a Cron Job
   {gray endpoint:} {yellow ${getQueueName(job.endpoint)}}
   {gray schedule:} {yellow ${(_a = job.repeat) === null || _a === void 0 ? void 0 : _a.cron}}`);
            return;
        }
        console.log(chalk `
📝Created Job
   {gray queue:} {yellow ${getQueueName(job.endpoint)}}
      {gray id:} {yellow ${job.id}}
    {gray body:} {yellow ${job.body}}`);
    }
    cronUpdated(crons, deleted) {
        if (crons.dryRun) {
            return;
        }
        console.log("\n⏰Updated Cron jobs");
        console.log(crons.crons
            .map((c) => chalk `  {yellow ${c.route}:} {green ${c.schedule}}`)
            .join("\n"));
        if (deleted.length) {
            console.log(chalk `  {red obsolete:} {yellow ${deleted.join(", ")}}`);
        }
    }
    jobDeleted(job) {
        if (job.id === "@cron") {
            console.log(chalk `
⏰Unregistered a Cron Job
   {gray endpoint:} {yellow ${getQueueName(job.endpoint)}}`);
            return;
        }
    }
    startingExecution(job) {
        console.log(chalk `
👟Executing job
  {gray queue:} {yellow ${getQueueName(job.endpoint)}}
     {gray id:} {yellow ${job.id}}
   {gray body:} {yellow ${job.body}}`);
        return () => {
            console.log("\n" + chalk `✔️ Successfully executed {yellow ${job.id}}.`);
        };
    }
}
//# sourceMappingURL=dx-logger.js.map