Client needs to automatically import data from a Google spreadsheet into a Custom Post Type.
I wrote up a quick (largely borrowed) python script to convert to Google Spreadsheet to a CSV file with the desired headers.
Found this pro plugin from Smackcoders called WP CSV Import Pro, which can run the CSV to CPT imports on a schedule.
The challenge has been getting CRON to play nicely with the plugin.
System cron is running
Server cron is running, man. And my manually set Cron Jobs are running:
$ sudo service cron status
● cron.service - Regular background program processing daemon
Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2018-03-30 02:57:50 UTC; 4 months 7 days ago
Docs: man:cron(8)
Main PID: 1394 (cron)
Tasks: 1
Memory: 296.2M
CPU: 2h 48min 26.415s
CGroup: /system.slice/cron.service
└─1394 /usr/sbin/cron -f
Aug 06 17:45:01 ubuntu-s-1vcpu-1gb-nyc1-client CRON[29038]: pam_unix(cron:session): session closed for user web
Aug 06 18:00:01 ubuntu-s-1vcpu-1gb-nyc1-client CRON[29075]: pam_unix(cron:session): session opened for user web by (uid=0)
Aug 06 18:00:01 ubuntu-s-1vcpu-1gb-nyc1-client CRON[29074]: pam_unix(cron:session): session opened for user web by (uid=0)
Aug 06 18:00:01 ubuntu-s-1vcpu-1gb-nyc1-client CRON[29076]: (web) CMD (cd /srv/www/client.org/current/scripts && ./convert_google_docs.py --path /srv/www/ny
Aug 06 18:00:01 ubuntu-s-1vcpu-1gb-nyc1-client CRON[29077]: (web) CMD (cd /srv/www/client.org/current && wp cron event run --due-now > /dev/null 2>&1)
Aug 06 18:00:02 ubuntu-s-1vcpu-1gb-nyc1-client CRON[29075]: pam_unix(cron:session): session closed for user web
Aug 06 18:00:02 ubuntu-s-1vcpu-1gb-nyc1-client CRON[29074]: pam_unix(cron:session): session closed for user web
Aug 06 18:01:01 ubuntu-s-1vcpu-1gb-nyc1-client CRON[29080]: pam_unix(cron:session): session opened for user web by (uid=0)
Aug 06 18:01:01 ubuntu-s-1vcpu-1gb-nyc1-client CRON[29081]: (web) CMD (wget wp_home/wp-cron.php > /dev/null 2>&1)
Aug 06 18:01:01 ubuntu-s-1vcpu-1gb-nyc1-client CRON[29080]: pam_unix(cron:session): session closed for user web
The one you see on the 4th line: convert_google_docs.py is updating the counties.csv file which is supposed to update the County CPTs, and does when I run the import manually.
Installed a plugin called WP Control to view WP Cron jobs and the Smack Coders jobds are listed:
smack_uci_cron_scheduler
smack_uci_cron_scheduled
smack_uci_email_schedule
smack_uci_replace_inline
smack_uci_image_schedule
Here’s output of the CRON Log:
$sudo grep CRON /var/log/syslog
Sep 4 06:30:01 mps CRON[16743]: (web) CMD (cd /srv/www/client.org/current && wp cron event run --due-now > /dev/null 2>&1)
Sep 4 06:39:01 mps CRON[16758]: (root) CMD ( [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi)
Sep 4 06:45:01 mps CRON[16921]: (web) CMD (cd /srv/www/client.org/current && wp cron event run --due-now > /dev/null 2>&1)
Sep 4 07:00:01 mps CRON[16939]: (web) CMD (cd /srv/www/client.org/current && wp cron event run --due-now > /dev/null 2>&1)
Sep 4 07:09:01 mps CRON[16952]: (root) CMD ( [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi)
Sep 4 07:15:01 mps CRON[17051]: (web) CMD (cd /srv/www/client.org/current && wp cron event run --due-now > /dev/null 2>&1)
Sep 4 07:17:01 mps CRON[17059]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Sep 4 07:30:01 mps CRON[17077]: (web) CMD (cd /srv/www/client.org/current && wp cron event run --due-now > /dev/null 2>&1)
Sep 4 07:39:01 mps CRON[17089]: (root) CMD ( [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi)
Sep 4 07:45:01 mps CRON[17192]: (web) CMD (cd /srv/www/client.org/current && wp cron event run --due-now > /dev/null 2>&1)
Sep 4 08:00:01 mps CRON[17210]: (web) CMD (cd /srv/www/client.org/current && wp cron event run --due-now > /dev/null 2>&1)
However crontab -l
comes up as empty both for the admin and web users. No crontab for either.
Look into what events are being run by wp-cli (via cron):
$ wp cron event run --due-now
Executed the cron event 'smack_uci_cron_scheduler' in 0.012s.
Executed the cron event 'smack_uci_cron_scheduled_export' in 0.003s.
Executed the cron event 'smack_uci_email_scheduler' in 0.003s.
Executed the cron event 'smack_uci_replace_inline_images' in 0.003s.
Executed the cron event 'smack_uci_image_scheduler' in 0.003s.
Executed the cron event 'tribe_aggregator_process_insert_records' in 0.014s.
Executed the cron event 'wp_version_check' in 0.319s.
Executed the cron event 'wp_update_plugins' in 1.737s.
Executed the cron event 'wp_update_themes' in 0.288s.
Executed the cron event 'wp_scheduled_delete' in 0.006s.
Executed the cron event 'delete_expired_transients' in 0.01s.
So it looks like the smackcoders events are being run. But imports are not occurring. Looking into the role of crontab in all of this now.