0z2i6v3u5t 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/devcontainer.json +4 -0
- package/.devcontainer/setup.sh +11 -0
- package/.dockerignore +2 -0
- package/.github/CONTRIBUTING.md +52 -0
- package/.github/FUNDING.yml +3 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +59 -0
- package/.github/ISSUE_TEMPLATE/config.yml +5 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +43 -0
- package/.github/dependabot.yml +17 -0
- package/.github/workflows/codeql.yml +76 -0
- package/.github/workflows/publish_docs.yml +25 -0
- package/.github/workflows/test.yml +78 -0
- package/.nvmrc +1 -0
- package/.prettierignore +1 -0
- package/.prettierrc +1 -0
- package/.vscode/launch.json +42 -0
- package/CODE_OF_CONDUCT.md +76 -0
- package/Dockerfile +17 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/SECURITY.md +5 -0
- package/__tests__/actions/cacheTest.ts +58 -0
- package/__tests__/actions/randomNumber.ts +26 -0
- package/__tests__/actions/recursiveAction.ts +16 -0
- package/__tests__/actions/sleepTest.ts +24 -0
- package/__tests__/actions/status.ts +17 -0
- package/__tests__/actions/swagger.ts +76 -0
- package/__tests__/actions/validationTest.ts +63 -0
- package/__tests__/cli/cli.ts +126 -0
- package/__tests__/core/api.ts +632 -0
- package/__tests__/core/cache.ts +400 -0
- package/__tests__/core/chatRoom.ts +589 -0
- package/__tests__/core/cli.ts +349 -0
- package/__tests__/core/cluster.ts +132 -0
- package/__tests__/core/config.ts +78 -0
- package/__tests__/core/errors.ts +112 -0
- package/__tests__/core/log.ts +23 -0
- package/__tests__/core/middleware.ts +427 -0
- package/__tests__/core/plugins/partialPlugin.ts +94 -0
- package/__tests__/core/plugins/withPlugin.ts +88 -0
- package/__tests__/core/plugins/withoutPlugin.ts +81 -0
- package/__tests__/core/process.ts +42 -0
- package/__tests__/core/specHelper.ts +330 -0
- package/__tests__/core/staticFile/compression.ts +99 -0
- package/__tests__/core/staticFile/staticFile.ts +180 -0
- package/__tests__/core/tasks/customQueueFunction.ts +67 -0
- package/__tests__/core/tasks/fullWorkerFlow.ts +199 -0
- package/__tests__/core/tasks/tasks.ts +605 -0
- package/__tests__/integration/browser.ts +133 -0
- package/__tests__/integration/ioredis-mock.ts +194 -0
- package/__tests__/integration/sendBuffer.ts +97 -0
- package/__tests__/integration/sendFile.ts +24 -0
- package/__tests__/integration/sharedFingerprint.ts +82 -0
- package/__tests__/integration/taskFlow.ts +110 -0
- package/__tests__/jest.ts +5 -0
- package/__tests__/modules/action.ts +103 -0
- package/__tests__/modules/config.ts +19 -0
- package/__tests__/modules/utils/ensureNoTsHeaderOrSpecFiles.ts +24 -0
- package/__tests__/servers/web/allowedRequestHosts.ts +88 -0
- package/__tests__/servers/web/enableMultiples.ts +83 -0
- package/__tests__/servers/web/fileUpload.ts +79 -0
- package/__tests__/servers/web/jsonp.ts +57 -0
- package/__tests__/servers/web/nonMultiples.ts +83 -0
- package/__tests__/servers/web/rawBody.ts +208 -0
- package/__tests__/servers/web/returnErrorCodes.ts +55 -0
- package/__tests__/servers/web/routes/deepRoutes.ts +96 -0
- package/__tests__/servers/web/routes/routes.ts +579 -0
- package/__tests__/servers/web/routes/veryDeepRoutes.ts +92 -0
- package/__tests__/servers/web/web.ts +1031 -0
- package/__tests__/servers/websocket.ts +795 -0
- package/__tests__/tasks/runAction.ts +37 -0
- package/__tests__/template.ts.example +20 -0
- package/__tests__/testCliCommands/hello.ts +44 -0
- package/__tests__/testPlugin/public/plugin.html +1 -0
- package/__tests__/testPlugin/src/actions/pluginAction.ts +14 -0
- package/__tests__/testPlugin/src/bin/hello.ts +22 -0
- package/__tests__/testPlugin/src/initializers/pluginInitializer.ts +17 -0
- package/__tests__/testPlugin/src/tasks/pluginTask.ts +15 -0
- package/__tests__/testPlugin/tsconfig.json +10 -0
- package/__tests__/utils/utils.ts +492 -0
- package/app.json +23 -0
- package/bin/deploy-docs +39 -0
- package/client/ActionheroWebsocketClient.js +277 -0
- package/docker-compose.yml +73 -0
- package/package.json +24 -0
- package/public/chat.html +194 -0
- package/public/css/cosmo.css +12 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +115 -0
- package/public/javascript/.gitkeep +0 -0
- package/public/linkedSession.html +80 -0
- package/public/logo/actionhero-small.png +0 -0
- package/public/logo/actionhero.png +0 -0
- package/public/pixel.gif +0 -0
- package/public/simple.html +2 -0
- package/public/swagger.html +32 -0
- package/public/websocketLoadTest.html +322 -0
- package/src/actions/cacheTest.ts +58 -0
- package/src/actions/createChatRoom.ts +20 -0
- package/src/actions/randomNumber.ts +17 -0
- package/src/actions/recursiveAction.ts +13 -0
- package/src/actions/sendFile.ts +12 -0
- package/src/actions/sleepTest.ts +40 -0
- package/src/actions/status.ts +73 -0
- package/src/actions/swagger.ts +155 -0
- package/src/actions/validationTest.ts +36 -0
- package/src/bin/actionhero.ts +225 -0
- package/src/bin/methods/actions/list.ts +30 -0
- package/src/bin/methods/console.ts +26 -0
- package/src/bin/methods/generate/action.ts +58 -0
- package/src/bin/methods/generate/cli.ts +51 -0
- package/src/bin/methods/generate/initializer.ts +54 -0
- package/src/bin/methods/generate/plugin.ts +57 -0
- package/src/bin/methods/generate/server.ts +38 -0
- package/src/bin/methods/generate/task.ts +68 -0
- package/src/bin/methods/generate.ts +176 -0
- package/src/bin/methods/task/enqueue.ts +35 -0
- package/src/classes/action.ts +98 -0
- package/src/classes/actionProcessor.ts +463 -0
- package/src/classes/api.ts +51 -0
- package/src/classes/cli.ts +67 -0
- package/src/classes/config.ts +15 -0
- package/src/classes/connection.ts +321 -0
- package/src/classes/exceptionReporter.ts +9 -0
- package/src/classes/initializer.ts +59 -0
- package/src/classes/initializers.ts +5 -0
- package/src/classes/input.ts +9 -0
- package/src/classes/inputs.ts +34 -0
- package/src/classes/process/actionheroVersion.ts +15 -0
- package/src/classes/process/env.ts +16 -0
- package/src/classes/process/id.ts +34 -0
- package/src/classes/process/pid.ts +32 -0
- package/src/classes/process/projectRoot.ts +16 -0
- package/src/classes/process/typescript.ts +47 -0
- package/src/classes/process.ts +479 -0
- package/src/classes/server.ts +251 -0
- package/src/classes/task.ts +87 -0
- package/src/config/api.ts +107 -0
- package/src/config/errors.ts +162 -0
- package/src/config/logger.ts +113 -0
- package/src/config/plugins.ts +37 -0
- package/src/config/redis.ts +78 -0
- package/src/config/routes.ts +44 -0
- package/src/config/tasks.ts +84 -0
- package/src/config/web.ts +136 -0
- package/src/config/websocket.ts +62 -0
- package/src/index.ts +46 -0
- package/src/initializers/actions.ts +125 -0
- package/src/initializers/chatRoom.ts +214 -0
- package/src/initializers/connections.ts +124 -0
- package/src/initializers/exceptions.ts +155 -0
- package/src/initializers/params.ts +52 -0
- package/src/initializers/redis.ts +191 -0
- package/src/initializers/resque.ts +248 -0
- package/src/initializers/routes.ts +229 -0
- package/src/initializers/servers.ts +134 -0
- package/src/initializers/specHelper.ts +195 -0
- package/src/initializers/staticFile.ts +253 -0
- package/src/initializers/tasks.ts +188 -0
- package/src/modules/action.ts +89 -0
- package/src/modules/cache.ts +326 -0
- package/src/modules/chatRoom.ts +321 -0
- package/src/modules/config.ts +246 -0
- package/src/modules/log.ts +62 -0
- package/src/modules/redis.ts +93 -0
- package/src/modules/route.ts +59 -0
- package/src/modules/specHelper.ts +182 -0
- package/src/modules/task.ts +527 -0
- package/src/modules/utils/argv.ts +3 -0
- package/src/modules/utils/arrayStartingMatch.ts +21 -0
- package/src/modules/utils/arrayUnique.ts +15 -0
- package/src/modules/utils/collapseObjectToArray.ts +33 -0
- package/src/modules/utils/deepCopy.ts +3 -0
- package/src/modules/utils/ensureNoTsHeaderOrSpecFiles.ts +19 -0
- package/src/modules/utils/eventLoopDelay.ts +34 -0
- package/src/modules/utils/fileUtils.ts +119 -0
- package/src/modules/utils/filterObjectForLogging.ts +51 -0
- package/src/modules/utils/filterResponseForLogging.ts +53 -0
- package/src/modules/utils/getExternalIPAddress.ts +17 -0
- package/src/modules/utils/hashMerge.ts +63 -0
- package/src/modules/utils/isPlainObject.ts +45 -0
- package/src/modules/utils/isRunning.ts +7 -0
- package/src/modules/utils/parseCookies.ts +20 -0
- package/src/modules/utils/parseHeadersForClientAddress.ts +53 -0
- package/src/modules/utils/parseIPv6URI.ts +24 -0
- package/src/modules/utils/replaceDistWithSrc.ts +9 -0
- package/src/modules/utils/safeGlob.ts +6 -0
- package/src/modules/utils/sleep.ts +8 -0
- package/src/modules/utils/sortGlobalMiddleware.ts +17 -0
- package/src/modules/utils/sourceRelativeLinkPath.ts +29 -0
- package/src/modules/utils.ts +66 -0
- package/src/server.ts +20 -0
- package/src/servers/web.ts +894 -0
- package/src/servers/websocket.ts +304 -0
- package/src/tasks/runAction.ts +29 -0
- package/tea.yaml +9 -0
- package/templates/README.md.template +17 -0
- package/templates/action.ts.template +15 -0
- package/templates/boot.js.template +9 -0
- package/templates/cli.ts.template +15 -0
- package/templates/gitignore.template +23 -0
- package/templates/initializer.ts.template +17 -0
- package/templates/package-plugin.json.template +12 -0
- package/templates/package.json.template +45 -0
- package/templates/projectMap.txt +39 -0
- package/templates/projectServer.ts.template +20 -0
- package/templates/server.ts.template +37 -0
- package/templates/task.ts.template +16 -0
- package/templates/test/action.ts.template +13 -0
- package/templates/test/task.ts.template +20 -0
- package/tsconfig.json +11 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
import * as uuid from "uuid";
|
2
|
+
import { config, api, id, log } from "./../index";
|
3
|
+
|
4
|
+
export namespace redis {
|
5
|
+
export interface PubSubMessage {
|
6
|
+
[key: string]: any;
|
7
|
+
}
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Publish a message to all other Actionhero nodes in the cluster. Will be authenticated against `api.config.serverToken`
|
11
|
+
* ```js
|
12
|
+
* let payload = {
|
13
|
+
* messageType: 'myMessageType',
|
14
|
+
* serverId: api.id,
|
15
|
+
* serverToken: api.config.general.serverToken,
|
16
|
+
* message: 'hello!'
|
17
|
+
* }
|
18
|
+
*
|
19
|
+
* await api.redis.publish(payload)
|
20
|
+
* ```
|
21
|
+
*/
|
22
|
+
export async function publish(payload: object | Array<any>) {
|
23
|
+
const channel = config.general.channel;
|
24
|
+
const connection = api.redis.clients.client;
|
25
|
+
const stringPayload = JSON.stringify(payload);
|
26
|
+
if (connection.status !== "close" && connection.status !== "end") {
|
27
|
+
return connection.publish(channel, stringPayload);
|
28
|
+
} else {
|
29
|
+
log(`cannot send message, redis disconnected`, "error", {
|
30
|
+
channel,
|
31
|
+
payload,
|
32
|
+
});
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Invoke a command on all servers in this cluster.
|
38
|
+
*/
|
39
|
+
export async function doCluster<T>(
|
40
|
+
method: string,
|
41
|
+
args: Array<any> = [],
|
42
|
+
connectionId?: string,
|
43
|
+
waitForResponse: boolean = false,
|
44
|
+
): Promise<T extends any ? T : unknown> {
|
45
|
+
const messageId = uuid.v4();
|
46
|
+
const payload = {
|
47
|
+
messageType: "do",
|
48
|
+
serverId: id,
|
49
|
+
serverToken: config.general.serverToken,
|
50
|
+
messageId: messageId,
|
51
|
+
method: method,
|
52
|
+
connectionId: connectionId,
|
53
|
+
args: args, // [1,2,3]
|
54
|
+
};
|
55
|
+
|
56
|
+
// we need to be sure that we build the response-handling promise before sending the request to Redis
|
57
|
+
// it is possible for another node to get and work the request before we resolve our write
|
58
|
+
// see https://github.com/actionhero/actionhero/issues/1244 for more information
|
59
|
+
if (waitForResponse) {
|
60
|
+
return new Promise(async (resolve, reject) => {
|
61
|
+
const timer = setTimeout(
|
62
|
+
() => reject(new Error("RPC Timeout")),
|
63
|
+
config.general.rpcTimeout,
|
64
|
+
);
|
65
|
+
api.redis.rpcCallbacks[messageId] = { timer, resolve, reject };
|
66
|
+
try {
|
67
|
+
await redis.publish(payload);
|
68
|
+
} catch (e) {
|
69
|
+
clearTimeout(timer);
|
70
|
+
delete api.redis.rpcCallbacks[messageId];
|
71
|
+
throw e;
|
72
|
+
}
|
73
|
+
});
|
74
|
+
} else {
|
75
|
+
return redis.publish(payload) as T extends any ? T : unknown;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
export async function respondCluster(
|
80
|
+
messageId: string,
|
81
|
+
response: PubSubMessage,
|
82
|
+
) {
|
83
|
+
const payload = {
|
84
|
+
messageType: "doResponse",
|
85
|
+
serverId: id,
|
86
|
+
serverToken: config.general.serverToken,
|
87
|
+
messageId: messageId,
|
88
|
+
response: response, // args to pass back, including error
|
89
|
+
};
|
90
|
+
|
91
|
+
await redis.publish(payload);
|
92
|
+
}
|
93
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { api } from "./../index";
|
2
|
+
|
3
|
+
export const routerMethods = [
|
4
|
+
"all",
|
5
|
+
"head",
|
6
|
+
"get",
|
7
|
+
"patch",
|
8
|
+
"post",
|
9
|
+
"put",
|
10
|
+
"delete",
|
11
|
+
] as const;
|
12
|
+
export type RouteMethod = (typeof routerMethods)[number];
|
13
|
+
|
14
|
+
export type RouteType = {
|
15
|
+
path: string;
|
16
|
+
action: string;
|
17
|
+
dir?: string;
|
18
|
+
matchTrailingPathParts?: boolean;
|
19
|
+
apiVersion?: number | string;
|
20
|
+
};
|
21
|
+
|
22
|
+
export type RoutesConfig = Partial<
|
23
|
+
Record<(typeof routerMethods)[number], RouteType[]>
|
24
|
+
>;
|
25
|
+
|
26
|
+
export namespace route {
|
27
|
+
/**
|
28
|
+
* Programmatically define a route, rather than using `config.routes`. This is useful for plugins which may define routes as well.
|
29
|
+
* You can use both `routes.registerRoute` and `config.routes` in the same project.
|
30
|
+
*
|
31
|
+
* * method: HTTP verb (get, put, etc)
|
32
|
+
* * path: The route in question. Can use variables.
|
33
|
+
* * action: The action to call with this route.
|
34
|
+
* * apiVersion: The version of the action to call, if more than one.
|
35
|
+
* * matchTrailingPathParts: Allows the final segment of your route to absorb all trailing path parts in a matched variable. (ie: /api/user would match /api/user/123)
|
36
|
+
* * dir: Which folder to serve static files from (must by included in config.general.paths)
|
37
|
+
*/
|
38
|
+
export function registerRoute(
|
39
|
+
method: string,
|
40
|
+
path: string,
|
41
|
+
action: string,
|
42
|
+
apiVersion?: number | string,
|
43
|
+
matchTrailingPathParts: boolean = false,
|
44
|
+
dir?: string,
|
45
|
+
) {
|
46
|
+
const verbs =
|
47
|
+
method === "all" ? routerMethods : ([method] as [RouteMethod]);
|
48
|
+
for (const vi in verbs) {
|
49
|
+
const verb = verbs[vi];
|
50
|
+
api.routes.routes[verb].push({
|
51
|
+
path: path,
|
52
|
+
matchTrailingPathParts: matchTrailingPathParts,
|
53
|
+
action: action,
|
54
|
+
dir: dir,
|
55
|
+
apiVersion: apiVersion,
|
56
|
+
});
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
@@ -0,0 +1,182 @@
|
|
1
|
+
import * as uuid from "uuid";
|
2
|
+
import { Worker } from "node-resque";
|
3
|
+
import { api, config, task, Task, Action, Connection } from "./../index";
|
4
|
+
import { WebServer } from "../servers/web";
|
5
|
+
import { AsyncReturnType } from "type-fest";
|
6
|
+
import { TaskInputs } from "../classes/task";
|
7
|
+
|
8
|
+
export type SpecHelperConnection = Connection & {
|
9
|
+
actionCallbacks?: { [key: string]: Function };
|
10
|
+
};
|
11
|
+
|
12
|
+
export namespace specHelper {
|
13
|
+
/**
|
14
|
+
* Generate a connection to use in your tests
|
15
|
+
*/
|
16
|
+
export async function buildConnection() {
|
17
|
+
return api.specHelper.Connection.createAsync() as SpecHelperConnection;
|
18
|
+
}
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Run an action via the specHelper server.
|
22
|
+
*/
|
23
|
+
export async function runAction<A extends Action | void = void>(
|
24
|
+
actionName: string,
|
25
|
+
input: Partial<SpecHelperConnection> | Record<string, any> = {},
|
26
|
+
) {
|
27
|
+
let connection: SpecHelperConnection;
|
28
|
+
|
29
|
+
if (input.id && input.type === "testServer") {
|
30
|
+
connection = input as SpecHelperConnection;
|
31
|
+
} else {
|
32
|
+
connection = await specHelper.buildConnection();
|
33
|
+
connection.params = input;
|
34
|
+
}
|
35
|
+
|
36
|
+
connection.params.action = actionName;
|
37
|
+
connection.messageId = connection.params.messageId || uuid.v4();
|
38
|
+
|
39
|
+
const response: (A extends Action
|
40
|
+
? AsyncReturnType<A["run"]>
|
41
|
+
: { [key: string]: any }) & {
|
42
|
+
messageId?: string;
|
43
|
+
error?: NodeJS.ErrnoException | string | any;
|
44
|
+
requesterInformation?: ReturnType<WebServer["buildRequesterInformation"]>;
|
45
|
+
serverInformation?: ReturnType<WebServer["buildServerInformation"]>;
|
46
|
+
} = await new Promise((resolve) => {
|
47
|
+
api.servers.servers.testServer.processAction(connection);
|
48
|
+
connection.actionCallbacks[connection.messageId] = resolve;
|
49
|
+
});
|
50
|
+
|
51
|
+
return response;
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Mock a specHelper connection requesting a file from the server.
|
56
|
+
*/
|
57
|
+
export async function getStaticFile(file: string): Promise<any> {
|
58
|
+
const connection = await specHelper.buildConnection();
|
59
|
+
connection.params.file = file;
|
60
|
+
|
61
|
+
const response = await new Promise((resolve) => {
|
62
|
+
api.servers.servers.testServer.processFile(connection);
|
63
|
+
connection.actionCallbacks[connection.messageId] = resolve;
|
64
|
+
});
|
65
|
+
|
66
|
+
return response;
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Use the specHelper to run a task.
|
71
|
+
* Note: this only runs the task's `run()` method, and no middleware. This is faster than api.specHelper.runFullTask.
|
72
|
+
*/
|
73
|
+
export async function runTask<T extends Task | void = void>(
|
74
|
+
taskName: string,
|
75
|
+
params: object | Array<any>,
|
76
|
+
) {
|
77
|
+
if (!api.tasks.tasks[taskName]) {
|
78
|
+
throw new Error(`task ${taskName} not found`);
|
79
|
+
}
|
80
|
+
|
81
|
+
const result: (T extends Task
|
82
|
+
? AsyncReturnType<T["run"]>
|
83
|
+
: { [key: string]: any }) & {
|
84
|
+
error?: NodeJS.ErrnoException | string;
|
85
|
+
} = await api.tasks.tasks[taskName].run(params, undefined);
|
86
|
+
return result;
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Use the specHelper to run a task.
|
91
|
+
* Note: this will run a full Task worker, and will also include any middleware. This is slower than api.specHelper.runTask.
|
92
|
+
*/
|
93
|
+
export async function runFullTask<T extends Task | void = void>(
|
94
|
+
taskName: string,
|
95
|
+
params: object | Array<any>,
|
96
|
+
) {
|
97
|
+
const worker = new Worker(
|
98
|
+
{
|
99
|
+
connection: {
|
100
|
+
redis: api.redis.clients.tasks,
|
101
|
+
pkg:
|
102
|
+
api.redis.clients.tasks?.constructor?.name === "RedisMock"
|
103
|
+
? "ioredis-mock"
|
104
|
+
: "ioredis",
|
105
|
+
},
|
106
|
+
queues: (Array.isArray(config.tasks.queues)
|
107
|
+
? config.tasks.queues
|
108
|
+
: await config.tasks.queues()) || ["default"],
|
109
|
+
},
|
110
|
+
api.tasks.jobs,
|
111
|
+
);
|
112
|
+
|
113
|
+
try {
|
114
|
+
await worker.connect();
|
115
|
+
|
116
|
+
const result: (T extends Task
|
117
|
+
? AsyncReturnType<T["run"]>
|
118
|
+
: { [key: string]: any }) & {
|
119
|
+
error?: string;
|
120
|
+
} = await worker.performInline(
|
121
|
+
taskName,
|
122
|
+
Array.isArray(params) ? params : [params],
|
123
|
+
);
|
124
|
+
await worker.end();
|
125
|
+
return result;
|
126
|
+
} catch (error) {
|
127
|
+
try {
|
128
|
+
worker.end();
|
129
|
+
} catch (error) {}
|
130
|
+
throw error;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* Use the specHelper to find enqueued instances of a task
|
136
|
+
* This will return an array of instances of the task which have been enqueued either in the normal queues or delayed queues
|
137
|
+
* If a task is enqueued in a delayed queue, it will have a 'timestamp' property
|
138
|
+
* i.e. [ { class: 'regularTask', queue: 'testQueue', args: [ [Object] ] } ]
|
139
|
+
*/
|
140
|
+
export async function findEnqueuedTasks(taskName: string) {
|
141
|
+
let found: TaskInputs[] = [];
|
142
|
+
|
143
|
+
// normal queues
|
144
|
+
const queues = await api.resque.queue.queues();
|
145
|
+
for (const i in queues) {
|
146
|
+
const q = queues[i];
|
147
|
+
const length = await api.resque.queue.length(q);
|
148
|
+
const batchFound = await task.queued(q, 0, length + 1);
|
149
|
+
let matches = batchFound.filter((t) => t.class === taskName);
|
150
|
+
matches = matches.map((m) => {
|
151
|
+
m.timestamp = null;
|
152
|
+
return m;
|
153
|
+
});
|
154
|
+
found = found.concat(matches);
|
155
|
+
}
|
156
|
+
|
157
|
+
// delayed queues
|
158
|
+
const allDelayed = await api.resque.queue.allDelayed();
|
159
|
+
for (const timestamp in allDelayed) {
|
160
|
+
let matches = allDelayed[timestamp].filter((t) => t.class === taskName);
|
161
|
+
matches = matches.map((m) => {
|
162
|
+
m.timestamp = parseInt(timestamp);
|
163
|
+
return m;
|
164
|
+
});
|
165
|
+
found = found.concat(matches);
|
166
|
+
}
|
167
|
+
|
168
|
+
return found;
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* Delete all enqueued instances of a task, both in all the normal queues and all of the delayed queues
|
173
|
+
*/
|
174
|
+
export async function deleteEnqueuedTasks(taskName: string, params: {}) {
|
175
|
+
const queues = await api.resque.queue.queues();
|
176
|
+
for (const i in queues) {
|
177
|
+
const q = queues[i];
|
178
|
+
await api.resque.queue.del(q, taskName, [params]);
|
179
|
+
await api.resque.queue.delDelayed(q, taskName, [params]);
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|