-
Notifications
You must be signed in to change notification settings - Fork 3
Use worker cleanup task instead of direct jedis cleanup #89
Conversation
public byte[] writeCleanUp(Set<String> removedIds){ | ||
CeleryBody body = new CeleryBody(); | ||
|
||
body.task= "cleanup"; |
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 know that we don't have a linter for java projects yet, but what do you think if we'll try to follow some basic formatting rules, common for most languages? Like spaces before and after =
and +
for example.
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.
agreed
@@ -24,6 +25,9 @@ | |||
@Component | |||
public class EntityRepository extends CachedRepository<String, EntityAdapterRegistry, Entity> { | |||
|
|||
@Autowired | |||
Scheduler scheduler; |
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.
Best practice is to use constructor injection over field or setter injection (e.g. https://www.vojtechruzicka.com/field-dependency-injection-considered-harmful/)
@alexkorotkikh could you review please? |
Codecov Report
@@ Coverage Diff @@
## master #89 +/- ##
============================================
+ Coverage 19.95% 20.63% +0.67%
- Complexity 152 159 +7
============================================
Files 92 94 +2
Lines 2290 2331 +41
Branches 232 234 +2
============================================
+ Hits 457 481 +24
- Misses 1795 1812 +17
Partials 38 38
Continue to review full report at Codecov.
|
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.
👍
@@ -65,6 +65,10 @@ | |||
public int priority = 1; | |||
public String team; | |||
} | |||
|
|||
public static class EntityCleanUpArg{ |
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.
EntityCleanUpArg<space>{
@@ -24,21 +21,43 @@ public CommandSerializer(TaskSerializerType type, Tracer tracer) { | |||
} | |||
|
|||
public String expiresTime(long interval) { | |||
Date exp = new Date(System.currentTimeMillis()+(interval * 1000L)); | |||
Date exp = new Date(System.currentTimeMillis() + (interval * 1000L)); |
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.
it's error-prone to have interval
as long
. E.g. if interval == Long.MAX_VALUE
, what do you expect interval * 1000
to be equal to? I'd change interval
to int
and maybe rename it some way to clarify it's in seconds...
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.
@alexkorotkikh this piece of code was previously there. Only formatting changes were introduced by me. I understand your point. However, I would solve this in another PR rather than using this PR to solve it
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.
oh, I was inattentive. Sorry about that.
public void notifyEntityRemove(EntityRepository repo, Entity e) { | ||
} | ||
|
||
public BatchEntityCleanup(Scheduler scheduler) { |
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.
constructor usually goes before methods in class declaration
@@ -27,6 +30,9 @@ | |||
*/ | |||
public class SingleEntityCleanup implements EntityChangeListener{ |
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.
EntityChangeListener<space>{
@@ -56,6 +62,9 @@ public void notifyEntityRemove(EntityRepository repo, Entity e) { | |||
executor.schedule(new EntityCleanupTask(e), 300, TimeUnit.SECONDS); | |||
} | |||
|
|||
@Override | |||
public void notifyBatchEntityRemove (EntityRepository repo, Set<String> removedEntities) {} |
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'm not sure, but it sounds semantically incorrect to have batch operation method in a class called SingleEntityCleanup
. Did you think about introducing new Listener interface? Like BatchEntityChangeListener
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.
The EntityRepository only allows listeners of type EntityChangeListener
https://github.com/zalando-zmon/zmon-scheduler/blob/master/src/main/java/de/zalando/zmon/scheduler/ng/entities/EntityRepository.java#L31
@@ -1,7 +1,10 @@ | |||
package de.zalando.zmon.scheduler.ng.entities; | |||
|
|||
import com.codahale.metrics.MetricRegistry; |
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.
Why were these imports added?
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.
👍
verify(listener).notifyEntityChange(eq(repository), eq(host1), eq(host1_changed)); | ||
} | ||
|
||
@Test | ||
public void TestNotifyGlobalScheduler() { |
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.
It's not typical in java for method names to start from capital case
* cleanup entities task see also zalando-zmon/zmon-scheduler#89 * finish span... * fix span? * fix span? * log_kv requires dict
👍 |
👍 |
Relates to #87