psdev-task-manager 1.1.0 → 1.1.2

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/.eslintrc.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": ["plugin:@wix/cli/recommended"]
3
+ }
@@ -83,14 +83,14 @@ function taskManager() {
83
83
  * */
84
84
  const processTasksBasedOnVeloLimit = async (scheduledTasks, tasksConfig) => {
85
85
  console.log(
86
- `processTasksBasedOnVeloLimit: ${JSON.stringify(scheduledTasks)} ${JSON.stringify(tasksConfig)}`
86
+ `processTasksBasedOnVeloLimit: scheduledTasks count: ${scheduledTasks.length} tasksConfig: ${JSON.stringify(tasksConfig)}`
87
87
  );
88
88
  const toProcessTasks = getTasksToProcess({
89
89
  scheduledTasks,
90
90
  tasksConfig,
91
91
  maxDuration: CRON_JOB_MAX_DURATION_SEC,
92
92
  });
93
- console.log(`processTasksBasedOnVeloLimit: toProcessTasks: ${JSON.stringify(toProcessTasks)}`);
93
+ console.log(`processTasksBasedOnVeloLimit: toProcessTasks count: ${toProcessTasks.length}`);
94
94
  console.log(
95
95
  `[processTasksBasedOnVeloLimit] started processing: ${toProcessTasks.length} tasks`
96
96
  );
@@ -113,7 +113,7 @@ function taskManager() {
113
113
  const runScheduledTasks = async tasksConfig => {
114
114
  try {
115
115
  const scheduledTasks = await getScheduledTasks();
116
- console.log(`runScheduledTasks: scheduledTasks: ${JSON.stringify(scheduledTasks)}`);
116
+ console.log(`runScheduledTasks: scheduledTasks count: ${scheduledTasks.length}`);
117
117
  console.log(`runScheduledTasks: tasksConfig: ${JSON.stringify(tasksConfig)}`);
118
118
  if (scheduledTasks.length) {
119
119
  await processTasksBasedOnVeloLimit(scheduledTasks, tasksConfig);
@@ -169,7 +169,7 @@ const isParentTask = (task, taskConfig) => {
169
169
  };
170
170
  const filterScheduledTasksByStatus = (tasks, tasksConfig) => {
171
171
  console.log(
172
- `filterScheduledTasksByStatus: ${JSON.stringify(tasks)} ${JSON.stringify(tasksConfig)}`
172
+ `filterScheduledTasksByStatus: tasks count: ${tasks.length} tasksConfig: ${JSON.stringify(tasksConfig)}`
173
173
  );
174
174
  const filtered = tasks.filter(task => {
175
175
  if (task.status === TASK_STATUS.IN_PROGRESS) {
@@ -180,7 +180,7 @@ const filterScheduledTasksByStatus = (tasks, tasksConfig) => {
180
180
  }
181
181
  return [TASK_STATUS.PENDING, TASK_STATUS.FAILED].includes(task.status);
182
182
  });
183
- console.log(`filterScheduledTasksByStatus: filtered: ${JSON.stringify(filtered)}`);
183
+ console.log(`filterScheduledTasksByStatus: filtered count: ${filtered.length}`);
184
184
  return filtered;
185
185
  };
186
186
  const getScheduledTasks = async () => {
@@ -221,12 +221,12 @@ const getTaskScheduledChildren = async parentTaskId => {
221
221
  };
222
222
 
223
223
  const getTasksToProcess = ({ scheduledTasks, tasksConfig, maxDuration }) => {
224
- console.log('getTasksToProcess:', { scheduledTasks, tasksConfig, maxDuration });
224
+ console.log('getTasksToProcess:', { scheduledTasksCount: scheduledTasks.length, tasksConfig, maxDuration });
225
225
  const tasksToProcess = [];
226
226
  let totalDuration = 0;
227
227
  console.log(`tasksConfig is : ${JSON.stringify(tasksConfig)}`);
228
228
  const filteredScheduledTasks = filterScheduledTasksByStatus(scheduledTasks, tasksConfig);
229
- console.log(`filteredScheduledTasks is : ${JSON.stringify(filteredScheduledTasks)}`);
229
+ console.log(`filteredScheduledTasks count : ${filteredScheduledTasks.length}`);
230
230
  for (const task of filteredScheduledTasks) {
231
231
  console.log(`task is : ${JSON.stringify(task)}`);
232
232
  const taskConfig = getTaskConfig(task.name, tasksConfig);
@@ -243,7 +243,7 @@ const getTasksToProcess = ({ scheduledTasks, tasksConfig, maxDuration }) => {
243
243
  totalDuration += buffered;
244
244
  tasksToProcess.push(task);
245
245
  }
246
- console.log('getTasksToProcess: tasksToProcess:', tasksToProcess);
246
+ console.log('getTasksToProcess: tasksToProcess count:', tasksToProcess.length);
247
247
  return tasksToProcess;
248
248
  };
249
249
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "psdev-task-manager",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Task manager library",
5
5
  "keywords": [
6
6
  "task-manager"
@@ -0,0 +1,115 @@
1
+ # The Backend Code Folder
2
+
3
+ This folder contains the backend code files for your site. These files correspond to the ones found in the [**Backend**](https://support.wix.com/en/article/velo-working-with-the-velo-sidebar#backend) section of the **Public & Backend**
4
+ ![image](https://user-images.githubusercontent.com/89579857/184862813-e55cdd98-b723-4d64-b73c-593eb9af21c7.png) tab in the Velo sidebar. Add the following files to this folder to include them in your site:
5
+ + [**Web Modules:**](https://support.wix.com/en/article/velo-web-modules-calling-backend-code-from-the-frontend)
6
+ These are files that allow you to expose functions in your site's backend that you can run in your frontend code. These files require a `.jsw` file extension.
7
+ >**Note:**
8
+ >You can't change [web module permissions](https://support.wix.com/en/article/velo-about-web-module-permissions) in Wix editors when using Git Integration & Wix CLI. Instead, use the [permissions.json](#permissionsjson) file to set function permissions.
9
+
10
+ + **data.js**
11
+ A file for [adding data hooks](https://support.wix.com/en/article/velo-using-data-hooks) to your site's collections.
12
+
13
+ + **routers.js**
14
+ A file for implementing [routing and sitemap](https://support.wix.com/en/article/velo-about-routers#routing-code) functionality for your site.
15
+
16
+ + **events.js**
17
+ A file for implementing your site's [backend event handlers](https://support.wix.com/en/article/velo-backend-events).
18
+
19
+ + **http-functions.js**
20
+ A file for implementing [HTTP endpoints](https://www.wix.com/velo/reference/wix-http-functions/introduction) that are exposed on your site.
21
+
22
+ + **jobs.config**
23
+ A file for [scheduling recurring jobs](https://support.wix.com/en/article/velo-scheduling-recurring-jobs). Jobs consist of other backend code that's run at regular intervals.
24
+
25
+ + **General backend files**
26
+ JavaScript code files. You can import code from these files into any other backend file on your site. These files require a `.js` file extension.
27
+
28
+ Use the following syntax to import code from backend files:
29
+ ```js
30
+ import { myFunctionName } from 'backend/myFileName';
31
+ ```
32
+ Trying to import from the relative path in your site's repo doesn't work.
33
+
34
+ Learn more about [this repo's file structure](https://support.wix.com/en/article/velo-understanding-your-sites-github-repository-beta).
35
+
36
+ ## permissions.json
37
+ This file defines [permissions](https://support.wix.com/en/article/velo-about-web-module-permissions) for the functions in your web module files. The file contains a key, `"web-methods"`, whose value is an object that can contain keys named after the web module files in your `backend` folder. Name these keys with the following syntax: `"backend/{path to file}myFile.jsw"`. The value for each file name key is an object that can contain keys named after the functions in that file. Each function key has a value with the following format:
38
+ ```js
39
+ "backend/myFile.jsw": {
40
+ "siteOwner" : {
41
+ "invoke" : // Boolean
42
+ },
43
+ "siteMember" : {
44
+ "invoke" : // Boolean
45
+ },
46
+ "anonymous" : {
47
+ "invoke" : // Boolean
48
+ }
49
+ }
50
+ ```
51
+ These values reflect the different levels of web module function permissions. You can set them using the following options:
52
+ | |`siteOwner`|`siteMember`|`anonymous`|
53
+ |-|-----------|------------|-----------|
54
+ |Owner-only access| `true` | `false` | `false`|
55
+ |Site member access| `true` | `true` | `false`|
56
+ |Anyone can access| `true` | `true`| `true`|
57
+
58
+ The `"web-methods"` object must also contain a `"*"` key. The value for this key defines the default permissions that are applied to any function whose permissions you don't set manually.
59
+
60
+ Here is an example `permissions.json` file for a site with a backend file called `helperFunctions.jsw`. The file's functions are called `calculate`, `fetchData`, and `syncWithServer`. In this case anyone can call `calculate`, site members can call `syncWithServer`, and only site owners can call `fetchData`.
61
+
62
+ ```json
63
+ {
64
+ "web-methods": {
65
+ "*": {
66
+ "*": {
67
+ "siteOwner": {
68
+ "invoke": true
69
+ },
70
+ "siteMember": {
71
+ "invoke": true
72
+ },
73
+ "anonymous": {
74
+ "invoke": true
75
+ }
76
+ }
77
+ },
78
+ "backend/helperFunctions.jsw": {
79
+ "calculate": {
80
+ "siteOwner": {
81
+ "invoke": true
82
+ },
83
+ "siteMember": {
84
+ "invoke": true
85
+ },
86
+ "anonymous": {
87
+ "invoke": true
88
+ }
89
+ },
90
+ "fetchData": {
91
+ "siteOwner": {
92
+ "invoke": true
93
+ },
94
+ "siteMember": {
95
+ "invoke": false
96
+ },
97
+ "anonymous": {
98
+ "invoke": false
99
+ }
100
+ },
101
+ "syncWithServer": {
102
+ "siteOwner": {
103
+ "invoke": true
104
+ },
105
+ "siteMember": {
106
+ "invoke": true
107
+ },
108
+ "anonymous": {
109
+ "invoke": false
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
115
+ ```
@@ -0,0 +1,40 @@
1
+ import { response } from "wix-http-functions";
2
+ import { rootMethods } from './rootMethods';
3
+
4
+ export async function post_getResult(request) {
5
+ let options = {
6
+ headers: { "Content-Type": "application/json" }
7
+ };
8
+
9
+ try {
10
+ const methodsToExecute = await request.body.text();
11
+ /**
12
+ * Dynamically executes a method string from the request body.
13
+ *
14
+ * - `methodsToExecute` is expected to be a string, e.g.:
15
+ * "taskManager().schedule({ name: 'BadTask', data: {}, type: 'scheduled' })"
16
+ * - Only root methods defined in `rootMethods` are allowed.
17
+ * - We use `new Function(...)` to create a scoped function so that the
18
+ * root methods (taskManager, wixData, etc.) are available in the execution context.
19
+ * - The result of executing the string is returned and sent in the response.
20
+ *
21
+ * ⚠️ Warning: This executes arbitrary code strings, so only trusted input
22
+ * should be passed here.
23
+ */
24
+ const result = await (new Function(...Object.keys(rootMethods), `return ${methodsToExecute}`))(
25
+ ...Object.values(rootMethods)
26
+ );
27
+
28
+
29
+ options.body = { result };
30
+ options.status = 200;
31
+
32
+ } catch (err) {
33
+ options.body = {
34
+ message: err.message
35
+ };
36
+ options.status = 500;
37
+ }
38
+
39
+ return response(options);
40
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "web-methods": {
3
+ "*": {
4
+ "*": {
5
+ "siteOwner": {
6
+ "invoke": true
7
+ },
8
+ "siteMember": {
9
+ "invoke": true
10
+ },
11
+ "anonymous": {
12
+ "invoke": true
13
+ }
14
+ }
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,8 @@
1
+ // rootMethods.js
2
+ import { taskManager } from 'psdev-task-manager';
3
+ import wixData from 'wix-data';
4
+
5
+ export const rootMethods = {
6
+ taskManager,
7
+ wixData
8
+ };
@@ -0,0 +1,10 @@
1
+ // API Reference: https://www.wix.com/velo/reference/api-overview/introduction
2
+ // “Hello, World!” Example: https://learn-code.wix.com/en/article/hello-world
3
+
4
+ $w.onReady(function () {
5
+ // Write your JavaScript here
6
+
7
+ // To select an element by ID use: $w('#elementID')
8
+
9
+ // Click 'Preview' to run your code
10
+ });
@@ -0,0 +1,21 @@
1
+ # The Page Code Folder
2
+
3
+ This folder contains code files for each of the pages on your site as well as the [masterpage.js](https://support.wix.com/en/article/velo-working-with-the-velo-sidebar#global-site) file. The code you add to these files runs when visitors open pages on your site. These files correspond to the ones found in the [**Main Pages**](https://support.wix.com/en/article/velo-working-with-the-velo-sidebar#main-pages) section of the **Page Code** ![image](https://user-images.githubusercontent.com/89579857/184645988-6d4ee6d3-34ab-45bc-b914-5779a7de0cad.png) tab in the Velo sidebar.
4
+
5
+ When you add a page to your site in a Wix editor in your browser, a code file for that page gets added to your repo. The name of the file has 2 components: the name of the page that you define when you create it, and an internal ID string. The sections are separated by a period.
6
+
7
+ ![image](https://user-images.githubusercontent.com/89579857/188305074-6e2ee718-13b8-435d-9c75-bcb126f35718.png)
8
+
9
+ When you [add a dynamic page](https://support.wix.com/en/article/content-manager-about-dynamic-pages#adding-dynamic-pages) to your site 2 code files are added to the site's repo corresponding to the dynamic list and dynamic item pages.
10
+
11
+ When you open a page's code file, you see the same sample code that appears in these code files in Wix editors in your browser.
12
+
13
+ ![image](https://user-images.githubusercontent.com/89579857/184646571-1e14f166-2b86-4f21-bf57-83468251bca8.png)
14
+
15
+ When you delete a page in a Wix editor in your browser, the page's corresponding code file is deleted from your repo.
16
+
17
+ > **Note:**
18
+ > * You can't create new code files for pages from your IDE. To add a file, create a new page for your site in a Wix editor in your browser, and [sync](https://support.wix.com/en/article/velo-working-with-the-local-editor-beta#sync-design-changes-to-your-ide) your site with your local IDE.
19
+ > * Do not rename code files for pages. Wix uses these file names to associate the files with the appropriate pages on your site. If you rename a file, your code is ignored and a new code file is created for the page.
20
+
21
+ Learn more about [this repo's file structure](https://support.wix.com/en/article/velo-understanding-your-sites-github-repository-beta).
@@ -0,0 +1,10 @@
1
+ // API Reference: https://www.wix.com/velo/reference/api-overview/introduction
2
+ // “Hello, World!” Example: https://learn-code.wix.com/en/article/hello-world
3
+
4
+ $w.onReady(function () {
5
+ // Write your JavaScript here
6
+
7
+ // To select an element by ID use: $w('#elementID')
8
+
9
+ // Click 'Preview' to run your code
10
+ });
@@ -0,0 +1,11 @@
1
+ # The Public Code Folder
2
+
3
+ This folder contains the public code files for your site. These files correspond to the ones found in the [**Public**](https://support.wix.com/en/article/velo-working-with-the-velo-sidebar#public) section of the **Public & Backend** ![image](https://user-images.githubusercontent.com/89579857/184873215-d6042ace-4d20-40f2-ad37-1b1911302f96.png) tab in the Velo sidebar. You can import code from these files into any other file on your site.
4
+
5
+ Use the following syntax to import code from public files:
6
+ ```js
7
+ import { myFunctionName } from 'public/myFileName';
8
+ ```
9
+ Trying to import from the relative path in your site's repo doesn't work.
10
+
11
+ Learn more about [this repo's file structure](https://support.wix.com/en/article/velo-understanding-your-sites-github-repository-beta).
@@ -0,0 +1,3 @@
1
+ export const COLLECTIONS = {
2
+ TASKS: 'Tasks',
3
+ };
@@ -1,19 +0,0 @@
1
- name: Update Sites After Release Main
2
-
3
- on:
4
- workflow_dispatch:
5
-
6
- permissions:
7
- contents: write
8
- packages: write
9
-
10
- jobs:
11
- update-sites:
12
- uses: psdevteamenterprise/ci-workflows/.github/workflows/publish-and-notify.yml@main
13
-
14
- secrets:
15
- MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
16
- NPM_TOKEN: ${{ secrets.NPM_TOKEN_PUBLISH }}
17
- GH_APP_ID: ${{ secrets.GH_APP_ID }}
18
- GH_APP_PRIVATE_KEY: ${{ secrets.GH_APP_PRIVATE_KEY }}
19
- WIX_CLI_API_KEY: ${{ secrets.PS_WIX_ACCOUNT_TOKEN }}