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
Fixes #21383: Add logic to handle campaign within Rudder #4366
Fixes #21383: Add logic to handle campaign within Rudder #4366
Conversation
bc4ee62
to
eaff027
Compare
Commit modified |
eaff027
to
5364c47
Compare
Commit modified |
5364c47
to
b522b8c
Compare
Commit modified |
1e5b13b
to
e0e78b4
Compare
Commit modified |
, eventid text | ||
, state text | ||
, startDate timestamp with time zone NOT NULL | ||
, endDate timestamp with time zone NOT NULL |
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 think we will want a type
(or kind
) colum to be able to do select * from campaign where kind=dist-upgrade
once we will have several compaign type (and i will avoid a migration script later on).
We also discussed a compliance (result?) field which would a summary of the campaign results and avoid join request and computation with the campaign-specific table. Likely json with a number of success/error.
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 do think result should be apart from events
} | ||
def get(id : CampaignId) : IOResult[Campaign] = { | ||
for { | ||
content <- IOResult.effect ("error when getting "){ |
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.
missing end of message ?
def save(c : Campaign): IOResult[Campaign] = { | ||
for { | ||
file <- IOResult.effect { | ||
val file = path / (c.info.id.value ++".json") |
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.
one too many +
|
||
class CampaignRepositoryImpl(campaignSerializer: CampaignSerializer) extends CampaignRepository { | ||
|
||
val path = root / "var" / "rudder" /" configuration-repository" / "campaigns" |
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.
We want that to be a parameter to be able to change it for tests
for { | ||
file <- IOResult.effect { | ||
val file = path / (c.info.id.value ++".json") | ||
file.createFileIfNotExists(true) |
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.
can you add createParents =
, it helps understanding what the true
is
def info : CampaignInfo | ||
def details : CampaignDetails | ||
} | ||
|
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.
We will need a big warning message here: "All the data type define here are part of the json API. If you change them, change them in a forward compatible way, or seal revision in dedicated case class + skim"
} | ||
|
||
def start() = { | ||
loop.delay(5.seconds).forever |
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.
doesn't it need a .forkDaemon
?
case class CampaignEvent(id : CampaignEventId, campaignId : CampaignId, state : CampaignEventState, start : DateTime, end : DateTime ) | ||
case class CampaignEventId(value : String) | ||
|
||
sealed trait CampaignEventState |
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.
please use the conventional way:
- add a
def value: String
in trait - add an
object CampaignEventState
to encapsulate case objects - add a
def values = sealarate.IforgotTheName[CampaignEventState]
- create a
def parse(s: String) = values.find(_ == s)
If it breaks your json serialisation, you can have an implicit class ToValue(c: CampaignEventState) { def value = c match { case Scheduled => "scheduled" ... }
But it's important that the string representation of the values and their parsing is done here, and nowhere else.
Same: if you need to use string representation in db queries or whatever, use Scheduled.value
in place.
It's more searchable, and it's easier to see what needs to be updated if one day we need to change a value (and we prefer to not do it, but futur is complicated)
|
||
implicit val idDecoder : JsonDecoder[CampaignId] = JsonDecoder[String].map(s => CampaignId(s)) | ||
|
||
val iso8601 = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZZ") |
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 think we have it in DateFormaterService, else we need to add it;
} catch { | ||
case e: Exception => Left(e.getMessage) | ||
} | ||
) |
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.
actually, that devoder should be in dateformatter service (but that's for an other day, because zio json is not at that level of pom.xml IIRC)
case 3 => Right(Third) | ||
case -1 => Right(Last) | ||
case -2 => Right(SecondLast) | ||
case _ => Left(s"value should be between [-2,3], received ${v}") |
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.
0 is not a valid case, can you adapt message?
case Skipped => "skipped" | ||
case Running => "running" | ||
case Finished => "finished" | ||
case Scheduled => "scheduled" |
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 needs to be Running.value
as explained above
Commit modified |
e0e78b4
to
541669b
Compare
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.
Appart the little remarks, LGTM, you can merge it when you feel ready
Commit modified |
d99b297
to
1ca8770
Compare
Commit modified |
1ca8770
to
d855f09
Compare
OK, merging this PR |
https://issues.rudder.io/issues/21383