Setting a timer in the past seems to not work, but it does

I often use the POST /t/:topic_id/timer action to change topic categories (from private to public).

This works fine if the time parameter is in the future, but if I use the current time (or a past time by mistake), I get a valid response but the category change does not happen instantaneously.

It usually takes 5-10 minutes, which can be confusing (I’m assuming this is due to the frequency of an internal polling loop).

Here is an example request (past time) and response:

# Request
POST /t/4378/timer HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Api-Key: REDACTED
Api-Username: REDACTED
Connection: keep-alive
Content-Length: 96
Content-Type: application/json
Host: REDACTED
User-Agent: HTTPie/2.2.0

{
    "category_id": "54",
    "status_type": "publish_to_category",
    "time": "2020-10-26 08:09:45+01:00"
}

# Response
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json; charset=utf-8
Date: Mon, 26 Oct 2020 07:09:46 GMT
Referrer-Policy: strict-origin-when-cross-origin
Server: nginx/1.18.0 (Ubuntu)
Strict-Transport-Security: max-age=63072000;
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Discourse-Route: topics/timer
X-Discourse-Username: REDACTED
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: REDACTED
X-Runtime: 0.055819
X-XSS-Protection: 1; mode=block

{
    "based_on_last_post": false,
    "category_id": 54,
    "closed": false,
    "duration": null,
    "execute_at": "2020-10-26T07:09:45.000Z",
    "success": "OK"
}

Update: I thought this was exclusive to the API, but it can also be a problem in the UI because even though you can’t select a date in the past, you can select a time in the past.

image

The behavior is the same: no indication that a timer has been set, but it still goes off anywhere between 5-10 minutes after being created.

2 Likes

This is a bit of an edge case, but I think the server should return an error message if you submit a topic timer with today’s date and a time in the past.

3 Likes

There is in fact a :bug: in the code that blocks past dating. PR is open:
https://github.com/discourse/discourse/pull/11434

3 Likes