Giter Club home page Giter Club logo

Comments (8)

rmccue avatar rmccue commented on June 1, 2024

Is your database server's time offset 5 hours, or is the timezone itself just set to UTC-5? From what I can see, datetime columns (as used in Cavalcade) are always stored as UTC, so it's only when we cast it in order to compare to now() that it's an issue.

What I think you might be able to do is use per-connection timezones in both WordPress and Cavalcade-Runner to enforce the use of UTC. For Cavalcade, you should be able to do that with:

HM\Cavalcade\Runner::instance()->hooks->register( 'Runner.connect_to_db.connected', function ( $db ) {
	$db->exec( 'SET time_zone = "+00:00"' );
} );

(You may want to do this on the WordPress side; the code for that is left as an exercise for the reader.)

Does that solve the issue for you? We could potentially look at building this in to Cavalcade, or changing NOW() to use date( 'Y-m-d H:i:s' ) (although I'm unsure if the latter would affect query caching).

from cavalcade.

rmccue avatar rmccue commented on June 1, 2024

I did some local testing.

  • I ran SELECT NOW() which returned 2018-03-04 03:34:00 (the UTC time).
  • I then ran INSERT INTO wp_cavalcade_jobs SET site=1, hook="fake", args="a:0", start="2018-03-04 13:34:00", nextrun="2018-03-04 13:34:00"
  • I ran SELECT * FROM wp_cavalcade_jobs WHERE start < NOW() and got 0 results
  • I ran SET time_zone = "+10:00"
  • I ran SELECT NOW() and got 2018-03-04 13:34:00 (-ish)
  • I ran SELECT * FROM wp_cavalcade_jobs WHERE start < NOW() and got 1 result

So it appears that indeed the time_zone variable does affect NOW() but does not affect the datetime column, so setting the time_zone variable on connect should work correctly here.

from cavalcade.

boonebgorges avatar boonebgorges commented on June 1, 2024

@rmccue Thanks for this - you're right that time_zone is the culprit. From what you've suggested here (which aligns with my tests), setting time_zone in the runner seems to be the crux of the issue.

from cavalcade.

discoinfiltrator avatar discoinfiltrator commented on June 1, 2024

I've just run into this issue as well.

The proposed fix, adding:

HM\Cavalcade\Runner::instance()->hooks->register( 'Runner.connect_to_db.connected', function ( $db ) {
	$db->exec( 'SET time_zone = "+00:00"' );
} );

didn't work for me. Adding:

$this->db->exec( 'SET time_zone = "+00:00"' );

after we create the PDO instance works though.

from cavalcade.

rmccue avatar rmccue commented on June 1, 2024

@discoinfiltrator These should be equivalent, so not sure what's happening there. You may need to check that your callback is actually being executed; might be that where you have that code is not being run?

from cavalcade.

discoinfiltrator avatar discoinfiltrator commented on June 1, 2024

Ah, my bad. I had added the code snippet incorrectly. Both are solving the problem for me.

from cavalcade.

rmccue avatar rmccue commented on June 1, 2024

Fantastic to hear.

I'd be happy to add this to the Cavalcade Runner code itself since it simply makes things consistent with no downsides for others, if anyone wants to open a PR :)

from cavalcade.

discoinfiltrator avatar discoinfiltrator commented on June 1, 2024

Sounds great. I've created: humanmade/Cavalcade-Runner#44

from cavalcade.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.