Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第八章:相同時間多節點排程任務防止重複執行的方式 - Mason #95

Open
0x171-0 opened this issue Aug 2, 2022 · 2 comments
Labels
question Further information is requested

Comments

@0x171-0
Copy link

0x171-0 commented Aug 2, 2022

想請教大家有沒有實作過特定時間排程任務的鎖定?我之前有過的作法是最先處理到的 pod 去 db 拿 redis key,或是利用環境變數設定特定的節點執行特定任務,好奇大家有沒有時做過其他機制來阻止排程任務重複執行?

@kylemocode kylemocode added the question Further information is requested label Aug 3, 2022
@kylemocode
Copy link
Collaborator

kylemocode commented Aug 3, 2022

印象中 kubernetes cronjobs (https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/) 應該就可以管理排程,kubernetes 根據你定的時間, 起一個 container 跑你的 code
如果有error, application 就 throw exception, 成功跑完就 system.exit(0) 結束
有 exception 的話, pod 就會一直留在那 -> 接著就需要一些 monitor mechanism 來監控 如果失敗要怎麼處理排程

我們專案在 config 上還有加
concurrencyPolicy: Forbid
來做多一層保護 => 假設每小時跑一次, 上個小時的job 失敗了, pod 還卡在哪. 這個小時 k8s 執行前, 發現已經有一個 job 還在跑, 那他就不會執行這個小時的 job

@0x171-0
Copy link
Author

0x171-0 commented Aug 3, 2022

  • 把任務存在 DB,如果遇到 timeout 跟需要 redo,就可以再拿出來做,設定狀態、deadline ,來判斷其他節點要不要做、什麼時間前要做。
  • Redis 可能會有爆掉丟失的問題
  • Jenkins 可以對特定節點下標記,只有特定的 group 才能指定排程

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants