ECA: Cron Event - View - Message per Mail

Created on 3 March 2024, 4 months ago
Updated 2 April 2024, 3 months ago

I would like to send a notification by e-mail to a user when a certain event occurs. The event is then a view that outputs a content, this content is currently a table with several entries or the table is just empty if there is nothing current.

I have created a cronjob with ECA that analyses a view and writes the content of this view to the mail. At least in theory, because in practice the mail does not yet arrive regularly. It has already been sent, but not at the respective time of the cron.

Hence my question, what am I doing wrong at the moment?

As I said, the view simply outputs an HTML table. If there is content in the table, then the system should send out a mail. If the table has no entries, then in the best case it will not. This seems to work so far, if it sends out a mail at all.

That would be my ECA export:

uuid: 854bec77-51a2-4a86-bf06-07508024432b
langcode: en
status: true
dependencies:
  config:
    - field.field.node.agent_anlegen.body
    - field.field.node.article.body
    - field.field.node.bonus_anlegen.body
    - field.field.node.grund_anlegen.body
    - field.field.node.page.body
    - field.field.node.paragraphs_ief_example.body
    - field.storage.node.body
    - views.view.erinnerungsmodul_ansicht_einen_monat
  module:
    - eca_base
    - eca_render
id: process_tcsl0rh
modeller: bpmn_io
label: 'Erinnerungsmodul grafisch'
version: ''
weight: -10
events:
  Event_08nnbjr:
    plugin: 'eca_base:eca_cron'
    label: Cron
    configuration:
      frequency: '0 */1 * * *'
    successors:
      -
        id: Activity_0qsiv4k
        condition: ''
conditions: {  }
gateways: {  }
actions:
  Activity_0qsiv4k:
    plugin: 'eca_render_views:views'
    label: 'Views ausgeben'
    configuration:
      view_id: erinnerungsmodul_ansicht_einen_monat
      display_id: default
      arguments: ''
      name: ''
      token_name: viewergebnis
      weight: ''
      mode: append
    successors:
      -
        id: Activity_00bl874
        condition: ''
  Activity_00bl874:
    plugin: action_send_email_action
    label: 'Mail verschicken'
    configuration:
      recipient: kontakt@robertrese.de
      subject: 'Ich bin die Testnachricht'
      message: |-
        Ich bin die Testnachricht:

        [node:title]
        [user:account-name]
        [user:display-name] 
        [comment:body] 
        -----------------------------------
        [viewergebnis]
      replace_tokens: true
    successors: {  }

Sometimes I get the following error message in the log files, but I'm not sure what it means?

Failed execution of Views ausgeben (Activity_0qsiv4k) from ECA Erinnerungsmodul grafisch (process_tcsl0rh) for event Drupal\eca_base\Event\CronEvent: Failed to start the session because headers have already been sent by "/xxx/http-foundation/Response.php" at line 384..\n\n#0

Any help would be appreciated and if anyone has a template or similar function I would also be very grateful.

Supplement: So when I send the mail when the user logs in, it does so as it should. So the only thing that doesn't seem to work is the cron event. But what am I doing wrong? Thank you

Thnx Bavra

πŸ’¬ Support request
Status

Postponed: needs info

Version

1.1

Component

Documentation

Created by

πŸ‡©πŸ‡ͺGermany bavramor

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @bavramor
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    That sounds like a permission issue. If your cron job is run via drush or other means, which is not the automated_cron module from Drupal core, than the process runs as the anonymous user. And that user most likely has no permission to query the view. You may have to use the User: switch current account action right after the event.

  • πŸ‡©πŸ‡ͺGermany bavramor

    Hallo JΓΌrgen ;)

    First of all, thank you very much for your quick response. I have now made the UserSwitch after the cron event of Eca and then I check the view to send out the mail. I will now test this overnight to see if it works as desired.

    But in any case, I have already correctly surmised that the core cron is different from the ECA cron event. So it probably doesn't matter when they run separately. Only always at the same time is probably unfavourable? Or do the two have any other influence on each other and is there anything else I need to be aware of?

    Thanks for the help

    ECA Export:

    uuid: 854bec77-51a2-4a86-bf06-07508024432b
    langcode: en
    status: true
    dependencies:
      config:
        - field.field.node.agent_anlegen.body
        - field.field.node.article.body
        - field.field.node.bonus_anlegen.body
        - field.field.node.grund_anlegen.body
        - field.field.node.page.body
        - field.field.node.paragraphs_ief_example.body
        - field.storage.node.body
        - views.view.erinnerungsmodul_ansicht_einen_monat
      module:
        - eca_base
        - eca_render
        - eca_user
    id: process_tcsl0rh
    modeller: bpmn_io
    label: 'Erinnerungsmodul grafisch'
    version: ''
    weight: -10
    events:
      Event_08nnbjr:
        plugin: 'eca_base:eca_cron'
        label: Cron
        configuration:
          frequency: '0 */1 * * *'
        successors:
          -
            id: Activity_1yzoqbg
            condition: ''
    conditions: {  }
    gateways: {  }
    actions:
      Activity_0qsiv4k:
        plugin: 'eca_render_views:views'
        label: 'Views ausgeben'
        configuration:
          view_id: erinnerungsmodul_ansicht_einen_monat
          display_id: default
          arguments: ''
          name: ''
          token_name: viewergebnis
          weight: ''
          mode: append
        successors:
          -
            id: Activity_00bl874
            condition: ''
      Activity_00bl874:
        plugin: action_send_email_action
        label: 'Mail verschicken'
        configuration:
          recipient: landwehr@system-labor.de
          subject: 'Ich bin die Testnachricht'
          message: |-
            Ich bin die Testnachricht:
    
            [node:title]
            [user:account-name]
            [user:display-name] 
            [comment:body] 
            -----------------------------------
            [viewergebnis]
          replace_tokens: true
        successors: {  }
      Activity_1yzoqbg:
        plugin: eca_switch_account
        label: 'set user permissions'
        configuration:
          user_id: '1'
        successors:
          -
            id: Activity_0qsiv4k
            condition: ''
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    But in any case, I have already correctly surmised that the core cron is different from the ECA cron event. So it probably doesn't matter when they run separately. Only always at the same time is probably unfavourable? Or do the two have any other influence on each other and is there anything else I need to be aware of?

    That's not how it works. Core provides a cron API, and all modules can tell core "Hey, I have something to do when cron runs". And that's what ECA does, just exactly like all the other modules as well who implement a cron worker.

    If you wanted to have more fine grained control over which cron tasks run at what time, then there are contrib modules that allow you to configure that. But that has nothing to do with ECA.

  • πŸ‡©πŸ‡ͺGermany bavramor

    Okay, I see, thank you. The cron frequency settings in eca_base:eca_cron must have confused me a bit. So in any case ECA sends its request to the cron api and the Drupal cron actually executes it first. Ideally, both should run one after the other. Have I understood correctly now?

    Now I'll see if it works as intended.

    Thank you

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    It's the other way round. Core cron is the only process running. And core is asking all modules if they have anything to process. So, eca responds yes, just like alle other modules. It then verifies if any of the cron events in all your models are due for execution. If so, they get processed, otherwise skipped.

    The starting point is always cron from core. And it's up to you how frequently that cron executes. It's strongly recommended to turn the automated cron module off and run "drush cron" from a crontab on the os level.

  • Status changed to Postponed: needs info 3 months ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen
Production build 0.69.0 2024