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

Fixes #21383: Add logic to handle campaign within Rudder #4366

Conversation

VinceMacBuche
Copy link
Member

@VinceMacBuche VinceMacBuche requested a review from fanf July 7, 2022 14:56
@VinceMacBuche VinceMacBuche force-pushed the bug_21383/add_logic_to_handle_campaign_within_rudder branch 2 times, most recently from bc4ee62 to eaff027 Compare July 7, 2022 15:00
@VinceMacBuche VinceMacBuche mentioned this pull request Jul 7, 2022
@VinceMacBuche
Copy link
Member Author

Commit modified

@VinceMacBuche VinceMacBuche force-pushed the bug_21383/add_logic_to_handle_campaign_within_rudder branch from eaff027 to 5364c47 Compare July 7, 2022 15:12
@VinceMacBuche
Copy link
Member Author

Commit modified

@VinceMacBuche VinceMacBuche force-pushed the bug_21383/add_logic_to_handle_campaign_within_rudder branch from 5364c47 to b522b8c Compare July 7, 2022 15:28
@VinceMacBuche
Copy link
Member Author

Commit modified

@VinceMacBuche VinceMacBuche force-pushed the bug_21383/add_logic_to_handle_campaign_within_rudder branch 2 times, most recently from 1e5b13b to e0e78b4 Compare July 8, 2022 10:31
@VinceMacBuche
Copy link
Member Author

Commit modified

, eventid text
, state text
, startDate timestamp with time zone NOT NULL
, endDate timestamp with time zone NOT NULL
Copy link
Member

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.

Copy link
Member Author

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 "){
Copy link
Member

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")
Copy link
Member

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"
Copy link
Member

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)
Copy link
Member

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
}

Copy link
Member

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
Copy link
Member

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
Copy link
Member

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")
Copy link
Member

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)
}
)
Copy link
Member

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}")
Copy link
Member

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"
Copy link
Member

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

@VinceMacBuche
Copy link
Member Author

Commit modified

@VinceMacBuche VinceMacBuche force-pushed the bug_21383/add_logic_to_handle_campaign_within_rudder branch from e0e78b4 to 541669b Compare July 8, 2022 16:23
Copy link
Member

@fanf fanf left a 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

@VinceMacBuche
Copy link
Member Author

Commit modified

@VinceMacBuche VinceMacBuche force-pushed the bug_21383/add_logic_to_handle_campaign_within_rudder branch 2 times, most recently from d99b297 to 1ca8770 Compare July 11, 2022 22:55
@VinceMacBuche
Copy link
Member Author

Commit modified

@VinceMacBuche VinceMacBuche force-pushed the bug_21383/add_logic_to_handle_campaign_within_rudder branch from 1ca8770 to d855f09 Compare July 11, 2022 23:17
@Normation-Quality-Assistant
Copy link
Contributor

OK, merging this PR

@Normation-Quality-Assistant Normation-Quality-Assistant merged commit d855f09 into Normation:master Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants