-
-
Notifications
You must be signed in to change notification settings - Fork 7
refactor(BUX-411): taskmanager simplification & tasq with redis fixes #510
Conversation
Welcome to our open-source project @chris-4chain! π |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #510 +/- ##
==========================================
- Coverage 53.18% 53.04% -0.15%
==========================================
Files 110 107 -3
Lines 11251 11146 -105
==========================================
- Hits 5984 5912 -72
+ Misses 4815 4787 -28
+ Partials 452 447 -5
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
|
taskmanager/taskq.go
Outdated
// There are two ways to run a task: | ||
// Option 1: Run the task immediately | ||
if options.RunEveryPeriod == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// There are two ways to run a task: | |
// Option 1: Run the task immediately | |
if options.RunEveryPeriod == 0 { | |
if runImmediately(options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a method to the TaskRunOptions
struct. Now the line looks like this.
if options.runImmediately() {
return c.options.taskq.queue.Add(taskMessage)
}
taskmanager/taskq.go
Outdated
|
||
// Debugging | ||
c.DebugLog(fmt.Sprintf("registering task: %s...", c.options.taskq.tasks[task.Name].Name())) | ||
// Option 2: Run the task periodically using cron |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. Function names are readable enough so the comments were redundant. But I left the note comment about cron The first scheduled run
taskmanager/taskq.go
Outdated
)) | ||
// The runEveryPeriod should be greater than 1 second | ||
if runEveryPeriod < 1*time.Second { | ||
runEveryPeriod = 1 * time.Second |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe instead of default we could return an error here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Co-authored-by: Damian Orzepowski <damian.orzepowski@4chain.studio>
Co-authored-by: arkadiuszos4chain <135072995+arkadiuszos4chain@users.noreply.github.com>
β¦hub.com/BuxOrg/bux into refactor-411-taskmanager-simplification
Pull Request Checklist
Initially, the goal of this task was to simplify the taskmanager by fixing taskq and localCron and make some refactorization & simplification changes. All are done:
client
-related names/filenames to more precise ones;With
functional options;Redis
configuration:taskmanager.WithRedis
function;localCron
structure, instead, thegithub.com/robfig/cron/v3
-cronService
is used directly.After my changes, a lot of test files had to be adjusted - that's why so many files are modified.
I tested it locally running different examples and
bux-server
with backend/frontend. Tasks were correctly scheduled.TL;DR
Additionally, I tested the
bux
, running several parallel instances with Redis configuration fortaskq
. Apparently, the codebase before my changes didn't allow to run it that way. So I fixed the issue, according to task-doc, adding:After that, the
taskq
in different nodes (instances) started to communicate via Redis.But another problem appeared.
Number of cronJob executions in defined period was about number of active nodes.
In this PR I'm proposing a fix using
distributed redis locks
with TTL.lockTime
period, the job is added to ataskq
queue.Diagrams for better understanding:
Previous solution
New solution
I tested it with 6 instances and collecting local metrics. My example task has
2sec
period and every time it was executed it sent1
(one) to my local influxDB.I analysed the results, grouping metrics in
2sec
aggregation window and then summing the number of points per window.Without cronlocks
With cronlocks
Note:
Of course, the solution can be developed, but, for now:
In the future we should re-think whether using
taskq
is a good idea for us:Maybe a good alternative will be asynq.