Automattic / WP-Job-Manager

Manage job listings from the WordPress admin panel, and allow users to post jobs directly to your site.
https://wpjobmanager.com
GNU General Public License v3.0
899 stars 368 forks source link

Job Alerts not sending #2768

Open joewa1980 opened 7 months ago

joewa1980 commented 7 months ago

Describe the bug Job Alerts are currently not being triggered on two separate sites. This has been tested with two new jobs added, alert emails are not being triggered. No emails in our email log. Our two sites have around 1200 email alerts, none of the alerts have been triggered.

To Reproduce Create a job, monitor the process of the job-manager-alert hook which should trigger emails to be sent out.

Expected behavior Email alerts should send when a job is added (for the alerts that match the criteria).

Isolating the problem (mark completed items with an [x]):

WordPress Environment

yscik commented 7 months ago

Hi @joewa1980!

Could you start a support ticket for this at https://wpjobmanager.com/support/, and send over more details about your site setup? Most importantly the host, other plugins, e-mail sending service used. We are not seeing this issue on other sites or on test sites, so it could be something specific to those sites.

Some other things to check:

joewa1980 commented 7 months ago

Thanks @yscik. A support ticket was created this morning.

Our email sending service isn't relevant at this stage as the emails aren't being created to even get to the point of being sent by our provider (MailGun).

Alert Duration is blank as we don't want them disabling at any point. Oddly enough though they were all disabled this morning so we re-published them all.

Job creation is handled by our custom Gravity Forms integration so we use their email notifications for new pending jobs.

I disabled the paid for Smyles plugin which helps with more options for job alerts, and takes over command of the job-manager-alert hook, and when disabled I did in fact receive my own job alert via WP Job Manager... however, none of the other alerts were triggered which is odd... and also my own alert was suddenly in a disabled state when I checked it this evening.

Last updates: WP Job Manager - Emails, Version 2.11.5, 14 December 2023 WP Job Manager - Alerts, Version 3.0.0, 2 February 2024 WP Job Manager, Version 2.2.2, 15 February 2024

joewa1980 commented 7 months ago

Are the alerts showing as active ("published") in WP-Admin -> Job Manager -> Job Alerts?

If not, could you check what value is set for the Alert Duration setting?

Does downgrading to WP Job Manager Version: 2.2.1 fix the issue?

yscik commented 7 months ago

Thanks for the extra details! Just checked and it's indeed a new bug with the alert duration, it disables the alerts right away when it's blank or 0. We are just preparing a release, I'll make sure a fix for this is included.

Meanwhile setting the Alert Duration to 1000 or something should fix the issue.

joewa1980 commented 7 months ago

Thanks @yscik - that's reassuring, I'm not going mad seeing these auto-disabling alerts!

The main issue now is the sending of job alerts which remains outstanding.

I've tested adding a new job (using the standard WP Job Manager shortcode [submit_job_form] rather than our usual Gravity Forms integration) to test if WP Job Manager is out sending ANY emails. An admin email with the subject, "New Job Listing Submitted:" was received successfully.

So currently it seems that it's an issue solely with the Job Alerts extension. If there's a previous version available I can try rolling back to that and see if emails are triggered - the job-manager-alert Cron is showing up as it should, but is not triggering the generation of emails to send.

Other non-WP Job Manager Job Alerts site emails are being sent successfully as usual.

Extra information, it might be useful:

Cron event Hook: job-manager-alert Action: WP_Job_Manager_Emails_Hooks_Job_Alerts->job_alert_email() WP_Job_Manager_Alerts\Notifier->job_manager_alert() Arguments (from one example): [ 12104 ]

yscik commented 7 months ago

I believe the two are connected: the alerts are not sending because they got disabled (even if the cron job is still there). If you re-published all the alerts, they should start sending, but let me know if I'm misunderstanding and it keeps happening even to published alerts.

joewa1980 commented 7 months ago

All alerts were republished first thing today, still no action.

A client has since posted a job, no alerts are going out.

I added a new alert to see if a newly created/published one would trigger the email alert for that account, alas no.

yscik commented 7 months ago

Are they not sending when manually running the the cron hook via WP Crontrol or a similar debug plugin, or waiting for their scheduled time? Note that an alert is only sent out daily (or less often depending on the frequency it's set to), so creating a job wouldn't trigger them right away.

joewa1980 commented 7 months ago

We have a 3hr frequency trigger using this snippet.

They're not sending when manually running the cron hook via WP Crontrol - but I'll give it a few hours to see if the custom frequency triggers them. I can see one is scheduled to run in around 45mins.

joewa1980 commented 7 months ago

I can see the Cron for my own alert ran, the time has now reset to the next scheduled event. Nothing was sent. No emails for anyone else's either.

joewa1980 commented 7 months ago

It's like the plugin is running a Cron for each alert that is set up by each user... but decides that nothing matches for some reason, so it doesn't send out an email alert... yet all of them have at least job type and category selected, and worked for years only a couple of weeks ago.

joewa1980 commented 7 months ago

I disabled third-party WP Job Manager - Emails, Version 2.11.5 (14 December 2023) and managed to get three job alerts generated and sent at the time they were set for... then the 3.1.0 Job Alerts update came through today and even though hundreds of alerts are lined up, they're seemingly being skipped and not generated or sent. Even setting the frequency to 60s, then creating a new alert yesterday to test if it would sent worked correctly. Today... not happening.

joewa1980 commented 7 months ago

For additional information, the send_count custom field within the alert I set up for myself has a value of 3, suggesting that the alert has been sent out 3 times. It hasn't been sent once, so I hope that might help narrow things down a little, as to what part of the chain isn't working?

joewa1980 commented 7 months ago

I've found when querying each user (and their associated alert), they are all empty and returning the error, "No jobs were found matching your search. Login to your account to change your alert criteria" which is found in wp-job-manager-alerts\includes\emails\class-job-alert-email.php

Looks like the plugin is not matching any of the criteria that the alerts contain and assumes it's not a match for a job alert email.

Can you think of why this might be happening? ALL alerts have the job type and categories set, either specific individual ones, or all job types and all categories. All should match the current jobs on the site.

    /**
     * Render list of matching jobs for plain text e-mail.
     *
     * @param \WP_Query $jobs Jobs query.
     *
     * @return string
     */
    private function render_jobs_plaintext( $jobs ) {
        if ( ! $jobs || ! $jobs->have_posts() ) {
            return __( 'No jobs were found matching your search. Login to your account to change your alert criteria', 'wp-job-manager-alerts' );
        }

        $job_content = '';

        while ( $jobs->have_posts() ) {
            $jobs->the_post();

            $job_content .= WP_Job_Manager_Alerts::get_template( 'content-email_job_listing.php', [] );
        }

        wp_reset_postdata();

        return $job_content;
    }
joewa1980 commented 7 months ago

The only times I can get this to send out an alert is with a new alert with no categories or keywords etc., and only one job type. It then sends out a giant list of all previous jobs - if I add a second or third job type it sends, but only those that match the first job type in the list. And again, a giant list.

There are hundreds of alerts but only 2 sending to 2 of our users. Both have gone out the past 3 days, with long lists of all previous jobs.

Really struggling with troubleshooting this. It all worked beautifully just two weeks ago.

yscik commented 7 months ago

Thanks @joewa1980, that gives a good hint of what might be wrong. I'll look into the query around tags/categories, maybe we changed something there. Just to make sure, you don't have any snippet active that might hook into the query?

joewa1980 commented 7 months ago

We have a 3hr frequency trigger using this snippet from your repository, but no others.

The WP Job Manager - Emails plugin we use (were using), Version 2.11.5, 14 December 2023, uses your hook to send out alert emails but it's been disabled for this testing as it wasn't allowing ANY alerts to be sent out when it was activated. I guess something has changed with your core plugins affecting their plugin since their last update.

If you could look into the query for job types as well that would be great as there's something funky going on that's really difficult to troubleshoot from this end.

I've been unable to work out a failsafe method that consistently creates and sends alerts. The last time we had successful alerts go out was at the beginning of February (when the last job went live). We've had 4 jobs go live since 16 February without any correct alerts being sent.

joewa1980 commented 7 months ago

This found in our error log might well be useful.

[21-Feb-2024 14:22:28 UTC] PHP Fatal error:  Uncaught Error: Call to a member function get_matching_jobs() on null in /mywebsite.com/wp-content/plugins/wp-job-manager-alerts/includes/class-notifier.php:228
Stack trace:
#0 /mywebsite.com/wp-content/plugins/wp-job-manager-emails/includes/hooks/job/class-alerts.php(263): WP_Job_Manager_Alerts\Notifier::get_matching_jobs(NULL, false)
#1 /mywebsite.com/wp-content/plugins/wp-job-manager-emails/includes/hooks/job/class-alerts.php(363): WP_Job_Manager_Emails_Hooks_Job_Alerts::get_matching_jobs(NULL, false)
#2 /mywebsite.com/wp-content/plugins/wp-job-manager-emails/includes/class-shortcodes.php(216): WP_Job_Manager_Emails_Hooks_Job_Alerts->alert_jobs(Array, '', 'alert_jobs', Object(WP_Job_Manager_Emails_Shortcodes_Job))
#3 /mywebsite.com/wp-content/plugins/wp-job-manager-emails/includes/class-shortcodes.php(555): WP_Job_Manager_Emails_Shortcodes->handler_get_value(Array, '', 'alert_jobs', true)
#4 /mywebsite.com/wp-includes/shortcodes.php(433): WP_Job_Manager_Emails_Shortcodes->handler(Array, '', 'alert_jobs')
#5 [internal function]: do_shortcode_tag(Array)
#6 /mywebsite.com/wp-includes/shortcodes.php(273): preg_replace_callback('/\\[(\\[?)(alert_...', 'do_shortcode_ta...', 'Hi [if alert_di...')
#7 /mywebsite.com/wp-content/plugins/wp-job-manager-emails/includes/class-shortcodes.php(1197): do_shortcode('Hi [if alert_di...')
#8 /mywebsite.com/wp-content/plugins/wp-job-manager-emails/includes/class-emails.php(192): WP_Job_Manager_Emails_Shortcodes->replace('Hi [if alert_di...')
#9 /mywebsite.com/wp-content/plugins/wp-job-manager-emails/includes/emails/class-job.php(18): WP_Job_Manager_Emails_Emails->setup(Object(WP_Post), 21582)
#10 /mywebsite.com/wp-content/plugins/wp-job-manager-emails/includes/class-job.php(238): WP_Job_Manager_Emails_Emails_Job->setup(Object(WP_Post), 21582)
#11 /mywebsite.com/wp-content/plugins/wp-job-manager-emails/includes/admin/ajax/class-job.php(26): WP_Job_Manager_Emails_Job->generate_email(18805, 21582, Array)
#12 /mywebsite.com/wp-content/plugins/wp-job-manager-emails/includes/admin/class-ajax.php(78): WP_Job_Manager_Emails_Admin_Ajax_Job->get_email(Array)
#13 /mywebsite.com/wp-includes/class-wp-hook.php(324): WP_Job_Manager_Emails_Admin_Ajax->generate_preview_email('')
#14 /mywebsite.com/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#15 /mywebsite.com/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#16 /mywebsite.com/wp-admin/admin-ajax.php(188): do_action('wp_ajax_jme_job...')
#17 {main}
  thrown in /mywebsite.com/wp-content/plugins/wp-job-manager-alerts/includes/class-notifier.php on line 228

Line 228 is at the end of this from class-notifier.php:

    /**
     * Match jobs to an alert.
     *
     * @deprecated 3.0.0
     *
     * @param Alert|\WP_Post $alert The job alert.
     * @param bool           $force Ignore alert frequency and cache.
     *
     * @return false|\WP_Query
     */
    public static function get_matching_jobs( $alert, $force ) {
        _deprecated_function( __METHOD__, '3.0.0', 'WP_Job_Manager_Alerts\Alert::get_matching_jobs()' );
        if ( $alert instanceof \WP_Post ) {
            $alert = Alert::load( $alert->ID );
        }

        return $alert->get_matching_jobs( $force );
    }
yscik commented 7 months ago

Looks like that error is coming from the WP Job Manager Emails plugin, but from a Preview e-mail action where an alert was somehow not selected — shouldn't be related to regular sending. But let me know if you find a similar error in the logs. While that plugin should still work, I'd disable its alert e-mail for a few days and test using the default one only.

I wonder if the problem could be related to the 3 hour frequency and some timezone issue, though that part of the query hasn't changed either recently. Do you have alerts on longer frequency that were not being sent?

Do any matching jobs show up if you click 'Results' in the my alerts frontend (the page with the [job_alerts] shortcode) as a user, or when sending manually from there with 'Send now'?

joewa1980 commented 7 months ago

"Results" button shows a list of jobs according to the criteria set (albeit the full list of jobs ever published), and the "Send Now" button correctly manually sends the email to the user (with the long list again, from noreply@mywebsite.com).

Ah yes, well spotted. The WP Job Manager Emails plugin was activated for testing purposes to see what output would be generated for each alert, but has been off the rest of the time. It is off and emails are still not being sent out by the core plugin.

It should be noted the usual hook was in use for the email previews, which worked just a few weeks ago. Their error shows a null value for get_matching_jobs().

At the moment any new or updated alerts are set to 60 seconds for testing purposes, only a couple get through as explained earlier on the GitHub thread (usually when no categories are selected, and only one job type... then a massive list comes through).

All other alerts are not being sent for all frequencies and combinations of criteria... yet were working a few weeks ago.

joewa1980 commented 7 months ago

Did that add any insight?

It seems only newly added alerts are triggering and sending out, but only matching the first of the job types (if multiple are selected), and ignoring the categories. The returned list is the full long list of jobs, rather than the specific newly added jobs. So it looks pretty confusing for users.

Alerts from when the alerts were automatically disabled (incorrectly) by the plugin and then republished are not sending.

Testing with the WP Job Manager Emails plugin on again shows the alerts not sending at all, even with new alerts.

yscik commented 7 months ago

Okay, I've put it together now, this is stemming from the alerts being incorrectly disabled earlier. Republishing them didn't set up the cron schedule correctly. We've already started a fix for that one, should be fixed in a patch release this week. (As well as the issue of all the previous alerts being included.)

For the job type / category filters not being applied correctly, I couldn't reproduce this one yet. Could you share what value do you have for these options in Job Manager settings?

For compatibility with WP Job Manager Emails, it's been working correctly during our tests, but maybe missing something. @tripflex is WP Job Manager Emails compatible with the latest WPJM (2.2.2) and Job Alerts (3.0.0+) changes? Did you have any reports about the job alert e-mails not triggering?

joewa1980 commented 7 months ago

In the process of setting up a staging site over the weekend, something in that process (using WP Staging) disables various things, such as Cron, WAF, and others.

I began testing the staging site with all plugins disabled (except obviously for those needed, plus the default Wordpress theme... and the issue persisted... but... suddenly noticed that 400 emails had correctly sent on the live site via the job-manager-alert Cron.

Looks like it needed some kind of reset to re-seat the alerts.

Tentatively things are working well, but with WP Job Manager Emails disabled I've not been testing that. We've actually now reproduced the email we used their plugin for in the core plugin now, so don't need it, unless we can guarantee it plays nicely.

So, progress. Just not 100% sure why. But not complaining!

yscik commented 7 months ago

That's good to hear, I know cron setups can be tricky sometimes. Job Alerts does have a daily hook (job-manager-alert-check-reschedule) that goes through all alerts and re-schedules them if their hook is missing, maybe it didn't run before.

joewa1980 commented 7 months ago

It's still a seemingly quite random - a new job went live yesterday and only 7 alerts went out. I'd estimate it should be at least 1000 matching alerts. Just can't see a pattern.

joewa1980 commented 7 months ago

On our sister site (virtually identical setup), a new job went live this morning, several hours before the daily check for most of the 650+ job alerts (since they were re-published a few weeks ago). Only one alert came through... and that was to me, oddly enough. No other alerts have been triggered. I can see the cron running as it should. Any thoughts? Maybe you could briefly look at our specific setup.

yscik commented 6 months ago

Yeah that's very odd. Maybe it's a performance problem, the cron job timing out or running out of memory before it can process all the alerts. I'll try to do some benchmarks in a test environment. That should also show up in the logs, could you reach out to the host and check if maybe they have separate logging for cron, and what the max execution time and memory limit PHP settings are?

joewa1980 commented 6 months ago

11 March 2024 09:44 
ELAPSED TIME: 5.6 ms

Hook Name Time (ms) Result

COMPLETED job-manager-alert 5.6

joewa1980 commented 6 months ago

PHP time limit 300 PHP memory limit 512M

joewa1980 commented 6 months ago

To help with testing, I set all alerts to draft then to publish, then cloned an existing job and published it as new. No alerts as yet but I'll report back.

yscik commented 6 months ago

Thanks! Another thing to look for is a pattern on what filters (keyword, category, job type etc) the working alerts have vs the non-working ones.

joewa1980 commented 6 months ago

The only difference with the two that went out a few days ago was they were the newest to be published, that's why l've republished them all in the hopes that they'll actually become active.

The first alert had all categories and all job types selected individually, the second alert had nothing specifically selected, so the alert effectively had all items automatically selected as per the other one.

Many others have those same settings though. But just weren't newly published.

joewa1980 commented 6 months ago

Right then, 24hrs later, the same behaviour occurred - the same 3 alerts went out despite republishing all the alerts and adding a new job.

The alerts went out to my admin account, a test user account with another email of mine, and one of our actual members. The same three users as before with the same alerts. Not any of the other hundreds of users and alerts. This is so baffling.

yscik commented 6 months ago

Hey Joe! We just released a new version, Alerts 3.1.1 with a few fixes for matching jobs for the alerts and for cron scheduling. LMK whether the update fixes the issue on your sites.

joewa1980 commented 6 months ago

Excellent, I'm excited to try it!

joewa1980 commented 6 months ago

No success, unfortunately. We've had a new job on both sites that use this set of plugins, both send out oddly minimal sets of alerts - the second platform sent out 1 for the recent job (published over 24hrs ago), yet it was a broad matching job which should have triggered hundreds of alerts.

atv2016 commented 3 months ago

@joewa1980 I know this has been 4 years ago, but did you ever manage to fix this ? I'm having similar issues.

joewa1980 commented 3 months ago

@atv2016 - Unfortunately it has always felt like an unpredictable black box of mystery, so after too many user complaints we stopped using it and had to create our own plugin to work for the specific setup we have, which ties into various hooks when particular events are triggered.