#141 Track event state in handlers
Merged by qwan. Opened by qwan.
qwan/freshmaker event-state  into  master

Download 141.patch

Added states for Event:
1. INITIALIZED: default state when event is created
2. BUILDING: some artifacts are found and under building.
3. COMPLETE: event is handled successfully.
4. FAILED: there is error happens while handling the event.
5. SKIPPED: no action to be taken upon the event, e.g. no ArtifactBuild to be built according to the
blacklist/whitelist policy.

And create event in db for the manual rebuild case to track event status.

FIXES: #137

Send for early review on the states. Will need to update event states in all handlers.

I would add "BUILDING" here which would mean that event has been created, some artifacts has been found and it is currently being build.

rebased onto 609759293cc52c1f0ae5c890359824b032b13219

Updated to:
1. Add Building state
2. Update all handlers to create the event passed to handler in db, and update the event's state accordingly.

2 new commits added

  • Update handlers to track event state
  • Add state and state_reason for Event model

I'm not sure it's good idea to use get_or_create_from_event in set_default_db_event_context. I would better do just get_from_event and set to None if the db_event does not exist.

For example in this handler, we don't want to create db_event for every container image build which finishes in Brew. Instead, we are only interested in finished builds of events we have created before.

When build is not found in this method, it means the Brew container build which just finished was not created by Freshmaker. I think we should not transition to NOOP in this case, but just return [].

I would suggest to rephrase it as:

A decorator which will set the db event context for the given handler, using the event passed to the handler.

Maybe it is worth including db_event in the msg as well.

To make it short and more meaningful, I guess we could use:
INITIALIZED
BUILDING
COMPLETE
FAILED
SKIPPED

rebased onto bf06aa01ba1420767e8c512a4efe59d5308e5b20

@mjia , thanks for review, after discussed with @jkaluza , we agree on that creating db representation for all events can generate a lot of records in db which we don't care in most cases, so at this moment, we only do that for the manual rebuild case, I updated patch to remove the decorator, only create event in db and track its state for the manual rebuild case. I updated the EventState as you suggest.

rebased onto 35d5fcea58751391087d2a8b89efb46114a3fa45

2 new commits added

  • Track event state for the manual rebuild case
  • Add state and state_reason for Event model

I agree with server_default to INITIALIZED, but can we somehow set the default value for all the current records in DB to COMPELTE? Otherwise we will end up with all the historical events being marked as INITIALIZED, which is not right.

rebased onto 8ca8a153fbfe2b0ebb61827f8df76e537a2e09f4

Updated patch to update state to 'COMPLETE' for historical events.

:thumbsup:

Pull-Request has been merged by qwan

Metadata