Skip to content
Snippets Groups Projects
services.md 1.81 KiB
Newer Older
  • Learn to ignore specific revisions
  • Hugo NOUTS's avatar
    Hugo NOUTS committed
    
    In order to build an automated task within our cozy-stack, we can create *services* which are javascript files called from a trigger job.
    
    
    For instance on Ecolyo, to schedule a mail that alert the user a new **monthly report** is available in the application, we add a trigger that is launched every month with a *cron* attribute. On that trigger we link a .js script then we instanciate this script with cozy-client.
    ### Manifest config example
    
    ![Manifest.webapp](monthly-service.png)
    
    File location is determined after the build, see [here](https://forge.grandlyon.com/web-et-numerique/llle_project/ecolyo/-/tree/build/services/monthlyReport).
    
    !!! note "Cron"
        See the cron definition at [cozy-stack](https://docs.cozy.io/en/cozy-stack/jobs/#cron-syntax).
    
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    ## Ecolyo services
    
    
    Located under **src\targets\services**
    
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    ### Monthly report notification
    
    #### Definition of the service
    The service will run the 3rd of each month at 10.00 am, as defined in the manifest:
    
    ```
    "monthlyReportNotification": {
          "type": "node",
          "file": "services/monthlyReportNotification/ecolyo.js",
          "trigger": "@cron 0 0 10 3 * *"
        }
    ```
    #### Main responsabilities of the service
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    The service is reponsible of sending a mail to user to warn him about the availability of a new information in the Analyse.
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    Main steps are the following:
     - Check the "sendReportNotification" attribute in the com.grandlyon.ecolyo.profile doctype. If true, service will continue, else it will stop.
     - Fetches metadata to customize the mail (Public name, instance url).
     - Build the mail.
     - Send the mail.
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    
    ### Sending mail
    
    Doc of cozy for sendmail worker: https://docs.cozy.io/en/cozy-stack/workers/#sendmail-worker
    
    !!! Send mail in local
        In local you can use the mail hog tools to see the mail sent by the stack using http://cozy.tools:8025/