@certik/skynet 0.10.26 → 0.10.29

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.29
4
+
5
+ - Added `serve.instances` parameter to `api` library to support multiple instances
6
+
7
+ ## 0.10.28
8
+
9
+ - Fixed `deploy` library aws region bug
10
+
3
11
  ## 0.10.26
4
12
 
5
13
  - Improved support for AVAX and FTM in const.js
package/api.js CHANGED
@@ -46,12 +46,29 @@ const apiKeyMiddleware = (key) => {
46
46
  return;
47
47
  }
48
48
 
49
- if (apiKey !== key) {
50
- inline.log("request has an invalid api key");
49
+ // key can be either a string or a map with multiple keys
50
+ if (typeof key === "string") {
51
+ if (apiKey !== key) {
52
+ inline.log("request has an invalid api key");
51
53
 
52
- res.status(400).send("invalid api key");
54
+ res.status(400).send("invalid api key");
53
55
 
54
- return;
56
+ return;
57
+ }
58
+
59
+ inline.log(`requested by valid key ${key.slice(0, 6)}`);
60
+ } else {
61
+ const name = key[apiKey];
62
+
63
+ if (!name) {
64
+ inline.log("request has an invalid api key");
65
+
66
+ res.status(400).send("invalid api key");
67
+
68
+ return;
69
+ }
70
+
71
+ inline.log(`requested by authorized user ${name}`);
55
72
  }
56
73
 
57
74
  next();
@@ -93,7 +110,9 @@ ${getSelectorDesc(selector)}
93
110
 
94
111
  const { verbose, ...selectorFlags } = cli.flags;
95
112
 
96
- await useLock({ name: getJobName(name, selectorFlags), ttl: 50, verbose });
113
+ if (!serve.count || serve.count === 1) {
114
+ await useLock({ name: getJobName(name, selectorFlags), ttl: 50, verbose });
115
+ }
97
116
 
98
117
  // for health check
99
118
  app.get("/", (req, res) => {
package/app.d.ts CHANGED
@@ -18,6 +18,7 @@ export type Serve = {
18
18
  apiKey: string;
19
19
  cpu: number;
20
20
  mem: number;
21
+ instances: number;
21
22
  }
22
23
 
23
24
  export type Consume = {
package/app.js CHANGED
@@ -656,6 +656,7 @@ function api({ name, routes, serve, beforeListen, env = {}, region = "us-east-1"
656
656
  region,
657
657
  env,
658
658
  schedule: "@minutely",
659
+ count: serve.instances,
659
660
  cpu: serve.cpu,
660
661
  mem: serve.mem,
661
662
  service: {
package/deploy.js CHANGED
@@ -46,6 +46,7 @@ const genConfig = ({
46
46
  workingDirectory,
47
47
  cmd,
48
48
  cron,
49
+ count,
49
50
  restart,
50
51
  cpu,
51
52
  mem,
@@ -79,6 +80,17 @@ const genConfig = ({
79
80
  }
80
81
 
81
82
  group "default" {
83
+ ${count && count > 1 ? `count = ${count}` : ""}
84
+ ${
85
+ count && count > 1
86
+ ? `# Rolling Update
87
+ update {
88
+ max_parallel = 1
89
+ min_healthy_time = "10s"
90
+ }`
91
+ : ""
92
+ }
93
+
82
94
  reschedule {
83
95
  attempts = 0
84
96
  unlimited = false
@@ -108,7 +120,6 @@ const genConfig = ({
108
120
 
109
121
  env {
110
122
  SKYNET_ENVIRONMENT="${isProduction ? "prd" : "dev"}"
111
- AWS_REGION="${region}"
112
123
  }
113
124
 
114
125
  kill_timeout = "120s"
@@ -171,7 +182,6 @@ EOH
171
182
  # available to the task when it runs.
172
183
  env {
173
184
  SKYNET_ENVIRONMENT="${isProduction ? "prd" : "dev"}"
174
- AWS_REGION="${region}"
175
185
  }
176
186
 
177
187
  # Specify the maximum resources required to run the task,
@@ -514,6 +524,7 @@ function createDeploy({
514
524
  selector = {},
515
525
  region = "us-east-1",
516
526
  env = {},
527
+ count,
517
528
  check,
518
529
  schedule,
519
530
  restart,
@@ -544,6 +555,7 @@ function createDeploy({
544
555
  const nomadJobDefinition = genConfig({
545
556
  jobName,
546
557
  cron: INTERVAL_ALIASES[cron] || cron,
558
+ count,
547
559
  restart,
548
560
  workingDirectory,
549
561
  additionalEnv: env,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.10.26",
3
+ "version": "0.10.29",
4
4
  "description": "Skynet Shared JS library",
5
5
  "main": "index.js",
6
6
  "author": "CertiK Engineering",