@stacksjs/cloud 0.58.57 → 0.58.58

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/dist/index.js CHANGED
@@ -1811,43 +1811,23 @@ class QueueStack {
1811
1811
  async init() {
1812
1812
  const jobsDir = path6.jobsPath();
1813
1813
  try {
1814
- const files = await fs.readdir(jobsDir);
1815
- for (const file of files) {
1816
- if (file.endsWith(".ts")) {
1817
- const filePath = path6.jobsPath(file);
1818
- const jobModule = await this.loadJobModule(filePath);
1819
- const rate = jobModule.default.rate || "* * * * *";
1820
- const schedule = Schedule.cron(this.cronScheduleFromRate(rate));
1821
- const id = `QueueRule${pascalCase(file.replace(".ts", ""))}`;
1822
- const rule = new Rule(this.scope, id, {
1823
- ruleName: `${this.props.appName}-${this.props.appEnv}-queue-rule-${slug2(file.replace(".ts", ""))}`,
1824
- schedule
1825
- });
1826
- rule.addTarget(new EcsTask({
1827
- cluster: this.props.cluster,
1828
- taskDefinition: this.props.taskDefinition,
1829
- containerOverrides: [
1830
- {
1831
- containerName: `${this.props.appName}-${this.props.appEnv}-api`,
1832
- environment: [
1833
- {
1834
- name: "QUEUE_WORKER",
1835
- value: "true"
1836
- },
1837
- {
1838
- name: "JOB",
1839
- value: file
1840
- }
1841
- ]
1842
- }
1843
- ],
1844
- retryAttempts: 3,
1845
- subnetSelection: {
1846
- subnetType: ec24.SubnetType.PUBLIC
1847
- }
1848
- }));
1849
- }
1814
+ const jobFiles = await fs.readdir(jobsDir);
1815
+ const actionFiles = await fs.readdir(actionsDir);
1816
+ const jobs = [];
1817
+ for (const file2 of jobFiles) {
1818
+ if (!file2.endsWith(".ts"))
1819
+ continue;
1820
+ const filePath = path6.jobsPath(file2);
1821
+ jobs.push(await this.loadModule(filePath));
1822
+ }
1823
+ for (const file2 of actionFiles) {
1824
+ if (!file2.endsWith(".ts"))
1825
+ continue;
1826
+ const filePath = path6.actionsPath(file2);
1827
+ jobs.push(await this.loadModule(filePath));
1850
1828
  }
1829
+ for (const job of jobs)
1830
+ await this.createQueueRule(job);
1851
1831
  } catch (err2) {
1852
1832
  console.error("Error reading the jobs directory:", err2);
1853
1833
  }
@@ -1862,9 +1842,59 @@ class QueueStack {
1862
1842
  year: parts[4]
1863
1843
  };
1864
1844
  }
1865
- async loadJobModule(filePath) {
1866
- const jobModule = await import(filePath);
1867
- return jobModule;
1845
+ async loadModule(filePath) {
1846
+ const jobModule2 = await import(filePath);
1847
+ return jobModule2;
1848
+ }
1849
+ createQueueRule(job) {
1850
+ const rate = job.default?.rate;
1851
+ if (!rate || job.default?.enabled === false)
1852
+ return;
1853
+ const schedule = Schedule.cron(this.cronScheduleFromRate(rate));
1854
+ const id = `QueueRule${pascalCase(file.replace(".ts", ""))}`;
1855
+ const rule = new Rule(this.scope, id, {
1856
+ ruleName: `${this.props.appName}-${this.props.appEnv}-queue-rule-${slug2(file.replace(".ts", ""))}`,
1857
+ schedule
1858
+ });
1859
+ rule.addTarget(new EcsTask({
1860
+ cluster: this.props.cluster,
1861
+ taskDefinition: this.props.taskDefinition,
1862
+ containerOverrides: [
1863
+ {
1864
+ containerName: `${this.props.appName}-${this.props.appEnv}-api`,
1865
+ environment: [
1866
+ {
1867
+ name: "QUEUE_WORKER",
1868
+ value: "true"
1869
+ },
1870
+ {
1871
+ name: "JOB",
1872
+ value: file
1873
+ },
1874
+ {
1875
+ name: "JOB_BACKOFF_FACTOR",
1876
+ value: jobModule.default?.backoffFactor
1877
+ },
1878
+ {
1879
+ name: "JOB_RETRIES",
1880
+ value: jobModule.default?.tries
1881
+ },
1882
+ {
1883
+ name: "JOB_INITIAL_DELAY",
1884
+ value: jobModule.default?.initialDelay
1885
+ },
1886
+ {
1887
+ name: "JOB_JITTER",
1888
+ value: jobModule.default?.jitter
1889
+ }
1890
+ ]
1891
+ }
1892
+ ],
1893
+ retryAttempts: 1,
1894
+ subnetSelection: {
1895
+ subnetType: ec24.SubnetType.PUBLIC
1896
+ }
1897
+ }));
1868
1898
  }
1869
1899
  }
1870
1900
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/cloud",
3
3
  "type": "module",
4
- "version": "0.58.57",
4
+ "version": "0.58.58",
5
5
  "description": "The Stacks cloud/serverless integration & implementation.",
6
6
  "author": "Chris Breuer",
7
7
  "license": "MIT",
@@ -55,19 +55,19 @@
55
55
  "prepublishOnly": "bun run build"
56
56
  },
57
57
  "peerDependencies": {
58
- "@aws-sdk/client-bedrock": "^3.507.0",
59
- "@aws-sdk/client-cloudformation": "^3.507.0",
60
- "@aws-sdk/client-cloudfront": "^3.507.0",
61
- "@aws-sdk/client-cloudwatch-logs": "^3.508.0",
62
- "@aws-sdk/client-ec2": "^3.507.0",
63
- "@aws-sdk/client-efs": "^3.507.0",
64
- "@aws-sdk/client-iam": "^3.507.0",
65
- "@aws-sdk/client-lambda": "^3.507.0",
66
- "@aws-sdk/client-route-53-domains": "^3.507.0",
67
- "@aws-sdk/client-s3": "^3.507.0",
68
- "@aws-sdk/client-ses": "^3.507.0",
69
- "@aws-sdk/client-sesv2": "^3.507.0",
70
- "@aws-sdk/client-ssm": "^3.507.0",
58
+ "@aws-sdk/client-bedrock": "^3.509.0",
59
+ "@aws-sdk/client-cloudformation": "^3.509.0",
60
+ "@aws-sdk/client-cloudfront": "^3.509.0",
61
+ "@aws-sdk/client-cloudwatch-logs": "^3.509.0",
62
+ "@aws-sdk/client-ec2": "^3.509.0",
63
+ "@aws-sdk/client-efs": "^3.509.0",
64
+ "@aws-sdk/client-iam": "^3.509.0",
65
+ "@aws-sdk/client-lambda": "^3.509.0",
66
+ "@aws-sdk/client-route-53-domains": "^3.509.0",
67
+ "@aws-sdk/client-s3": "^3.509.0",
68
+ "@aws-sdk/client-ses": "^3.509.0",
69
+ "@aws-sdk/client-sesv2": "^3.509.0",
70
+ "@aws-sdk/client-ssm": "^3.509.0",
71
71
  "@stacksjs/config": "latest",
72
72
  "@stacksjs/env": "latest",
73
73
  "@stacksjs/logging": "latest",
@@ -79,20 +79,20 @@
79
79
  "@stacksjs/validation": "latest"
80
80
  },
81
81
  "dependencies": {
82
- "@aws-sdk/client-bedrock": "^3.507.0",
83
- "@aws-sdk/client-cloudformation": "^3.507.0",
84
- "@aws-sdk/client-cloudfront": "^3.507.0",
85
- "@aws-sdk/client-cloudwatch-logs": "^3.508.0",
86
- "@aws-sdk/client-dynamodb": "3.507.0",
87
- "@aws-sdk/client-ec2": "^3.507.0",
88
- "@aws-sdk/client-efs": "^3.507.0",
89
- "@aws-sdk/client-iam": "^3.507.0",
90
- "@aws-sdk/client-lambda": "^3.507.0",
91
- "@aws-sdk/client-route-53-domains": "^3.507.0",
92
- "@aws-sdk/client-s3": "^3.507.0",
93
- "@aws-sdk/client-ses": "^3.507.0",
94
- "@aws-sdk/client-sesv2": "^3.507.0",
95
- "@aws-sdk/client-ssm": "^3.507.0",
82
+ "@aws-sdk/client-bedrock": "^3.509.0",
83
+ "@aws-sdk/client-cloudformation": "^3.509.0",
84
+ "@aws-sdk/client-cloudfront": "^3.509.0",
85
+ "@aws-sdk/client-cloudwatch-logs": "^3.509.0",
86
+ "@aws-sdk/client-dynamodb": "3.509.0",
87
+ "@aws-sdk/client-ec2": "^3.509.0",
88
+ "@aws-sdk/client-efs": "^3.509.0",
89
+ "@aws-sdk/client-iam": "^3.509.0",
90
+ "@aws-sdk/client-lambda": "^3.509.0",
91
+ "@aws-sdk/client-route-53-domains": "^3.509.0",
92
+ "@aws-sdk/client-s3": "^3.509.0",
93
+ "@aws-sdk/client-ses": "^3.509.0",
94
+ "@aws-sdk/client-sesv2": "^3.509.0",
95
+ "@aws-sdk/client-ssm": "^3.509.0",
96
96
  "@stacksjs/config": "latest",
97
97
  "@stacksjs/dns": "latest",
98
98
  "@stacksjs/env": "latest",
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "aws-sdk-layer",
3
- "version": "0.58.53",
3
+ "version": "0.58.57",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "aws-sdk-layer",
9
- "version": "0.58.53",
9
+ "version": "0.58.57",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
- "aws-sdk": "^2.1552.0"
12
+ "aws-sdk": "^2.1553.0"
13
13
  }
14
14
  },
15
15
  "node_modules/available-typed-arrays": {
@@ -24,9 +24,9 @@
24
24
  }
25
25
  },
26
26
  "node_modules/aws-sdk": {
27
- "version": "2.1552.0",
28
- "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1552.0.tgz",
29
- "integrity": "sha512-sRuzlCeSHXUsdLqsV/E+nPrgBn1EI3BoA38D5qfNMRcPTd9j4G8M4AyMymKyNxLoWOKLqz7xFBa801MHflGwEg==",
27
+ "version": "2.1553.0",
28
+ "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1553.0.tgz",
29
+ "integrity": "sha512-CfZaw8dR9e642aBOeFhkFL7KoQApeLR15uH2IQqfL/12snWYayAAesYh0tEaU+XbhrH0CUsf2Zro5IraEXEZMg==",
30
30
  "dependencies": {
31
31
  "buffer": "4.9.2",
32
32
  "events": "1.1.1",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-sdk-layer",
3
- "version": "0.58.57",
3
+ "version": "0.58.58",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "ISC",
@@ -10,6 +10,6 @@
10
10
  "test": "echo \"Error: no test specified\" && exit 1"
11
11
  },
12
12
  "dependencies": {
13
- "aws-sdk": "^2.1552.0"
13
+ "aws-sdk": "^2.1553.0"
14
14
  }
15
15
  }
@@ -26,57 +26,33 @@ export class QueueStack {
26
26
  const jobsDir = path.jobsPath()
27
27
 
28
28
  try {
29
- const files = await fs.readdir(jobsDir)
30
-
31
- for (const file of files) {
32
- if (file.endsWith('.ts')) {
33
- const filePath = path.jobsPath(file)
34
-
35
- // Await the loading of the job module
36
- const jobModule = await this.loadJobModule(filePath)
37
-
38
- // Now you can safely access jobModule.default.rate
39
- const rate = jobModule.default.rate || '* * * * *'
40
-
41
- // Rest of your logic here...
42
- // Convert the rate to a Schedule object
43
- const schedule = Schedule.cron(this.cronScheduleFromRate(rate))
44
-
45
- const id = `QueueRule${pascalCase(file.replace('.ts', ''))}`
46
- // Perform operations with the jobModule.default as needed
47
- const rule = new Rule(this.scope, id, {
48
- // schedule to run every second
49
- ruleName: `${this.props.appName}-${this.props.appEnv}-queue-rule-${slug(file.replace('.ts', ''))}`,
50
- schedule,
51
- })
52
-
53
- rule.addTarget(new EcsTask({
54
- cluster: this.props.cluster,
55
- taskDefinition: this.props.taskDefinition,
56
- containerOverrides: [
57
- {
58
- containerName: `${this.props.appName}-${this.props.appEnv}-api`,
59
- environment: [
60
- {
61
- name: 'QUEUE_WORKER',
62
- value: 'true',
63
- },
64
- {
65
- name: 'JOB',
66
- value: file,
67
- },
68
- ],
69
- },
70
- ],
71
-
72
- retryAttempts: 3,
73
-
74
- subnetSelection: {
75
- subnetType: ec2.SubnetType.PUBLIC, // SubnetType.PRIVATE_WITH_EGRESS
76
- },
77
- }))
78
- }
29
+ const jobFiles = await fs.readdir(jobsDir)
30
+ const actionFiles = await fs.readdir(actionsDir)
31
+ const jobs = []
32
+
33
+ // then, need to loop through all app/Jobs/*.ts and create a rule for each, potentially overwriting the Schedule.ts jobs
34
+ for (const file of jobFiles) {
35
+ if (!file.endsWith('.ts'))
36
+ continue
37
+
38
+ const filePath = path.jobsPath(file)
39
+
40
+ // Await the loading of the job module
41
+ jobs.push(await this.loadModule(filePath))
42
+ }
43
+
44
+ for (const file of actionFiles) {
45
+ if (!file.endsWith('.ts'))
46
+ continue
47
+
48
+ const filePath = path.actionsPath(file)
49
+
50
+ // Await the loading of the job module
51
+ jobs.push(await this.loadModule(filePath))
79
52
  }
53
+
54
+ for (const job of jobs)
55
+ await this.createQueueRule(job)
80
56
  }
81
57
  catch (err) {
82
58
  console.error('Error reading the jobs directory:', err)
@@ -96,9 +72,73 @@ export class QueueStack {
96
72
  }
97
73
  }
98
74
 
99
- async loadJobModule(filePath: string) {
75
+ async loadModule(filePath: string) {
100
76
  const jobModule = await import(filePath)
101
77
 
102
78
  return jobModule
103
79
  }
80
+
81
+ createQueueRule(job: any) {
82
+ // Now you can safely access job.default.rate
83
+ const rate = job.default?.rate
84
+
85
+ // if no rate or job is disabled, no need to schedule, skip
86
+ if (!rate || job.default?.enabled === false)
87
+ return
88
+
89
+ // Convert the rate to a Schedule object
90
+ const schedule = Schedule.cron(this.cronScheduleFromRate(rate))
91
+
92
+ const id = `QueueRule${pascalCase(file.replace('.ts', ''))}`
93
+
94
+ // Perform operations with the jobModule.default as needed
95
+ const rule = new Rule(this.scope, id, {
96
+ // schedule to run every second
97
+ ruleName: `${this.props.appName}-${this.props.appEnv}-queue-rule-${slug(file.replace('.ts', ''))}`,
98
+ schedule,
99
+ })
100
+
101
+ rule.addTarget(new EcsTask({
102
+ cluster: this.props.cluster,
103
+ taskDefinition: this.props.taskDefinition,
104
+ containerOverrides: [
105
+ {
106
+ containerName: `${this.props.appName}-${this.props.appEnv}-api`,
107
+ environment: [
108
+ {
109
+ name: 'QUEUE_WORKER',
110
+ value: 'true',
111
+ },
112
+ {
113
+ name: 'JOB',
114
+ value: file,
115
+ },
116
+ {
117
+ name: 'JOB_BACKOFF_FACTOR',
118
+ value: jobModule.default?.backoffFactor,
119
+ },
120
+ {
121
+ name: 'JOB_RETRIES',
122
+ value: jobModule.default?.tries,
123
+ },
124
+ {
125
+ name: 'JOB_INITIAL_DELAY',
126
+ value: jobModule.default?.initialDelay,
127
+ },
128
+ {
129
+ name: 'JOB_JITTER',
130
+ value: jobModule.default?.jitter,
131
+ },
132
+ ],
133
+ },
134
+ ],
135
+
136
+ retryAttempts: 1, // we utilize a custom retry mechanism in the job itself
137
+ // retryAttempts: jobModule.default.tries || 3,
138
+
139
+ subnetSelection: {
140
+ subnetType: ec2.SubnetType.PUBLIC, // SubnetType.PRIVATE_WITH_EGRESS
141
+ },
142
+ }))
143
+ }
104
144
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stacks-router-layer",
3
- "version": "0.58.57",
3
+ "version": "0.58.58",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -10,6 +10,6 @@
10
10
  "test": "echo \"Error: no test specified\" && exit 1"
11
11
  },
12
12
  "dependencies": {
13
- "@stacksjs/router": "^0.58.56"
13
+ "@stacksjs/router": "^0.58.57"
14
14
  }
15
15
  }