Skip to content

Commit

Permalink
StartTime -> Time, add duration to pb response
Browse files Browse the repository at this point in the history
  • Loading branch information
safeer committed Oct 2, 2024
1 parent 9c26430 commit ff1598f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
5 changes: 3 additions & 2 deletions backend/controller/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func eventDALToProto(event timeline.Event) *pbconsole.Event {

case *timeline.CronScheduledEvent:
return &pbconsole.Event{
TimeStamp: timestamppb.New(event.StartTime),
TimeStamp: timestamppb.New(event.Time),
Id: event.ID,
Entry: &pbconsole.Event_CronScheduled{
CronScheduled: &pbconsole.CronScheduledEvent{
Expand All @@ -505,7 +505,8 @@ func eventDALToProto(event timeline.Event) *pbconsole.Event {
Module: event.Verb.Module,
Name: event.Verb.Name,
},
TimeStamp: timestamppb.New(event.StartTime),
TimeStamp: timestamppb.New(event.Time),
Duration: durationpb.New(event.Duration),
ScheduledAt: timestamppb.New(event.ScheduledAt),
Schedule: event.Schedule,
Error: event.Error.Ptr(),
Expand Down
6 changes: 3 additions & 3 deletions backend/controller/cronjobs/cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (s *Service) scheduleCronJobs(ctx context.Context) (err error) {
s.timelineService.EnqueueEvent(ctx, &timeline.CronScheduled{
DeploymentKey: job.DeploymentKey,
Verb: job.Verb,
StartTime: now,
Time: now,
ScheduledAt: job.NextExecution,
Schedule: job.Schedule,
Error: optional.Some(err.Error()),
Expand Down Expand Up @@ -159,7 +159,7 @@ func (s *Service) OnJobCompletion(ctx context.Context, key model.CronJobKey, fai
s.timelineService.EnqueueEvent(ctx, &timeline.CronScheduled{
DeploymentKey: job.DeploymentKey,
Verb: job.Verb,
StartTime: now,
Time: now,
ScheduledAt: job.NextExecution,
Schedule: job.Schedule,
Error: optional.Some(err.Error()),
Expand Down Expand Up @@ -231,7 +231,7 @@ func (s *Service) scheduleCronJob(ctx context.Context, tx *dal.DAL, job model.Cr
s.timelineService.EnqueueEvent(ctx, &timeline.CronScheduled{
DeploymentKey: job.DeploymentKey,
Verb: job.Verb,
StartTime: startTime,
Time: startTime,
ScheduledAt: nextAttemptForJob,
Schedule: job.Schedule,
})
Expand Down
6 changes: 3 additions & 3 deletions backend/controller/timeline/events_cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type CronScheduled struct {
DeploymentKey model.DeploymentKey
Verb schema.Ref

StartTime time.Time
Time time.Time
ScheduledAt time.Time
Schedule string
Error optional.Option[string]
Expand All @@ -45,7 +45,7 @@ type eventCronScheduledJSON struct {

func (s *Service) insertCronScheduledEvent(ctx context.Context, querier sql.Querier, event *CronScheduled) error {
cronJSON := eventCronScheduledJSON{
DurationMS: time.Since(event.StartTime).Milliseconds(),
DurationMS: time.Since(event.Time).Milliseconds(),
ScheduledAt: event.ScheduledAt,
Schedule: event.Schedule,
Error: event.Error,
Expand All @@ -64,7 +64,7 @@ func (s *Service) insertCronScheduledEvent(ctx context.Context, querier sql.Quer

err = libdal.TranslatePGError(querier.InsertTimelineCronScheduledEvent(ctx, sql.InsertTimelineCronScheduledEventParams{
DeploymentKey: event.DeploymentKey,
TimeStamp: event.StartTime,
TimeStamp: event.Time,
Module: event.Verb.Module,
Verb: event.Verb.Name,
Payload: payload,
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/timeline/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (s *Service) transformRowsToTimelineEvents(deploymentKeys map[int64]model.D
CronScheduled: CronScheduled{
DeploymentKey: row.DeploymentKey,
Verb: schema.Ref{Module: row.CustomKey1.MustGet(), Name: row.CustomKey2.MustGet()},
StartTime: row.TimeStamp,
Time: row.TimeStamp,
ScheduledAt: jsonPayload.ScheduledAt,
Schedule: jsonPayload.Schedule,
Error: jsonPayload.Error,
Expand Down
4 changes: 2 additions & 2 deletions backend/controller/timeline/timeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestTimeline(t *testing.T) {
CronScheduled: CronScheduled{
DeploymentKey: deploymentKey,
Verb: schema.Ref{Module: "time", Name: "time"},
StartTime: time.Now().Round(time.Millisecond),
Time: time.Now().Round(time.Millisecond),
ScheduledAt: time.Now().Add(time.Minute).Round(time.Millisecond).UTC(),
Schedule: "* * * * *",
Error: optional.None[string](),
Expand All @@ -154,7 +154,7 @@ func TestTimeline(t *testing.T) {
timeline.EnqueueEvent(ctx, &CronScheduled{
DeploymentKey: cronEvent.DeploymentKey,
Verb: cronEvent.Verb,
StartTime: cronEvent.StartTime,
Time: cronEvent.Time,
ScheduledAt: cronEvent.ScheduledAt,
Schedule: cronEvent.Schedule,
Error: cronEvent.Error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { formatTimestampShort } from '../../utils/date.utils.ts'
import { verbRefString } from '../verbs/verb.utils'

export const TimelineCronScheduled = ({ cron }: { cron: CronScheduledEvent }) => {
const verbRef = cron.verbRef?.module && verbRefString(cron.verbRef) || 'unknown'
const verbRef = (cron.verbRef?.module && verbRefString(cron.verbRef)) || 'unknown'
const scheduledAt = formatTimestampShort(cron.scheduledAt)
const title = `Cron ${cron.schedule} verb ${verbRef} scheduled for ${scheduledAt}`
return (
Expand Down

0 comments on commit ff1598f

Please sign in to comment.