puppyperpetual 1.0.2 → 1.0.4

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/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "puppyperpetual",
3
3
  "type": "module",
4
- "version": "v1.0.2",
4
+ "version": "1.0.4",
5
5
  "description": "Run stuff FOREVER! PERPETUALLY!",
6
- "main": "perpetual.js",
6
+ "main": "./src/index.js",
7
+ "exports": {
8
+ ".": "./src/index.js"
9
+ },
7
10
  "keywords": [
8
11
  "perpetual",
9
12
  "process-manager",
@@ -12,6 +12,7 @@ export class ProcessManager {
12
12
 
13
13
  this.runningProcess = null;
14
14
  this.restartScheduled = false;
15
+ this.autoRestart();
15
16
  }
16
17
 
17
18
  async startProcess(purposefulStop = false) {
@@ -148,13 +149,20 @@ export class ProcessManager {
148
149
  return;
149
150
  }
150
151
 
151
- const now = new Date();
152
- const [hour, minute] = this.options.dailyrestart_time.split(':').map(Number);
153
- const nextRestart = new Date();
154
- nextRestart.setHours(hour, minute, 0, 0);
155
- if (nextRestart < now) nextRestart.setDate(nextRestart.getDate() + 1);
152
+ const restartTimes = Array.isArray(this.options.dailyrestart_time) ? this.options.dailyrestart_time : [this.options.dailyrestart_time];
153
+ let earliestTime = null;
154
+ for (const timeStr of restartTimes) {
155
+ const [hour, minute] = timeStr.split(':').map(Number);
156
+ const now = new Date();
157
+ const restartTime = new Date();
158
+ restartTime.setHours(hour, minute, 0, 0);
159
+ if (restartTime < now) restartTime.setDate(restartTime.getDate() + 1);
160
+ if (!earliestTime || restartTime < earliestTime) {
161
+ earliestTime = restartTime;
162
+ }
163
+ }
156
164
 
157
- let timeUntilRestart = nextRestart - now;
165
+ let timeUntilRestart = earliestTime - new Date();
158
166
  if (timeUntilRestart <= 0) timeUntilRestart += 24*60*60*1000;
159
167
 
160
168
  this.logger.logSend(`Scheduled restart in ${Math.floor(timeUntilRestart / 1000 / 60)} minutes.`);
package/src/test/test.js DELETED
@@ -1,8 +0,0 @@
1
- import Perpetual from '../index.js';
2
-
3
- const perpetual = new Perpetual('test_process', {
4
- // process_cmd: 'node ./src/test/test_process.js',
5
- process_cmd: 'date',
6
- webhook_url: 'https://discord.com/api/webhooks/1460782220192256031/Fkibsumk3hWg4M6F2eCmDe_ylXaJlY_z3W9XeCMWbiw4r8zcYfQJg64YeIhaHT-7tpbT',
7
- })
8
- await perpetual.run();
@@ -1,10 +0,0 @@
1
- import log from 'puppylog';
2
-
3
- (async () => {
4
- let count = 0;
5
- while (true) {
6
- log.success("Hello, world!", count++);
7
- if (count == 10) throw new Error("Test error to check error handling");
8
- await new Promise(resolve => setTimeout(resolve, 1000));
9
- };
10
- })();