@celljs/faas-adapter 3.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/LICENSE +21 -0
- package/README.md +1 -0
- package/cell-event.yml +2 -0
- package/cell.yml +0 -0
- package/lib/hooks/serve.d.ts +8 -0
- package/lib/hooks/serve.d.ts.map +1 -0
- package/lib/hooks/serve.js +47 -0
- package/lib/hooks/serve.js.map +1 -0
- package/lib/node/credentials-provider.d.ts +6 -0
- package/lib/node/credentials-provider.d.ts.map +1 -0
- package/lib/node/credentials-provider.js +30 -0
- package/lib/node/credentials-provider.js.map +1 -0
- package/lib/node/dev-event-application-entry.d.ts +2 -0
- package/lib/node/dev-event-application-entry.d.ts.map +1 -0
- package/lib/node/dev-event-application-entry.js +21 -0
- package/lib/node/dev-event-application-entry.js.map +1 -0
- package/lib/node/event/event-listener.d.ts +5 -0
- package/lib/node/event/event-listener.d.ts.map +1 -0
- package/lib/node/event/event-listener.js +21 -0
- package/lib/node/event/event-listener.js.map +1 -0
- package/lib/node/event/event-protocol.d.ts +5 -0
- package/lib/node/event/event-protocol.d.ts.map +1 -0
- package/lib/node/event/event-protocol.js +5 -0
- package/lib/node/event/event-protocol.js.map +1 -0
- package/lib/node/event/index.d.ts +3 -0
- package/lib/node/event/index.d.ts.map +1 -0
- package/lib/node/event/index.js +19 -0
- package/lib/node/event/index.js.map +1 -0
- package/lib/node/factory/cron-job-factory.d.ts +9 -0
- package/lib/node/factory/cron-job-factory.d.ts.map +1 -0
- package/lib/node/factory/cron-job-factory.js +38 -0
- package/lib/node/factory/cron-job-factory.js.map +1 -0
- package/lib/node/factory/index.d.ts +2 -0
- package/lib/node/factory/index.d.ts.map +1 -0
- package/lib/node/factory/index.js +18 -0
- package/lib/node/factory/index.js.map +1 -0
- package/lib/node/index.d.ts +7 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +23 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/module.d.ts +4 -0
- package/lib/node/module.d.ts.map +1 -0
- package/lib/node/module.js +6 -0
- package/lib/node/module.js.map +1 -0
- package/lib/node/regin-provider.d.ts +5 -0
- package/lib/node/regin-provider.d.ts.map +1 -0
- package/lib/node/regin-provider.js +26 -0
- package/lib/node/regin-provider.js.map +1 -0
- package/lib/node/timer/clock.d.ts +8 -0
- package/lib/node/timer/clock.d.ts.map +1 -0
- package/lib/node/timer/clock.js +28 -0
- package/lib/node/timer/clock.js.map +1 -0
- package/lib/node/timer/cron-job.d.ts +13 -0
- package/lib/node/timer/cron-job.d.ts.map +1 -0
- package/lib/node/timer/cron-job.js +40 -0
- package/lib/node/timer/cron-job.js.map +1 -0
- package/lib/node/timer/events.d.ts +16 -0
- package/lib/node/timer/events.d.ts.map +1 -0
- package/lib/node/timer/events.js +92 -0
- package/lib/node/timer/events.js.map +1 -0
- package/lib/node/timer/index.d.ts +4 -0
- package/lib/node/timer/index.d.ts.map +1 -0
- package/lib/node/timer/index.js +20 -0
- package/lib/node/timer/index.js.map +1 -0
- package/lib/node/timer/timer-protocol.d.ts +7 -0
- package/lib/node/timer/timer-protocol.d.ts.map +1 -0
- package/lib/node/timer/timer-protocol.js +5 -0
- package/lib/node/timer/timer-protocol.js.map +1 -0
- package/lib/node/utils.d.ts +4 -0
- package/lib/node/utils.d.ts.map +1 -0
- package/lib/node/utils.js +12 -0
- package/lib/node/utils.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +4 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +48 -0
- package/src/hooks/serve.ts +46 -0
- package/src/node/credentials-provider.ts +20 -0
- package/src/node/dev-event-application-entry.ts +20 -0
- package/src/node/event/event-listener.ts +10 -0
- package/src/node/event/event-protocol.ts +5 -0
- package/src/node/event/index.ts +2 -0
- package/src/node/factory/cron-job-factory.ts +23 -0
- package/src/node/factory/index.ts +1 -0
- package/src/node/index.ts +6 -0
- package/src/node/module.ts +4 -0
- package/src/node/regin-provider.ts +15 -0
- package/src/node/timer/clock.ts +17 -0
- package/src/node/timer/cron-job.ts +46 -0
- package/src/node/timer/events.ts +115 -0
- package/src/node/timer/index.ts +3 -0
- package/src/node/timer/timer-protocol.ts +10 -0
- package/src/node/utils.ts +7 -0
- package/src/package.spec.ts +4 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Emitter = exports.Event = void 0;
|
|
4
|
+
var Event;
|
|
5
|
+
(function (Event) {
|
|
6
|
+
const disposable = { dispose() { } };
|
|
7
|
+
Event.None = function () { return disposable; };
|
|
8
|
+
})(Event = exports.Event || (exports.Event = {}));
|
|
9
|
+
class CallbackList {
|
|
10
|
+
add(callback, bucket) {
|
|
11
|
+
if (!this.callbacks) {
|
|
12
|
+
this.callbacks = [];
|
|
13
|
+
}
|
|
14
|
+
this.callbacks.push(callback);
|
|
15
|
+
if (Array.isArray(bucket)) {
|
|
16
|
+
bucket.push({ dispose: () => this.remove(callback) });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
remove(callback) {
|
|
20
|
+
if (!this.callbacks) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
for (let i = 0, len = this.callbacks.length; i < len; i++) {
|
|
24
|
+
if (this.callbacks[i] === callback) {
|
|
25
|
+
this.callbacks.splice(i, 1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
invoke(...args) {
|
|
30
|
+
if (!this.callbacks) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
const ret = [];
|
|
34
|
+
const callbacks = this.callbacks.slice(0);
|
|
35
|
+
for (let i = 0, len = callbacks.length; i < len; i++) {
|
|
36
|
+
try {
|
|
37
|
+
ret.push(callbacks[i].apply(this, args));
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
console.error(e);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return ret;
|
|
44
|
+
}
|
|
45
|
+
isEmpty() {
|
|
46
|
+
return !this.callbacks || this.callbacks.length === 0;
|
|
47
|
+
}
|
|
48
|
+
dispose() {
|
|
49
|
+
this.callbacks = undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
class Emitter {
|
|
53
|
+
get event() {
|
|
54
|
+
if (!this._event) {
|
|
55
|
+
this._event = (listener, disposables) => {
|
|
56
|
+
if (!this.callbacks) {
|
|
57
|
+
this.callbacks = new CallbackList();
|
|
58
|
+
}
|
|
59
|
+
this.callbacks.add(listener);
|
|
60
|
+
const result = {
|
|
61
|
+
dispose: () => {
|
|
62
|
+
if (!this.callbacks) {
|
|
63
|
+
// disposable is disposed after emitter is disposed.
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.callbacks.remove(listener);
|
|
67
|
+
result.dispose = Emitter._noop;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
if (Array.isArray(disposables)) {
|
|
71
|
+
disposables.push(result);
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return this._event;
|
|
77
|
+
}
|
|
78
|
+
async fire(event) {
|
|
79
|
+
if (this.callbacks) {
|
|
80
|
+
await Promise.all(this.callbacks.invoke.call(this.callbacks, event));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
dispose() {
|
|
84
|
+
if (this.callbacks) {
|
|
85
|
+
this.callbacks.dispose();
|
|
86
|
+
this.callbacks = undefined;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.Emitter = Emitter;
|
|
91
|
+
Emitter._noop = function () { };
|
|
92
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/node/timer/events.ts"],"names":[],"mappings":";;;AAOA,IAAiB,KAAK,C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MAAM,CAAC;YAClB,CAAC,CAAC;SACL;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAAQ;QACf,IAAI,IAAI,CAAC,SAAS,EAAE;YAChB,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;SACxE;IACL,CAAC;IAED,OAAO;QACH,IAAI,IAAI,CAAC,SAAS,EAAE;YAChB,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;YACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;SAC9B;IACL,CAAC;;AA/CL,0BAgDC;AA9CkB,aAAK,GAAG,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/timer/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./clock"), exports);
|
|
18
|
+
__exportStar(require("./cron-job"), exports);
|
|
19
|
+
__exportStar(require("./timer-protocol"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/timer/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,6CAA2B;AAC3B,mDAAiC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer-protocol.d.ts","sourceRoot":"","sources":["../../../src/node/timer/timer-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,eAAO,MAAM,KAAK,eAAkB,CAAC;AAErC,MAAM,WAAW,KAAK;IAElB,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAE7B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer-protocol.js","sourceRoot":"","sources":["../../../src/node/timer/timer-protocol.ts"],"names":[],"mappings":";;;AAEa,QAAA,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/node/utils.ts"],"names":[],"mappings":"AAEA,yBAAiB,SAAS,CAAC;IACvB,SAAgB,iCAAiC,YAEhD;CACJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FaaSUtils = void 0;
|
|
4
|
+
const config_util_1 = require("@celljs/core/lib/common/config/config-util");
|
|
5
|
+
var FaaSUtils;
|
|
6
|
+
(function (FaaSUtils) {
|
|
7
|
+
function getCallbackWaitsForEmptyEventLoop() {
|
|
8
|
+
return config_util_1.ConfigUtil.get('cell.cloud.function.callbackWaitsForEmptyEventLoop', false);
|
|
9
|
+
}
|
|
10
|
+
FaaSUtils.getCallbackWaitsForEmptyEventLoop = getCallbackWaitsForEmptyEventLoop;
|
|
11
|
+
})(FaaSUtils = exports.FaaSUtils || (exports.FaaSUtils = {}));
|
|
12
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/node/utils.ts"],"names":[],"mappings":";;;AAAA,4EAAwE;AAExE,IAAiB,SAAS,CAIzB;AAJD,WAAiB,SAAS;IACtB,SAAgB,iCAAiC;QAC7C,OAAO,wBAAU,CAAC,GAAG,CAAU,oDAAoD,EAAE,KAAK,CAAC,CAAC;IAChG,CAAC;IAFe,2CAAiC,oCAEhD,CAAA;AACL,CAAC,EAJgB,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAIzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=package.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.d.ts","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IAElC,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@celljs/faas-adapter",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "lib/node/index.js",
|
|
6
|
+
"typings": "lib/node/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@celljs/cli-common": "3.0.0",
|
|
9
|
+
"@celljs/cli-service": "3.0.0",
|
|
10
|
+
"@celljs/cloud": "3.0.0",
|
|
11
|
+
"@celljs/core": "3.0.0",
|
|
12
|
+
"@celljs/schedule": "3.0.0",
|
|
13
|
+
"@celljs/web": "3.0.0",
|
|
14
|
+
"cron": "^1.8.2"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"cell-component"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/cellbang/cell.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/cellbang/cell/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/cellbang/cell",
|
|
31
|
+
"files": [
|
|
32
|
+
"lib",
|
|
33
|
+
"src",
|
|
34
|
+
"cell.yml",
|
|
35
|
+
"cell-event.yml"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"lint": "cell-component lint",
|
|
39
|
+
"build": "cell-component build",
|
|
40
|
+
"watch": "cell-component watch",
|
|
41
|
+
"clean": "cell-component clean",
|
|
42
|
+
"test": "cell-component test:js"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@celljs/component": "3.0.0"
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "c0ef8d269e33a795406bcbb240cac4b845c6c24c"
|
|
48
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ServeContext } from '@celljs/cli-service';
|
|
2
|
+
import { ConfigUtil } from '@celljs/cli-common/lib/utils/config-util';
|
|
3
|
+
export class Deferred {
|
|
4
|
+
resolve: () => void;
|
|
5
|
+
reject: (err?: any) => void; // tslint:disable-line
|
|
6
|
+
|
|
7
|
+
promise = new Promise<void>((resolve, reject) => {
|
|
8
|
+
this.resolve = resolve;
|
|
9
|
+
this.reject = reject;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export async function after(context: ServeContext) {
|
|
13
|
+
const { app, entryContextProvider, cfg } = context;
|
|
14
|
+
|
|
15
|
+
if (!entryContextProvider) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const mode = ConfigUtil.getBackendConfig(cfg).mode || [];
|
|
19
|
+
if (!mode.includes('event')) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
let handler: (event: any, context: any, callback: any) => Promise<void>;
|
|
23
|
+
const compileDeferred = new Deferred();
|
|
24
|
+
|
|
25
|
+
context.compiler.hooks.done.tap('WebServe', () => {
|
|
26
|
+
entryContextProvider().then(async (ctx: any) => {
|
|
27
|
+
handler = ctx.handler;
|
|
28
|
+
console.log('Access any route to trigger event function execution.');
|
|
29
|
+
compileDeferred.resolve();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
app.all('*', async (req: any, res: any) => {
|
|
34
|
+
await compileDeferred.promise;
|
|
35
|
+
const event = req.query['event'] || '{}';
|
|
36
|
+
try {
|
|
37
|
+
await handler(event, {}, () => {});
|
|
38
|
+
res.end('Event function executed successfully.');
|
|
39
|
+
} catch (error) {
|
|
40
|
+
res.end('Event function failed to execute.');
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DefaultCredentialsProvider } from '@celljs/cloud/lib/node';
|
|
2
|
+
import { Component } from '@celljs/core';
|
|
3
|
+
import { Credentials, CredentialsProvider } from '@celljs/cloud';
|
|
4
|
+
|
|
5
|
+
@Component({ id: CredentialsProvider, rebind: true })
|
|
6
|
+
export class FaaSCredentialsProvider extends DefaultCredentialsProvider {
|
|
7
|
+
|
|
8
|
+
override async provide(): Promise<Credentials | undefined> {
|
|
9
|
+
const credentials = await super.provide();
|
|
10
|
+
if (credentials) {
|
|
11
|
+
return credentials;
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
accessKeyId: process.env.MALAGU_ACCESS_KEY_ID!,
|
|
15
|
+
accessKeySecret: process.env.MALAGU_ACCESS_KEY_SECRET!,
|
|
16
|
+
token: process.env.MALAGU_TOKEN
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { container } from '@celljs/core/lib/common/container/dynamic-container';
|
|
2
|
+
import { Application } from '@celljs/core/lib/common/application/application-protocol';
|
|
3
|
+
import { ContainerProvider } from '@celljs/core/lib/common/container/container-provider';
|
|
4
|
+
import { FaaSEventListener } from './event/event-protocol';
|
|
5
|
+
|
|
6
|
+
let listeners: FaaSEventListener<any, void>[];
|
|
7
|
+
|
|
8
|
+
async function start() {
|
|
9
|
+
const c = await container;
|
|
10
|
+
ContainerProvider.set(c);
|
|
11
|
+
await c.get<Application>(Application).start();
|
|
12
|
+
listeners = c.getAll<FaaSEventListener<any, void>>(FaaSEventListener);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const startPromise = start();
|
|
16
|
+
|
|
17
|
+
export async function handler(event: string, context: any) {
|
|
18
|
+
await startPromise;
|
|
19
|
+
await Promise.all(listeners.map(l => l.onTrigger(event)));
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Component } from '@celljs/core';
|
|
2
|
+
import { FaaSEventListener } from './event-protocol';
|
|
3
|
+
|
|
4
|
+
@Component(FaaSEventListener)
|
|
5
|
+
export class NoOpEventListener implements FaaSEventListener<{}, void> {
|
|
6
|
+
async onTrigger(event: {}): Promise<void> {
|
|
7
|
+
// NoOp
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Autowired, Component, Value } from '@celljs/core';
|
|
2
|
+
import { CronJob } from 'cron';
|
|
3
|
+
import { CronJobFactory, CronJobOptions, DefaultCronJobFactory } from '@celljs/schedule';
|
|
4
|
+
import { Clock, FaaSCronJob } from '../timer';
|
|
5
|
+
|
|
6
|
+
@Component({ id: CronJobFactory, rebind: true })
|
|
7
|
+
export class FaaSCronJobFactory extends DefaultCronJobFactory {
|
|
8
|
+
|
|
9
|
+
@Autowired(Clock)
|
|
10
|
+
protected readonly clock: Clock;
|
|
11
|
+
|
|
12
|
+
@Value('mode')
|
|
13
|
+
protected readonly mode: string[];
|
|
14
|
+
|
|
15
|
+
override create(options: CronJobOptions): CronJob {
|
|
16
|
+
if (this.mode.includes('remote')) {
|
|
17
|
+
return new FaaSCronJob(this.clock, {...this.defaultCronJobOptions, ...options });
|
|
18
|
+
} else {
|
|
19
|
+
return super.create(options);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cron-job-factory';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DefaultRegionProvider } from '@celljs/cloud/lib/node';
|
|
2
|
+
import { Component } from '@celljs/core';
|
|
3
|
+
import { RegionProvider } from '@celljs/cloud';
|
|
4
|
+
|
|
5
|
+
@Component({ id: RegionProvider, rebind: true })
|
|
6
|
+
export class FaaSRegionProvider extends DefaultRegionProvider {
|
|
7
|
+
|
|
8
|
+
override async provide(): Promise<string | undefined> {
|
|
9
|
+
const region = await super.provide();
|
|
10
|
+
if (region) {
|
|
11
|
+
return region;
|
|
12
|
+
}
|
|
13
|
+
return process.env.MALAGU_REGION;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Component } from '@celljs/core';
|
|
2
|
+
import { Emitter, Event } from './events';
|
|
3
|
+
import { Clock } from './timer-protocol';
|
|
4
|
+
|
|
5
|
+
@Component(Clock)
|
|
6
|
+
export class ClockImpl implements Clock {
|
|
7
|
+
protected onTickEmitter = new Emitter<void>();
|
|
8
|
+
|
|
9
|
+
get onTick(): Event<void> {
|
|
10
|
+
return this.onTickEmitter.event;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async tick(): Promise<void> {
|
|
14
|
+
await this.onTickEmitter.fire();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Disposable } from '@celljs/core';
|
|
2
|
+
import { CronJob, CronTime } from 'cron';
|
|
3
|
+
import { CronJobOptions } from '@celljs/schedule';
|
|
4
|
+
import { Clock } from './timer-protocol';
|
|
5
|
+
|
|
6
|
+
export class FaaSCronJob extends CronJob {
|
|
7
|
+
|
|
8
|
+
protected tickDisposable?: Disposable;
|
|
9
|
+
|
|
10
|
+
constructor(protected readonly clock: Clock, options: CronJobOptions) {
|
|
11
|
+
super(options);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
protected async fireOnTickAsync() {
|
|
15
|
+
const callbacks = (this as any)._callbacks;
|
|
16
|
+
const context = (this as any).context;
|
|
17
|
+
const onComplete = (this as any).onComplete;
|
|
18
|
+
await Promise.all(callbacks.map((callback: any) => callback.call(context, onComplete)));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
override start() {
|
|
22
|
+
if (this.running) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.tickDisposable = this.clock.onTick(async () => {
|
|
27
|
+
|
|
28
|
+
const cronTime: CronTime = (this as any).cronTime;
|
|
29
|
+
const timeout = cronTime.getTimeout();
|
|
30
|
+
if (timeout <= 60 * 1000) {
|
|
31
|
+
await this.fireOnTickAsync();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
override stop() {
|
|
38
|
+
this.tickDisposable?.dispose();
|
|
39
|
+
this.running = false;
|
|
40
|
+
const onComplete = (this as any).onComplete;
|
|
41
|
+
if (typeof onComplete === 'function') {
|
|
42
|
+
onComplete();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Disposable } from '@celljs/core';
|
|
2
|
+
|
|
3
|
+
export interface Event<T> {
|
|
4
|
+
|
|
5
|
+
(listener: (e: T) => any, disposables?: Disposable[]): Disposable;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export namespace Event {
|
|
9
|
+
const disposable = { dispose() { } };
|
|
10
|
+
export const None: Event<any> = function () { return disposable; };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class CallbackList {
|
|
14
|
+
|
|
15
|
+
private callbacks?: Function[];
|
|
16
|
+
|
|
17
|
+
add(callback: Function, bucket?: Disposable[]): void {
|
|
18
|
+
if (!this.callbacks) {
|
|
19
|
+
this.callbacks = [];
|
|
20
|
+
}
|
|
21
|
+
this.callbacks.push(callback);
|
|
22
|
+
|
|
23
|
+
if (Array.isArray(bucket)) {
|
|
24
|
+
bucket.push({ dispose: () => this.remove(callback) });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public remove(callback: Function): void {
|
|
29
|
+
if (!this.callbacks) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (let i = 0, len = this.callbacks.length; i < len; i++) {
|
|
34
|
+
if (this.callbacks[i] === callback) {
|
|
35
|
+
this.callbacks.splice(i, 1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public invoke(...args: any[]): any[] {
|
|
41
|
+
if (!this.callbacks) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const ret: any[] = [];
|
|
46
|
+
const callbacks = this.callbacks.slice(0);
|
|
47
|
+
|
|
48
|
+
for (let i = 0, len = callbacks.length; i < len; i++) {
|
|
49
|
+
try {
|
|
50
|
+
ret.push(callbacks[i].apply(this, args));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error(e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return ret;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public isEmpty(): boolean {
|
|
59
|
+
return !this.callbacks || this.callbacks.length === 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public dispose(): void {
|
|
63
|
+
this.callbacks = undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export class Emitter<T> {
|
|
68
|
+
|
|
69
|
+
private static _noop = function () { };
|
|
70
|
+
|
|
71
|
+
private _event: Event<T> | undefined;
|
|
72
|
+
private callbacks: CallbackList | undefined;
|
|
73
|
+
|
|
74
|
+
get event(): Event<T> {
|
|
75
|
+
if (!this._event) {
|
|
76
|
+
this._event = (listener: (e: T) => any, disposables?: Disposable[]) => {
|
|
77
|
+
if (!this.callbacks) {
|
|
78
|
+
this.callbacks = new CallbackList();
|
|
79
|
+
}
|
|
80
|
+
this.callbacks.add(listener);
|
|
81
|
+
|
|
82
|
+
const result: Disposable = {
|
|
83
|
+
dispose: () => {
|
|
84
|
+
if (!this.callbacks) {
|
|
85
|
+
// disposable is disposed after emitter is disposed.
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this.callbacks.remove(listener);
|
|
90
|
+
result.dispose = Emitter._noop;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
if (Array.isArray(disposables)) {
|
|
94
|
+
disposables.push(result);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return result;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return this._event;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async fire(event: T): Promise<void> {
|
|
104
|
+
if (this.callbacks) {
|
|
105
|
+
await Promise.all(this.callbacks.invoke.call(this.callbacks, event));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
dispose() {
|
|
110
|
+
if (this.callbacks) {
|
|
111
|
+
this.callbacks.dispose();
|
|
112
|
+
this.callbacks = undefined;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|