semaphoreui / semaphore

Modern UI and powerful API for Ansible, Terraform, OpenTofu, PowerShell and other DevOps tools.
https://semaphoreui.com
MIT License
10.64k stars 1.07k forks source link

Odd Cron format doesn't appear to be interpreted properly #1172

Open elreydetoda opened 1 year ago

elreydetoda commented 1 year ago

So, I've got a niche (or at least from a cron perspective) use case that I need to run a playbook on every first monday of the month.

I found this article which talks about how you can override the default behavior in cron to do this. So, I set the cron in semaphore to be: 0 5 */100,1-7 * MON

Unfortunately it seems like semaphore isn't interpreting that syntax correctly, because it just ran on this past monday instead of 2023-03-06 05:00:00.

It looks like it accepted the string properly when I dump out the schedule table in the web-ui & DB:

web-ui: image

DB:

> select * from project__schedule where project_id = 1 AND template_id = 13;
+----+-------------+------------+---------------------+---------------+------------------+
| id | template_id | project_id | cron_format         | repository_id | last_commit_hash |
+----+-------------+------------+---------------------+---------------+------------------+
|  2 |          13 |          1 | 0 5 */100,1-7 * MON |          NULL | NULL             |
+----+-------------+------------+---------------------+---------------+------------------+

This was the event table:

> select * from event where id > 1030 and id < 1045;

| 1037 |          1 |       192 | task        | Task ID 192 queued for running                           | 2023-02-20 05:00:01 |    NULL |
| 1038 |          1 |       192 | task        | Task ID 192 (Monthly Updates - <REDACTED>) is preparing       | 2023-02-20 05:00:01 |    NULL |
| 1039 |          1 |       192 | task        | Task ID 192 (Monthly Updates -  <REDACTED>) finished - WAITING | 2023-02-20 05:00:09 |    NULL |
| 1040 |          1 |       192 | task        | Task ID 192 (Monthly Updates -  <REDACTED>) is running         | 2023-02-20 05:00:11 |    NULL |
| 1041 |          1 |       192 | task        | Task ID 192 (Monthly Updates -  <REDACTED>) finished - ERROR   | 2023-02-20 06:01:17 |    NULL |

I also looked at the systemd log and didn't see anything in there between those time:

# journalctl -eu semaphore --since "2023-02-20 04:00:01" --until "2023-02-20 07:01:17" --output=cat --no-pager
time="2023-02-20T05:00:00Z" level=info msg="Task 192 added to queue"
time="2023-02-20T05:00:01Z" level=info msg="Set resource locker with TaskRunner 192"
time="2023-02-20T05:00:08Z" level=info msg="Stopped preparing TaskRunner 192"
time="2023-02-20T05:00:08Z" level=info msg="Release resource locker with TaskRunner 192"
time="2023-02-20T05:00:11Z" level=info msg="Set resource locker with TaskRunner 192"
time="2023-02-20T05:00:11Z" level=info msg="Task 192 removed from queue"
time="2023-02-20T06:01:17Z" level=info msg="Stopped running TaskRunner 192"
time="2023-02-20T06:01:17Z" level=info msg="Release resource locker with TaskRunner 192"

Is there some other places I should look for errors or issues?

Please let me know if I can help in any other way.

While this shouldn't matter here is some more info on the setup:

Caesarovich commented 1 year ago

Hi, Semaphore uses the Go library robfig/cron to handle cron jobs. When setting up cron schedules you have a little tooltip linking you to this package's supported cron formats (see here).

So it appears that you are trying to use a cron format unsupported by this library.

EHEX-schildt commented 3 months ago

You may want to test a newer Version Cron and Schedules got improved.