@fellas/adonisjs-resque
Version:
Resque Queue for AdonisJS v6
150 lines (142 loc) • 4.44 kB
JavaScript
// configure.ts
import { access } from "fs/promises";
async function configure(command) {
const codemods = await command.createCodemods();
if (await doesDependencyPackageMissing(command)) {
const dependencyPackage = "@adonisjs/redis";
const shouldInstallPackages = await command.prompt.confirm(
`Do you want to install dependencies ${dependencyPackage}?`,
{ name: "install", default: true }
);
const packagesToInstall = [
{
name: dependencyPackage,
isDevDependency: false
}
];
if (shouldInstallPackages) {
await codemods.installPackages(packagesToInstall);
command.logger.warning(`Run ${command.colors.bgMagenta(command.colors.red(`node ace configure ${dependencyPackage}`))} after installing`);
} else {
await codemods.listPackagesToInstall(packagesToInstall);
}
command.logger.warning(`and configure ${command.colors.red(dependencyPackage)} correctly before using this package`);
command.logger.action;
}
await codemods.makeUsingStub(stubsRoot, "config/resque.stub", {});
await codemods.updateRcFile((rcFile) => {
rcFile.addProvider(`${packageName}/providers/resque_provider`);
rcFile.addCommand(`${packageName}/commands`);
});
}
async function doesDependencyPackageMissing(command) {
const redisConfigFile = command.app.configPath("redis.ts");
try {
await access(redisConfigFile);
return false;
} catch (err) {
return true;
}
}
// define_config.ts
function defineConfig(config) {
return config;
}
// index.ts
import { Worker as Worker2 } from "node-resque";
import { Queue as Queue2 } from "node-resque";
// base_plugin.ts
import { Plugin } from "node-resque";
var BasePlugin = class extends Plugin {
static create(options = {}) {
return [this, options];
}
};
// plugin.ts
import { Plugins } from "node-resque";
var Plugin2 = class {
/**
* If a job with the same name, queue
* and args is already running
* put this job back in the queue and try later
* @param options.reEnqueue
* @param options.enqueueTimeout
* @param options.lockTimeout
* @param options.key
* If true, re-enqueue the job if it is already running. If false, do not enqueue the job if it is already running.
* @docs Source code: https://github.com/actionhero/node-resque/blob/main/src/plugins/JobLock.ts
*/
static jobLock(options = {}) {
return [Plugins.JobLock, options];
}
/**
* If a job with the same name, queue
* and args is already in the delayed queue(s)
* do not enqueue it again
* @docs Source code: https://github.com/actionhero/node-resque/blob/main/src/plugins/DelayQueueLock.ts
*/
static delayQueueLock() {
return [Plugins.DelayQueueLock, {}];
}
/**
* Log the error and do not throw it
* @param options.logger
* @docs Source code: https://github.com/actionhero/node-resque/blob/main/src/plugins/Noop.ts
* A function to log the error.
*/
static noop(options = {}) {
return [Plugins.Noop, options];
}
/**
* If a job with the same name, queue
* and args is already in the queue
* do not enqueue it again
* @param options.lockTimeout
* @param options.key
* @docs Source Code: https://github.com/actionhero/node-resque/blob/main/src/plugins/QueueLock.ts
*/
static queueLock(options = {}) {
return [Plugins.QueueLock, options];
}
/**
* If a job fails, retry it N times
* before finally placing it into the failed queue
*
* @param options.retryLimit
* @param options.retryDelay
* @param options.backoffStrategy
* @docs Source code: https://github.com/actionhero/node-resque/blob/main/src/plugins/Retry.ts
*/
static retry(options = {}) {
return [Plugins.Retry, options];
}
};
// index.ts
import { joinToURL } from "@poppinss/utils";
// types.ts
import { Worker, Plugins as Plugins2, Scheduler, Queue } from "node-resque";
// index.ts
import app from "@adonisjs/core/services/app";
var packageName = "@fellas/adonisjs-resque";
var stubsRoot = joinToURL(import.meta.url, "stubs");
function getConfig(name) {
return getConfigAll()[name];
}
function getConfigAll() {
return app.config.get("resque");
}
export {
configure,
defineConfig,
BasePlugin,
Plugin2 as Plugin,
Plugins2 as Plugins,
Scheduler,
packageName,
stubsRoot,
getConfig,
getConfigAll,
Worker2 as Worker,
Queue2 as Queue
};
//# sourceMappingURL=chunk-MZLOY7HF.js.map