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,67 @@
|
|
1
|
+
import { api, Process, utils, config } from "./../../../src/index";
|
2
|
+
|
3
|
+
const actionhero = new Process();
|
4
|
+
let taskOutput = [];
|
5
|
+
const queue = "testQueue";
|
6
|
+
|
7
|
+
jest.mock("./../../../src/config/tasks.ts", () => ({
|
8
|
+
__esModule: true,
|
9
|
+
test: {
|
10
|
+
tasks: () => {
|
11
|
+
return {
|
12
|
+
_toExpand: false,
|
13
|
+
|
14
|
+
scheduler: false,
|
15
|
+
queues: async () => {
|
16
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
17
|
+
return ["queueA", "queueB"];
|
18
|
+
},
|
19
|
+
workerLogging: {},
|
20
|
+
schedulerLogging: {},
|
21
|
+
timeout: 100,
|
22
|
+
checkTimeout: 50,
|
23
|
+
minTaskProcessors: 1,
|
24
|
+
maxTaskProcessors: 1,
|
25
|
+
maxEventLoopDelay: 5,
|
26
|
+
stuckWorkerTimeout: 1000 * 60 * 60,
|
27
|
+
connectionOptions: {
|
28
|
+
tasks: {},
|
29
|
+
},
|
30
|
+
};
|
31
|
+
},
|
32
|
+
},
|
33
|
+
}));
|
34
|
+
|
35
|
+
describe("Core: Tasks", () => {
|
36
|
+
describe("custom queues function", () => {
|
37
|
+
beforeAll(async () => {
|
38
|
+
await actionhero.start();
|
39
|
+
api.resque.multiWorker.options.connection!.redis!.setMaxListeners(100);
|
40
|
+
});
|
41
|
+
|
42
|
+
afterAll(async () => {
|
43
|
+
config.tasks!.queues = [];
|
44
|
+
|
45
|
+
api.resque.multiWorker.options.minTaskProcessors = 0;
|
46
|
+
api.resque.multiWorker.options.maxTaskProcessors = 0;
|
47
|
+
|
48
|
+
await actionhero.stop();
|
49
|
+
});
|
50
|
+
|
51
|
+
beforeEach(async () => {
|
52
|
+
taskOutput = [];
|
53
|
+
await api.resque.queue.connection.redis.flushdb();
|
54
|
+
});
|
55
|
+
|
56
|
+
test("normal tasks work", async () => {
|
57
|
+
api.resque.multiWorker.start();
|
58
|
+
await utils.sleep(2000);
|
59
|
+
|
60
|
+
expect(api.resque.multiWorker.workers[0].queues).toEqual([
|
61
|
+
"queueA",
|
62
|
+
"queueB",
|
63
|
+
]);
|
64
|
+
await api.resque.multiWorker.stop();
|
65
|
+
});
|
66
|
+
});
|
67
|
+
});
|
@@ -0,0 +1,199 @@
|
|
1
|
+
import { api, Process, Task, utils, config, task } from "./../../../src/index";
|
2
|
+
|
3
|
+
const actionhero = new Process();
|
4
|
+
let taskOutput: any[] = [];
|
5
|
+
const queue = "testQueue";
|
6
|
+
|
7
|
+
jest.mock("./../../../src/config/tasks.ts", () => ({
|
8
|
+
__esModule: true,
|
9
|
+
test: {
|
10
|
+
tasks: () => {
|
11
|
+
return {
|
12
|
+
scheduler: true,
|
13
|
+
queues: ["*"],
|
14
|
+
workerLogging: {},
|
15
|
+
schedulerLogging: {},
|
16
|
+
timeout: 100,
|
17
|
+
checkTimeout: 50,
|
18
|
+
minTaskProcessors: 1,
|
19
|
+
maxTaskProcessors: 1,
|
20
|
+
maxEventLoopDelay: 5,
|
21
|
+
stuckWorkerTimeout: 1000 * 60 * 60,
|
22
|
+
connectionOptions: {
|
23
|
+
tasks: {},
|
24
|
+
},
|
25
|
+
};
|
26
|
+
},
|
27
|
+
},
|
28
|
+
}));
|
29
|
+
|
30
|
+
describe("Core: Tasks", () => {
|
31
|
+
describe("full worker flow", () => {
|
32
|
+
beforeAll(async () => {
|
33
|
+
await actionhero.start();
|
34
|
+
api.resque.multiWorker.options.connection!.redis!.setMaxListeners(100);
|
35
|
+
|
36
|
+
class RegularTask extends Task {
|
37
|
+
constructor() {
|
38
|
+
super();
|
39
|
+
this.name = "regular";
|
40
|
+
this.description = "task: regular";
|
41
|
+
this.queue = queue;
|
42
|
+
this.frequency = 0;
|
43
|
+
}
|
44
|
+
|
45
|
+
run(params: Record<string, any>) {
|
46
|
+
taskOutput.push(params.word);
|
47
|
+
return params.word;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
class PeriodicTask extends Task {
|
52
|
+
constructor() {
|
53
|
+
super();
|
54
|
+
this.name = "periodicTask";
|
55
|
+
this.description = "task: periodicTask";
|
56
|
+
this.queue = queue;
|
57
|
+
this.frequency = 100;
|
58
|
+
}
|
59
|
+
|
60
|
+
async run() {
|
61
|
+
taskOutput.push("periodicTask");
|
62
|
+
return "periodicTask";
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
class SlowTask extends Task {
|
67
|
+
constructor() {
|
68
|
+
super();
|
69
|
+
this.name = "slowTask";
|
70
|
+
this.description = "task: slowTask";
|
71
|
+
this.queue = queue;
|
72
|
+
this.frequency = 0;
|
73
|
+
}
|
74
|
+
|
75
|
+
async run() {
|
76
|
+
await utils.sleep(5000);
|
77
|
+
taskOutput.push("slowTask");
|
78
|
+
return "slowTask";
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
api.tasks.tasks.regularTask = new RegularTask();
|
83
|
+
api.tasks.tasks.periodicTask = new PeriodicTask();
|
84
|
+
api.tasks.tasks.slowTask = new SlowTask();
|
85
|
+
|
86
|
+
api.tasks.jobs.regularTask = api.tasks.jobWrapper("regularTask");
|
87
|
+
api.tasks.jobs.periodicTask = api.tasks.jobWrapper("periodicTask");
|
88
|
+
api.tasks.jobs.slowTask = api.tasks.jobWrapper("slowTask");
|
89
|
+
});
|
90
|
+
|
91
|
+
afterAll(async () => {
|
92
|
+
delete api.tasks.tasks.regularTask;
|
93
|
+
delete api.tasks.tasks.periodicTask;
|
94
|
+
delete api.tasks.tasks.slowTask;
|
95
|
+
delete api.tasks.jobs.regularTask;
|
96
|
+
delete api.tasks.jobs.periodicTask;
|
97
|
+
delete api.tasks.jobs.slowTask;
|
98
|
+
|
99
|
+
config.tasks!.queues = [];
|
100
|
+
|
101
|
+
api.resque.multiWorker.options.minTaskProcessors = 0;
|
102
|
+
api.resque.multiWorker.options.maxTaskProcessors = 0;
|
103
|
+
|
104
|
+
await actionhero.stop();
|
105
|
+
});
|
106
|
+
|
107
|
+
beforeEach(async () => {
|
108
|
+
taskOutput = [];
|
109
|
+
await api.resque.queue.connection.redis.flushdb();
|
110
|
+
});
|
111
|
+
|
112
|
+
afterEach(async () => {
|
113
|
+
await api.resque.stopScheduler();
|
114
|
+
await api.resque.stopMultiWorker();
|
115
|
+
});
|
116
|
+
|
117
|
+
test("normal tasks work", async () => {
|
118
|
+
await task.enqueue("regularTask", { word: "first" });
|
119
|
+
config.tasks!.queues = ["*"];
|
120
|
+
api.resque.multiWorker.start();
|
121
|
+
|
122
|
+
await utils.sleep(500);
|
123
|
+
|
124
|
+
expect(taskOutput[0]).toEqual("first");
|
125
|
+
await api.resque.multiWorker.stop();
|
126
|
+
});
|
127
|
+
|
128
|
+
test("delayed tasks work", async () => {
|
129
|
+
await task.enqueueIn(100, "regularTask", { word: "delayed" });
|
130
|
+
|
131
|
+
config.tasks!.queues = ["*"];
|
132
|
+
config.tasks!.scheduler = true;
|
133
|
+
await api.resque.startScheduler();
|
134
|
+
await api.resque.multiWorker.start();
|
135
|
+
|
136
|
+
await utils.sleep(1500);
|
137
|
+
expect(taskOutput[0]).toEqual("delayed");
|
138
|
+
await api.resque.multiWorker.stop();
|
139
|
+
await api.resque.stopScheduler();
|
140
|
+
});
|
141
|
+
|
142
|
+
test("recurrent tasks work", async () => {
|
143
|
+
await task.enqueueRecurrentTask("periodicTask");
|
144
|
+
|
145
|
+
config.tasks!.queues = ["*"];
|
146
|
+
config.tasks!.scheduler = true;
|
147
|
+
await api.resque.startScheduler();
|
148
|
+
await api.resque.multiWorker.start();
|
149
|
+
|
150
|
+
await utils.sleep(1500);
|
151
|
+
expect(taskOutput[0]).toEqual("periodicTask");
|
152
|
+
expect(taskOutput[1]).toEqual("periodicTask");
|
153
|
+
expect(taskOutput[2]).toEqual("periodicTask");
|
154
|
+
// the task may have run more than 3 times, we just want to ensure that it happened more than once
|
155
|
+
await api.resque.multiWorker.stop();
|
156
|
+
await api.resque.stopScheduler();
|
157
|
+
});
|
158
|
+
|
159
|
+
test("enqueuing the same task multiple times does not produce an error", async () => {
|
160
|
+
await task.enqueueRecurrentTask("periodicTask");
|
161
|
+
await task.enqueueRecurrentTask("periodicTask"); // does not throw
|
162
|
+
await task.enqueueRecurrentTask("periodicTask"); // does not throw
|
163
|
+
|
164
|
+
const taskTimes = await task.allDelayed();
|
165
|
+
expect(Object.keys(taskTimes).length).toBe(1);
|
166
|
+
const tasks = Object.values(taskTimes)[0];
|
167
|
+
expect(tasks.length).toBe(1);
|
168
|
+
});
|
169
|
+
|
170
|
+
test("trying to run an unknown job will return a failure, but not crash the server", async () => {
|
171
|
+
await new Promise(async (resolve) => {
|
172
|
+
config.tasks!.queues = ["*"];
|
173
|
+
|
174
|
+
const listener = async (
|
175
|
+
workerId: number,
|
176
|
+
queue: string,
|
177
|
+
job: any,
|
178
|
+
f: Error,
|
179
|
+
duration: number,
|
180
|
+
) => {
|
181
|
+
expect(queue).toEqual(queue);
|
182
|
+
expect(job.class).toEqual("someCrazyTask");
|
183
|
+
expect(job.queue).toEqual("testQueue");
|
184
|
+
expect(String(f)).toEqual(
|
185
|
+
'Error: No job defined for class "someCrazyTask"',
|
186
|
+
);
|
187
|
+
api.resque.multiWorker.removeListener("failure", listener);
|
188
|
+
await api.resque.multiWorker.stop();
|
189
|
+
return resolve(null);
|
190
|
+
};
|
191
|
+
|
192
|
+
api.resque.multiWorker.on("failure", listener);
|
193
|
+
|
194
|
+
await api.resque.queue.enqueue(queue, "someCrazyTask");
|
195
|
+
api.resque.multiWorker.start();
|
196
|
+
});
|
197
|
+
});
|
198
|
+
});
|
199
|
+
});
|