Time-based conditional query

Suppose I have the following Server data model:

-> created_at Timestamp
-> last_ping Timestamp

A "stale" Server is defined as a Server whose last_ping occurred more than one hour ago (i.e., last_ping < Time.now - 1 hour). It should be destroyed if there exists another non-stale server that has come online (created_at) within one hour of the last_ping of the stale server.

How can I find all the Servers that should be destroyed? What would a query look like for this?

Read more here: https://stackoverflow.com/questions/67388997/time-based-conditional-query

Content Attribution

This content was originally published by kherro at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: