diff --git a/.github/workflows/trigger.yml b/.github/workflows/trigger.yml index 7fb8b8b8..4afbface 100644 --- a/.github/workflows/trigger.yml +++ b/.github/workflows/trigger.yml @@ -1,3 +1,5 @@ +name: "Trigger" + on: push: branches: diff --git a/.markdownlint.json b/.markdownlint.json index a0acc242..fce6205b 100644 --- a/.markdownlint.json +++ b/.markdownlint.json @@ -6,7 +6,7 @@ "MD033": false, "MD045": false, "MD024": { - "siblings_only": true, - "allow_different_nesting": true - } + "siblings_only": true + }, + "MD046": false } diff --git a/.mega-linter.yml b/.mega-linter.yml index 7d78261e..f1a30d6b 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -8,7 +8,7 @@ DISABLE: - CSS - DOCKERFILE - REPOSITORY - # - SPELL # Uncomment to disable checks of spelling mistakes + - SPELL # Uncomment to disable checks of spelling mistakes SHOW_ELAPSED_TIME: true FILEIO_REPORTER: false # DISABLE_ERRORS: true # Uncomment if you want MegaLinter to detect errors but not block CI to pass diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5954634c..93d25782 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,15 +3,9 @@ fail_fast: true default_stages: [commit, push] repos: - repo: https://github.com/oxsecurity/megalinter - rev: v7.13.0 # Git tag specifying the hook, not mega-linter-runner, version + rev: v8.0.0 # Git tag specifying the hook, not mega-linter-runner, version hooks: - id: megalinter-incremental # Faster, less thorough stages: - commit - args: - - mega-linter-runner - - --containername=megalinter-incremental - - --flavor=documentation - - --remove-container - - --fix # npx mega-linter-runner -e 'ENABLE=MARKDOWN,YAML' -e 'SHOW_ELAPSED_TIME=true' -e "'APPLY_FIXES=all'" -e "'CLEAR_REPORT_FOLDER=true'" -e "'LOG_LEVEL=warning'" --containername megalinter-incremental --remove-container --fix --filesonly diff --git a/Dockerfile b/Dockerfile index 0d142736..d369f070 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,15 +3,15 @@ ############################################################### # build highlight jolie highlight.js -FROM node:alpine AS highlight-jolie +FROM node:20-alpine AS highlight-jolie WORKDIR /highlight-jolie COPY highlight-jolie . RUN npm install -RUN npm run build +RUN npm run build --verbose # install mdbook -FROM rust:1.65 AS builder -ENV MDBOOK_VERSION="0.4.21" +FROM rust:1.80 AS builder +ENV MDBOOK_VERSION="0.4.40" ENV ARC="x86_64-unknown-linux-musl" RUN apt-get update && \ apt-get install --no-install-recommends -y \ @@ -19,7 +19,7 @@ RUN apt-get update && \ RUN rustup target add "${ARC}" RUN cargo --version # RUN cargo install mdbook -RUN cargo install mdbook --version "${MDBOOK_VERSION}" --target "${ARC}" +RUN cargo install mdbook --version "${MDBOOK_VERSION}" --target "${ARC}" --locked # RUN cargo install mdbook-mermaid RUN cargo install mdbook-mermaid --target "${ARC}" diff --git a/book.toml b/book.toml index e91ed3ae..c4f943fe 100644 --- a/book.toml +++ b/book.toml @@ -19,10 +19,12 @@ command = "mdbook-mermaid" [output.html] additional-js = ["src/assets/js/mermaid.min.js", "src/assets/js/mermaid-init.js"] +edit-url-template = "https://github.com/jolie/docs/edit/v1.12.x/{path}" [output.html.font] enable = true woff = true -# [output.html.fold] -# enable = true +[output.html.fold] +enable = true # whether or not to enable section folding +level = 1 # the depth to start folding diff --git a/src/SUMMARY.md b/src/SUMMARY.md index c2e56cdc..492cfd0c 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -19,6 +19,7 @@ - [JSON files](tutorials/standard-library/files/json/README.md) - [XML files](tutorials/standard-library/files/xml/README.md) - [Building a File Uploader Service](tutorials/file-uploader/README.md) + - [Scheduler](tutorials/standard-library/scheduler/README.md) - [Integration Scenarios](tutorials/twitter-api/README.md) - [Twitter API](tutorials/twitter-api/README.md) - [Advanced Scenarios](tutorials/advanced-scenarios/supporting-new-protocols-in-jolie/README.md) diff --git a/src/language-tools-and-standard-library/architectural-composition/embedding/README.md b/src/language-tools-and-standard-library/architectural-composition/embedding/README.md index 7a0879d3..c31f3792 100644 --- a/src/language-tools-and-standard-library/architectural-composition/embedding/README.md +++ b/src/language-tools-and-standard-library/architectural-composition/embedding/README.md @@ -144,8 +144,8 @@ As an example let us consider the case of a calculator which offers the four ari ```jolie from runtime import Runtime -from OperationInterface import OperationInterface -from CalculatorInterface import CalculatorInterface +from .OperationInterface import OperationInterface +from .CalculatorInterface import CalculatorInterface service Calculator { diff --git a/src/language-tools-and-standard-library/rest/README.md b/src/language-tools-and-standard-library/rest/README.md index a6edbf83..a6da0249 100644 --- a/src/language-tools-and-standard-library/rest/README.md +++ b/src/language-tools-and-standard-library/rest/README.md @@ -34,7 +34,8 @@ RequestResponse: listUsers( ListUsersRequest )( ListUsersResponse ), viewUser( UserRequest )( User ) throws UserNotFound( string ), updateUser( UserWithUsername )( void ) throws UserNotFound( string ), - deleteUser( UserRequest )( void ) throws UserNotFound( string ) + deleteUser( UserRequest )( void ) throws UserNotFound( string ), + default( undefined )( string ) } service App { @@ -74,6 +75,7 @@ service App { statusCodes.UserNotFound = 404 } } + default = "default" } interfaces: UsersInterface } @@ -134,6 +136,8 @@ service App { throw( UserNotFound, request.username ) } } ] + + [ default( )( "API listens under /api/user/..." ) ] } } ``` @@ -144,6 +148,8 @@ For example, operation `viewUser` is configured to use: - `/api/user` as URI template, by `template = "/api/user"`. See the [official RFC on URI templates](https://www.rfc-editor.org/rfc/rfc6570) for more information about them. - GET as HTTP method, by `method = "get"`. +The `default` operation (optional) gets called when no operation matches to avoid getting HTTP 500 status codes. + ## Adding a router Following this approach, a specific http router, called _jester_, is introduced between the caller and the Jolie service to expose as a REST service. The http router is in charge to convert all the rest calls into the corresponding Jolie operations. diff --git a/src/tutorials/getting-started/README.md b/src/tutorials/getting-started/README.md index c8ea6913..7b7c9c15 100644 --- a/src/tutorials/getting-started/README.md +++ b/src/tutorials/getting-started/README.md @@ -64,30 +64,30 @@ Some interesting things to note: * in Jolie there are basic data types as integers, string, double, etc. In the example we exploit `int` (integers) for all the operations with the exception of operations multiplication and division where we use type `double`. You can check the other basic types [here](../../language-tools-and-standard-library/basics/interfaces/data_types/README.md); * the keyword `type` allows for the definition of structured data types; -* an operation message type is just a data type associated with it into the definition of the operation. As an example the request message of operation `sum` is `SumRequest` whereas the reply is just a `double`; +* an operation message type is just a data type associated with it into the definition of the operation. As an example the request message of operation `sum` is `SumRequest` whereas the reply is just a `int`; * a data type structure in Jolie represents a tree of nodes. As an example, type `DivRequest` contains two subnodes named `dividend` and `divisor` respectively. Both of them are `double`; -* a node in a data structure can be a vector. As an example node `term` of type `SumRequest` is a vector of `double`. `[1,*]` stands for: minimum occurrences 1 and maximum occurrences infinite. We read `term[1,*]:double` as an unbounded vector of double with at least one element; +* a node in a data structure can be a vector. As an example node `term` of type `SumRequest` is a vector of `int`. `[1,*]` stands for: minimum occurrences 1 and maximum occurrences infinite. We read `term[1,*]:int` as an unbounded vector of int with at least one element; ## Program and run a service Once we have defined the interface to implement, we are ready to define the service. Let's call the service `CalculatorService`. Edit a new module as follows: ```jolie -from CalculatorInterfaceModule import CalculatorInterface +from .CalculatorInterfaceModule import CalculatorInterface service CalculatorService { } ``` -This code permits to import the definition of the `CalculatorInterface` from module `CalculatorInterfaceModule` stored into file `CalculatorInterfaceModule.ol` and defines a service called `CalculatorService`. +This code permits to import the definition of the `CalculatorInterface` from module `CalculatorInterfaceModule` stored into file `CalculatorInterfaceModule.ol` and defines a service called `CalculatorService`. The dot prefix tells Jolie that it should find the module in the same directory. ### Defining the inputPort Unfortunately, the code above will raise an error if executed, because the service definition does not contain any listening port nor any behaviour too. Let's start by defining a listening endpoint for this service: ```jolie -rom CalculatorInterfaceModule import CalculatorInterface +rom .CalculatorInterfaceModule import CalculatorInterface service CalculatorService { @@ -110,7 +110,7 @@ Listening endpoints in Jolie are called `inputPort`. In this example we defined Now, the service is ready to receive messages on the operation specified in interface `CalculatorInterface` but we did not tell it what to do once a message is received. It is time to finalize the service by specifying the behaviour: ```jolie -from CalculatorInterfaceModule import CalculatorInterface +from .CalculatorInterfaceModule import CalculatorInterface service CalculatorService { @@ -205,7 +205,7 @@ In order to enable the service to continuously serve requests we need to specify So, let's admire our first service in Jolie! ```jolie -from CalculatorInterfaceModule import CalculatorInterface +from .CalculatorInterfaceModule import CalculatorInterface service CalculatorService { diff --git a/src/tutorials/standard-library/scheduler/README.md b/src/tutorials/standard-library/scheduler/README.md new file mode 100644 index 00000000..10069261 --- /dev/null +++ b/src/tutorials/standard-library/scheduler/README.md @@ -0,0 +1,72 @@ +# Using cron scheduler + +In this section we provide an example on how to use the scheduler library for setting cron jobs in Jolie. +Before showing the example, leu us show the target architecture. + +![scheduler.png](scheduler.png) + +The test service embeds `Scheduler` imported from package `scheduler`. +THe Scheduler Service can be programmed by setting the OneWay operation wbere receiving the alarms when they are triggered by the jobs. The jobs can be added and deleted easily, by using the API offered by the Scheduler Service. + +In the following example we report the code. Juts run it with the following command: +``` +jolie test.ol +``` + +A job which runs every minute will trigegr the alarm, and a message with the job name and the group name will be printed out. + +``` +from scheduler import Scheduler // imported the Scheduler +from console import Console + +type SchedulerCallBackRequest: void { + .jobName: string + .groupName: string +} + +interface SchedulerCallBackInterface { +OneWay: + schedulerCallback( SchedulerCallBackRequest ) // definition of the call-back operation +} + +service Test { + + execution: concurrent + + embed Scheduler as Scheduler // embedding the scheduler service + embed Console as Console + + + // internal input port for receiving alarms from Scheduler + inputPort MySelf { + location: "local" + interfaces: SchedulerCallBackInterface + } + + init { + // setting the name of the callback operation + setCallbackOperation@Scheduler( { operationName = "schedulerCallback" }) + // setting cronjob + setCronJob@Scheduler( { + jobName = "myjobname" + groupName = "myGroupName" + cronSpecs << { + second = "0" + minute = "0/1" + hour = "*" + dayOfMonth = "1/1" + month = "*" + dayOfWeek = "?" + year = "*" + } + })() + enableTimestamp@Console( true )() + } + + main { + [ schedulerCallback( request ) ] { + println@Console( request.jobName + "/" + request.groupName )() + } + } +} +``` \ No newline at end of file diff --git a/src/tutorials/standard-library/scheduler/scheduler b/src/tutorials/standard-library/scheduler/scheduler new file mode 100644 index 00000000..f3b656fa --- /dev/null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F3kWB7bj6Yjx1+6v2qy7Qune3M9Oqzt52ctjbl3anNUt3m2lVz86rl86S3vcRByXYnihlzE6gpqJyxdRrt+U+7G1JDWBqbZJl8Fby3F3vEMrmCY/6CG1YNXFYFSJHqvU+zaz2lxY3EOkGIqETqM5DLxAQg+5bbuaIP7rgKHRkQLz/XJfrb2V01P8sd2c10Kj31+jrgPAZkjvhhfhMyVn5oLfJx0rVe4NULyi56YmKm/xMxY2Rq5T/KzkoMQ77TtTc60SEbvORtnZvPnXjd98B \ No newline at end of file diff --git a/src/tutorials/standard-library/scheduler/scheduler.png b/src/tutorials/standard-library/scheduler/scheduler.png new file mode 100644 index 00000000..9e1e6cd1 Binary files /dev/null and b/src/tutorials/standard-library/scheduler/scheduler.png differ diff --git a/src/tutorials/using-dependencies/README.md b/src/tutorials/using-dependencies/README.md index 7a5e007f..3a64268f 100644 --- a/src/tutorials/using-dependencies/README.md +++ b/src/tutorials/using-dependencies/README.md @@ -50,8 +50,8 @@ The service offers three operations: `factorial`, `average` and `percentage` who In the following we report the actual definition of the `AdvancedCalculatorService`: ```jolie -from AdvancedCalculatorServiceInterfaceModule import AdvancedCalculatorInterface -from CalculatorInterfaceModule import CalculatorInterface +from .AdvancedCalculatorServiceInterfaceModule import AdvancedCalculatorInterface +from .CalculatorInterfaceModule import CalculatorInterface service AdvancedCalculatorService { diff --git a/src/tutorials/using-more-input-ports-and-protocols/https/README.md b/src/tutorials/using-more-input-ports-and-protocols/https/README.md index 6cea80eb..681e4bf7 100644 --- a/src/tutorials/using-more-input-ports-and-protocols/https/README.md +++ b/src/tutorials/using-more-input-ports-and-protocols/https/README.md @@ -34,8 +34,8 @@ The complete example follows and it may be consulted at this [link] () ```jolie -from AdvancedCalculatorServiceInterfaceModule import AdvancedCalculatorInterface -from CalculatorInterfaceModule import CalculatorInterface +from .AdvancedCalculatorServiceInterfaceModule import AdvancedCalculatorInterface +from .CalculatorInterfaceModule import CalculatorInterface interface ChuckNorrisIface { RequestResponse: random( undefined )( undefined ) diff --git a/src/tutorials/using-more-input-ports-and-protocols/soaps/README.md b/src/tutorials/using-more-input-ports-and-protocols/soaps/README.md index 15dff37d..7365e4ce 100644 --- a/src/tutorials/using-more-input-ports-and-protocols/soaps/README.md +++ b/src/tutorials/using-more-input-ports-and-protocols/soaps/README.md @@ -41,8 +41,8 @@ The complete example follows and it may be consulted at this [link] () ```jolie -from AdvancedCalculatorServiceInterfaceModule import AdvancedCalculatorInterface -from CalculatorInterfaceModule import CalculatorInterface +from .AdvancedCalculatorServiceInterfaceModule import AdvancedCalculatorInterface +from .CalculatorInterfaceModule import CalculatorInterface interface ChuckNorrisIface { RequestResponse: random( undefined )( undefined ) diff --git a/src/tutorials/using-more-input-ports-and-protocols/sodep/README.md b/src/tutorials/using-more-input-ports-and-protocols/sodep/README.md index 04dfc8f4..c8014076 100644 --- a/src/tutorials/using-more-input-ports-and-protocols/sodep/README.md +++ b/src/tutorials/using-more-input-ports-and-protocols/sodep/README.md @@ -29,8 +29,8 @@ The complete example follows and it may be consulted at this [link] () ```jolie -from AdvancedCalculatorServiceInterfaceModule import AdvancedCalculatorInterface -from CalculatorInterfaceModule import CalculatorInterface +from .AdvancedCalculatorServiceInterfaceModule import AdvancedCalculatorInterface +from .CalculatorInterfaceModule import CalculatorInterface interface ChuckNorrisIface { RequestResponse: random( undefined )( undefined ) diff --git a/src/tutorials/using-more-input-ports-and-protocols/sodeps/README.md b/src/tutorials/using-more-input-ports-and-protocols/sodeps/README.md index 58dc90ff..de327c98 100644 --- a/src/tutorials/using-more-input-ports-and-protocols/sodeps/README.md +++ b/src/tutorials/using-more-input-ports-and-protocols/sodeps/README.md @@ -31,8 +31,8 @@ The complete example follows and it may be consulted at this [link] () ```jolie -from AdvancedCalculatorServiceInterfaceModule import AdvancedCalculatorInterface -from CalculatorInterfaceModule import CalculatorInterface +from .AdvancedCalculatorServiceInterfaceModule import AdvancedCalculatorInterface +from .CalculatorInterfaceModule import CalculatorInterface interface ChuckNorrisIface { RequestResponse: random( undefined )( undefined ) diff --git a/src/tutorials/using-more-than-one-dependency/README.md b/src/tutorials/using-more-than-one-dependency/README.md index 3b09a59e..90ffece1 100644 --- a/src/tutorials/using-more-than-one-dependency/README.md +++ b/src/tutorials/using-more-than-one-dependency/README.md @@ -53,8 +53,8 @@ It is worth noting that all the response messages, now contain a new field calle In the following we report the definition of the `AdvancedCalculatorService`. ```jolie -from AdvancedCalculatorServiceInterfaceModule import AdvancedCalculatorInterface -from CalculatorInterfaceModule import CalculatorInterface +from .AdvancedCalculatorServiceInterfaceModule import AdvancedCalculatorInterface +from .CalculatorInterfaceModule import CalculatorInterface interface ChuckNorrisIface { RequestResponse: random( undefined )( undefined )