{"id":1183,"date":"2020-05-28T17:11:45","date_gmt":"2020-05-29T00:11:45","guid":{"rendered":"https:\/\/traverstodd.com\/?p=1183"},"modified":"2020-06-04T12:52:20","modified_gmt":"2020-06-04T19:52:20","slug":"wordpress-missed-schedule-post-refactored-large-site","status":"publish","type":"post","link":"https:\/\/traverstodd.com\/wordpress-missed-schedule-post-refactored-large-site\/","title":{"rendered":"How We Fixed WordPress’ Missed-Schedule Post (by Refactoring a Large WordPress Site)"},"content":{"rendered":"\n
The skinny:<\/strong> We fixed missed-schedule posts by reducing the site’s code landscape, examining the hosting environment, and implemented a three-prong, bulletproof approach to ensuring posts publish on time. In the process we also trimmed megabytes<\/em> of render-blocking CSS and JavaScript, changing the site’s performance measured by Google Lighthouse from 17 to 75<\/strong>. So, that’s nice.<\/p>\n\n\n\n A primer: <\/strong>We generally build WordPress sites that we ourselves have designed, and as part of that we build from scratch. This ensures we know every part of the site is high performance and security solid. <\/p>\n\n\n\n But we also inherit sites built before us. Often a site is handed our way because there are frustrations or limitations with the prior developers. Either of those scenarios generally mean we’re inheriting a site with code bloat, and by extension technical-debt. <\/p>\n\n\n\n Inheriting (or creating) code bloat means troubleshooting will be more difficult, and this was particularly true with one major site we maintain. They have an editorial schedule that requires scheduling posts within WordPress, and far too often they would log in to WordPress to see the post didn’t go out at the scheduled time and would be labeled “missed schedule”.<\/p>\n\n\n\n Having built multiple enterprise, battle-tested healthcare apps in the last few years, we’re generally able to detect and fix problems. But troubleshooting this WordPress ecosystem always presented a big challenge and we were indeed short on definitive answers, which (to state the obvious) is demoralizing to not be able to provide real, actionable answers to a client. In addition, there were sporadic but significant remarks about the site working slowly, which was also hard to pin down. So to help in solving both efforts, we first aimed to trim bloat.<\/p>\n\n\n\n It’s complicated.<\/strong> Ideally, you’d schedule your post to go out at 8 am Wednesday on some date, and yet you log into WordPress later to find the label “missed schedule” next to your scheduled post. And even though WordPress knows<\/em> it’s past schedule, it’s still sitting there. Not published. WTH.<\/p>\n\n\n\n To understand how it works, you have to glimpse the mechanics behind the scenes. Put quickly, despite WordPress being a hugely-sophisticated piece of machinery, it’s ultimately only web software that sits atop a server, and it doesn’t have direct access to what servers call a “cron job” (short for “chronological” or “time-based” job). A cron job<\/a> is just a scheduled task. I can instruct the server to “do this thing every hour of every day<\/em>“, and it’ll do it. It’s really powerful. <\/p>\n\n\n\n But WordPress doesn’t have server access that deep. So it relies on a pseudo-cron job that isn’t chronologically-based, but “event-based”. What’s the “event”? Someone visits the site. That’s it. <\/p>\n\n\n\n When someone visits the site, that counts as an “event”, and WordPress will be triggered to run through its routines, including performing any scheduled tasks. But…let’s say you scheduled your post at 8 am Wednesday, and your site is low-traffic enough that you didn’t get a visitor until, say, 9 am. Well, WordPress ran through its tasks at 9 am and determined that based on the current time, your post is now behind schedule and labeled as “missed-schedule” instead of deployed. It’s a frustrating and kind of stupid feature.<\/a> <\/p>\n\n\n\nBut first<\/h3>\n\n\n\n
Ok, but what the heck is the missed-schedule issue in WordPress? <\/h2>\n\n\n\n
The Big Event<\/h2>\n\n\n\n