Skip to content

Email notifications failing in cron jobs #109

Description

@jvendetti

Email notifications are not being sent when cron jobs execute, but the same code works perfectly when run manually from the command line. This affects multiple notification types including:

  • Cloudflare Analytics reports (LinkedData::Utils::Notifications.cloudflare_analytics)
  • OBO Foundry sync reports (LinkedData::Utils::Notifications.obofoundry_sync)

Steps to reproduce:

  1. Log into staging and change to /opt/ontoportal/ncbo_cron
  2. Run the OBO Foundry synchronization script manually: ./bin/ncbo_obofoundry_sync.rb

Notice that the job completes successfully with no errors:

[2025-07-23 15:23:21] INFO: Starting OBO Foundry synchronization...
I, [2025-07-23T15:23:21.712035 #1182414]  INFO -- : Found 262 OBO Foundry ontologies
I, [2025-07-23T15:23:21.712182 #1182414]  INFO -- : 208 OBO Foundry ontologies are currently active
I, [2025-07-23T15:23:21.712226 #1182414]  INFO -- : Missing OBO Foundry ontology: Biomarker Ontology (bmont)
[2025-07-23 15:23:21] INFO: OBO Foundry synchronization completed successfully in 0.75 seconds
[2025-07-23 15:23:21] INFO: OBO Foundry sync process finished

If you then log into the ncbo.developers Gmail account, you can see that the email notification was successfully issued:

Image




However, when the same job is run as a cron job, no email message is sent. I wrapped the notification code in a rescue block:

begin
  LinkedData::Utils::Notifications.obofoundry_sync(missing_onts, obsolete_onts)
rescue StandardError => e
  @logger.error("Notification failed: #{e.class}: #{e.message}")
  @logger.error("Backtrace: #{e.backtrace.first(5).join(' | ')}")
  raise
end

But the scheduler.log file shows no errors/exceptions when the code is run as a cron job:

D, [2025-07-23T15:30:00.117496 #1182494] DEBUG -- : ncbo_cron_obofoundry_sync -- Lock acquired
I, [2025-07-23T15:30:00.117809 #1182494]  INFO -- : Start generating OBO Foundry synchronization report...
I, [2025-07-23T15:30:00.532924 #1182494]  INFO -- : Found 262 OBO Foundry ontologies
I, [2025-07-23T15:30:00.533068 #1182494]  INFO -- : 208 OBO Foundry ontologies are currently active
I, [2025-07-23T15:30:00.533107 #1182494]  INFO -- : Missing OBO Foundry ontology: Biomarker Ontology (bmont)
I, [2025-07-23T15:30:00.791022 #1182494]  INFO -- : OBO Foundry synchronization report job completed in 0.671604701 sec.
I, [2025-07-23T15:30:00.791089 #1182494]  INFO -- : Finished generating OBO Foundry synchronization report

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions