@certik/skynet 0.10.28 → 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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.29
4
+
5
+ - Added `serve.instances` parameter to `api` library to support multiple instances
6
+
3
7
  ## 0.10.28
4
8
 
5
9
  - Fixed `deploy` library aws region bug
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
@@ -512,6 +524,7 @@ function createDeploy({
512
524
  selector = {},
513
525
  region = "us-east-1",
514
526
  env = {},
527
+ count,
515
528
  check,
516
529
  schedule,
517
530
  restart,
@@ -542,6 +555,7 @@ function createDeploy({
542
555
  const nomadJobDefinition = genConfig({
543
556
  jobName,
544
557
  cron: INTERVAL_ALIASES[cron] || cron,
558
+ count,
545
559
  restart,
546
560
  workingDirectory,
547
561
  additionalEnv: env,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.10.28",
3
+ "version": "0.10.29",
4
4
  "description": "Skynet Shared JS library",
5
5
  "main": "index.js",
6
6
  "author": "CertiK Engineering",