psdev-task-manager 1.1.8 → 1.1.10

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.
@@ -0,0 +1,30 @@
1
+ name: Update Sites After Release Main
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: write
11
+ packages: write
12
+
13
+ jobs:
14
+ update-sites:
15
+ uses: psdevteamenterprise/ci-workflows/.github/workflows/update-and-notify.yml@main
16
+ with:
17
+ npm_packages_to_update: "[{repo: 'Hisense-Wix/velo-npm'}]"
18
+ sites_to_update: "[{repo: 'psdevteamenterprise/external-template', secret: 'WIX_SR_API_KEY'},
19
+ {repo: 'psdevteamenterprise/internal', secret: 'WIX_SR_API_KEY'},
20
+ {repo: 'psdevteamenterprise/tests-site', secret: 'WIX_PS_API_KEY'},
21
+ {repo: 'psdevteamenterprise/hisense_mexico', secret: 'WIX_HM_API_KEY'},
22
+ ]"
23
+ secrets:
24
+ GH_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
25
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN_PUBLISH }}
26
+ GH_APP_ID: ${{ secrets.GH_APP_ID }}
27
+ GH_APP_PRIVATE_KEY: ${{ secrets.GH_APP_PRIVATE_KEY }}
28
+ WIX_SR_API_KEY: ${{secrets.WIX_SR_API_KEY}}
29
+ WIX_PS_API_KEY: ${{secrets.WIX_PS_API_KEY}}
30
+ WIX_HM_API_KEY: ${{secrets.WIX_HM_API_KEY}}
@@ -1,4 +1,4 @@
1
- const { withDuration, withSuccessRateLogs } = require('psdev-utils/shared'); // Import from shared module to avoid frontend dependencies in backend
1
+ const { withDuration, withSuccessRateLogs } = require('psdev-utils');
2
2
 
3
3
  const { TASK_STATUS, CRON_JOB_MAX_DURATION_SEC, TASK_MAX_TRIES } = require('./consts');
4
4
  const { scheduleChildTasksAndUpdateParent } = require('./parentChildTasks/handler');
@@ -75,8 +75,9 @@ function taskManager() {
75
75
  }
76
76
  const isFailedAfterAllRetries = amountOfRetries >= TASK_MAX_TRIES;
77
77
  if (isFailedAfterAllRetries) {
78
+
78
79
  //Only throw error if task is permanently failed, otherwise we have retry mechanism
79
- throw new Error(errMsg);
80
+ throw new Error("task failed after all retries: " + errMsg);
80
81
  }
81
82
  }
82
83
  },
@@ -122,7 +123,6 @@ function taskManager() {
122
123
  try {
123
124
  const scheduledTasks = await getScheduledTasks();
124
125
  console.log(`runScheduledTasks: scheduledTasks count: ${scheduledTasks.length}`);
125
- console.log(`runScheduledTasks: tasksConfig: ${JSON.stringify(tasksConfig)}`);
126
126
  if (scheduledTasks.length) {
127
127
  await processTasksBasedOnVeloLimit(scheduledTasks, tasksConfig);
128
128
  } else {
@@ -2,7 +2,6 @@ const { COLLECTIONS, COLLECTIONS_FIELDS } = require('../../public/consts'); // n
2
2
  const { wixData, wixCollections } = require('../elevated-modules');
3
3
 
4
4
  const { TASK_STATUS, TASK_TYPE, TASK_MAX_TRIES } = require('./consts');
5
-
6
5
  /**
7
6
  * Generic function to create a collection if it doesn't exist
8
7
  * @param {string} collectionId - The ID of the collection to create
@@ -168,9 +167,6 @@ const isParentTask = (task, taskConfig) => {
168
167
  return true;
169
168
  };
170
169
  const filterScheduledTasksByStatus = (tasks, tasksConfig) => {
171
- console.log(
172
- `filterScheduledTasksByStatus: tasks count: ${tasks.length} tasksConfig: ${JSON.stringify(tasksConfig)}`
173
- );
174
170
  const shouldIncludeTask = (task, taskConfig) => {
175
171
  console.log(`filterScheduledTasksByStatus: task: ${JSON.stringify(task)}`);
176
172
  console.log(`filterScheduledTasksByStatus: taskConfig: ${JSON.stringify(taskConfig)}`);
@@ -195,6 +191,18 @@ const filterScheduledTasksByStatus = (tasks, tasksConfig) => {
195
191
  console.log(`filterScheduledTasksByStatus: filtered count: ${filtered.length}`);
196
192
  return filtered;
197
193
  };
194
+ const queryAllItems = async query => {
195
+ console.log('start query');
196
+ let oldResults = await query.find();
197
+ console.log(`found items: ${oldResults.items.length}`);
198
+ const allItems = oldResults.items;
199
+ while (oldResults.hasNext()) {
200
+ oldResults = await oldResults.next();
201
+ allItems.push(...oldResults.items);
202
+ }
203
+ console.log(`all items count : ${allItems.length}`);
204
+ return allItems;
205
+ };
198
206
  const getScheduledTasks = async () => {
199
207
  try {
200
208
  const baseQuery = wixData.query(COLLECTIONS.TASKS);
@@ -204,13 +212,12 @@ const getScheduledTasks = async () => {
204
212
  const eventBasedTasksQuery = baseQuery
205
213
  .eq('type', TASK_TYPE.EVENT)
206
214
  .eq('status', TASK_STATUS.FAILED);
207
- return await scheduledTasksQuery
215
+ const toRunQuery = scheduledTasksQuery
208
216
  .or(eventBasedTasksQuery)
209
217
  .lt('amountOfRetries', TASK_MAX_TRIES)
210
218
  .ascending('_updatedDate')
211
- .limit(1000)
212
- .find()
213
- .then(result => result.items);
219
+ .limit(1000);
220
+ return await queryAllItems(toRunQuery);
214
221
  } catch (error) {
215
222
  throw new Error(`[getScheduledTasks] failed with error: ${error.message}`);
216
223
  }
@@ -240,13 +247,11 @@ const getTasksToProcess = ({ scheduledTasks, tasksConfig, maxDuration }) => {
240
247
  });
241
248
  const tasksToProcess = [];
242
249
  let totalDuration = 0;
243
- console.log(`tasksConfig is : ${JSON.stringify(tasksConfig)}`);
244
250
  const filteredScheduledTasks = filterScheduledTasksByStatus(scheduledTasks, tasksConfig);
245
251
  console.log(`filteredScheduledTasks count : ${filteredScheduledTasks.length}`);
246
252
  for (const task of filteredScheduledTasks) {
247
253
  console.log(`task is : ${JSON.stringify(task)}`);
248
254
  const taskConfig = getTaskConfig(task.name, tasksConfig);
249
- console.log(`taskConfig is : ${JSON.stringify(taskConfig)}`);
250
255
  const estimated = taskConfig?.estimatedDurationSec;
251
256
  if (!estimated) {
252
257
  const errMsg = `[getTasksToProcess] estimatedDurationSec is not defined for task ${task.name}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "psdev-task-manager",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "Task manager library",
5
5
  "keywords": [
6
6
  "task-manager"
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "@wix/data": "^1.0.273",
30
30
  "@wix/essentials": "^0.1.27",
31
- "psdev-utils": "1.1.1"
31
+ "psdev-utils": "1.1.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@eslint/js": "^9.12.0",