this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(scheduling)!: allow clearing only scheduled jobs for specific events (closes #7)

+35 -11
+3 -2
events.go
··· 31 31 Id string `json:"id"` 32 32 // When to push the notification 33 33 SendAt time.Time `json:"send_at"` 34 - // Clear scheduled jobs for the object_id before scheduling notifications 35 - ClearSchedule bool `json:"clear_schedule"` 34 + // Clear scheduled jobs for the given event types on the object_id before scheduling notifications 35 + // TODO: generate jsonschema annotation 36 + ClearScheduleFor []Event `json:"clear_schedule_for"` 36 37 // Type of event that triggered the notification 37 38 // next-line-generate event-enum-jsonschema-values 38 39 Event Event `json:"event" jsonschema:"enum=clear_stored_schedule,enum=show_scheduled_jobs,enum=save_schedule,enum=restore_schedule,enum=restore_schedule_eager,enum=clear_schedule,enum=new_post,enum=godchild_request,enum=custom,enum=test,enum=godchild_accepted,enum=godchild_rejected,enum=pending_signup,enum=login_stuck,enum=booking_paid,enum=contribution_paid,enum=shotgun_opens_soon,enum=shotgun_closes_soon"`
+2 -2
receiver.go
··· 23 23 ll.Log("Received", "cyan", message.String()) 24 24 } 25 25 26 - if message.ClearSchedule { 27 - UnscheduleAllForObject(message.ChurrosObjectId) 26 + if len(message.ClearScheduleFor) > 0 { 27 + UnscheduleAllForObject(message.ChurrosObjectId, message.ClearScheduleFor...) 28 28 } 29 29 30 30 message.Schedule()
+24 -3
scheduler.go
··· 18 18 cmap.ConcurrentMap[string, Message] 19 19 } 20 20 21 + // schedules stores the scheduled messages in memory, as a mapping of job.Id -> job 21 22 var schedules Schedule = Schedule{cmap.New[Message]()} 22 23 23 24 func (job Message) Unschedule() { ··· 90 91 } 91 92 } 92 93 93 - func UnscheduleAllForObject(objectId string) { 94 - ll.Log("Unscheduling", "yellow", "all jobs for %s", objectId) 94 + // UnscheduleAllForObject unschedules all jobs for a given object ID. If any ofType is provided, only events of the types given will be unscheduled 95 + func UnscheduleAllForObject(objectId string, ofType ...Event) { 96 + var filter func(Message) bool 97 + if len(ofType) > 0 { 98 + ll.Log("Unscheduling", "yellow", "all jobs for %s of type %v", objectId, ofType) 99 + 100 + filter = func(job Message) bool { 101 + for _, t := range ofType { 102 + if job.Event == t { 103 + return true 104 + } 105 + } 106 + return false 107 + } 108 + 109 + } else { 110 + ll.Log("Unscheduling", "yellow", "all jobs for %s", objectId) 111 + 112 + filter = func(Message) bool { return true } 113 + } 114 + 95 115 for _, job := range schedules.Items() { 96 - if job.ChurrosObjectId == objectId { 116 + if job.ChurrosObjectId == objectId && filter(job) { 117 + ll.Log("Unscheduling", "yellow", "%s | %s", job.Id, job.String()) 97 118 job.Unschedule() 98 119 } 99 120 }
+2 -2
typescript-dist/index.js.map
··· 1 1 { 2 2 "version": 3, 3 3 "sources": ["../typescript/message.ts", "../typescript/constants.ts"], 4 - "sourcesContent": ["export interface Message {\n /**\n * URL to go to when the action button is clicked\n */\n action: string;\n /**\n * Additional action buttons\n */\n actions?: Action[];\n /**\n * Notification body\n */\n body: string;\n /**\n * Clear scheduled jobs for the object_id before scheduling notifications\n */\n clear_schedule: boolean;\n /**\n * Type of event that triggered the notification\n * next-line-generate event-enum-jsonschema-values\n */\n event: Event;\n /**\n * Unique ID for the notification scheduling request.\n */\n id: string;\n /**\n * URL to an image to display in the notification\n */\n image?: string;\n /**\n * Churros ID of the ressource (the ticket, the post, the comment, etc)\n * Used to determine to whom the notification should be sent\n * For godchild_request, this is not a user id, but a godparent request id.\n */\n object_id: string;\n /**\n * When to push the notification\n */\n send_at: Date;\n /**\n * Notification title\n */\n title: string;\n}\n\nexport interface Action {\n action: string;\n label: string;\n}\n\n/**\n * Type of event that triggered the notification\n * next-line-generate event-enum-jsonschema-values\n */\nexport enum Event {\n BookingPaid = \"booking_paid\",\n ClearSchedule = \"clear_schedule\",\n ClearStoredSchedule = \"clear_stored_schedule\",\n ContributionPaid = \"contribution_paid\",\n Custom = \"custom\",\n GodchildAccepted = \"godchild_accepted\",\n GodchildRejected = \"godchild_rejected\",\n GodchildRequest = \"godchild_request\",\n LoginStuck = \"login_stuck\",\n NewPost = \"new_post\",\n PendingSignup = \"pending_signup\",\n RestoreSchedule = \"restore_schedule\",\n RestoreScheduleEager = \"restore_schedule_eager\",\n SaveSchedule = \"save_schedule\",\n ShotgunClosesSoon = \"shotgun_closes_soon\",\n ShotgunOpensSoon = \"shotgun_opens_soon\",\n ShowScheduledJobs = \"show_scheduled_jobs\",\n Test = \"test\",\n}\n", "export const STREAM_NAME = 'notella:stream';\nexport const SUBJECT_NAME = 'notella:notification';\nexport const CONSUMER_NAME = 'NotellaConsumer';"], 5 - "mappings": ";AAuDO,IAAK,QAAL,kBAAKA,WAAL;AACH,EAAAA,OAAA,iBAAc;AACd,EAAAA,OAAA,mBAAgB;AAChB,EAAAA,OAAA,yBAAsB;AACtB,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,YAAS;AACT,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,qBAAkB;AAClB,EAAAA,OAAA,gBAAa;AACb,EAAAA,OAAA,aAAU;AACV,EAAAA,OAAA,mBAAgB;AAChB,EAAAA,OAAA,qBAAkB;AAClB,EAAAA,OAAA,0BAAuB;AACvB,EAAAA,OAAA,kBAAe;AACf,EAAAA,OAAA,uBAAoB;AACpB,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,uBAAoB;AACpB,EAAAA,OAAA,UAAO;AAlBC,SAAAA;AAAA,GAAA;;;ACvDL,IAAM,cAAc;AACpB,IAAM,eAAe;AACrB,IAAM,gBAAgB;", 4 + "sourcesContent": ["export interface Message {\n /**\n * URL to go to when the action button is clicked\n */\n action: string;\n /**\n * Additional action buttons\n */\n actions?: Action[];\n /**\n * Notification body\n */\n body: string;\n /**\n * Clear scheduled jobs for the given event types on the object_id before scheduling\n * notifications\n * TODO: generate jsonschema annotation\n */\n clear_schedule_for: string[];\n /**\n * Type of event that triggered the notification\n * next-line-generate event-enum-jsonschema-values\n */\n event: Event;\n /**\n * Unique ID for the notification scheduling request.\n */\n id: string;\n /**\n * URL to an image to display in the notification\n */\n image?: string;\n /**\n * Churros ID of the ressource (the ticket, the post, the comment, etc)\n * Used to determine to whom the notification should be sent\n * For godchild_request, this is not a user id, but a godparent request id.\n */\n object_id: string;\n /**\n * When to push the notification\n */\n send_at: Date;\n /**\n * Notification title\n */\n title: string;\n}\n\nexport interface Action {\n action: string;\n label: string;\n}\n\n/**\n * Type of event that triggered the notification\n * next-line-generate event-enum-jsonschema-values\n */\nexport enum Event {\n BookingPaid = \"booking_paid\",\n ClearSchedule = \"clear_schedule\",\n ClearStoredSchedule = \"clear_stored_schedule\",\n ContributionPaid = \"contribution_paid\",\n Custom = \"custom\",\n GodchildAccepted = \"godchild_accepted\",\n GodchildRejected = \"godchild_rejected\",\n GodchildRequest = \"godchild_request\",\n LoginStuck = \"login_stuck\",\n NewPost = \"new_post\",\n PendingSignup = \"pending_signup\",\n RestoreSchedule = \"restore_schedule\",\n RestoreScheduleEager = \"restore_schedule_eager\",\n SaveSchedule = \"save_schedule\",\n ShotgunClosesSoon = \"shotgun_closes_soon\",\n ShotgunOpensSoon = \"shotgun_opens_soon\",\n ShowScheduledJobs = \"show_scheduled_jobs\",\n Test = \"test\",\n}\n", "export const STREAM_NAME = 'notella:stream';\nexport const SUBJECT_NAME = 'notella:notification';\nexport const CONSUMER_NAME = 'NotellaConsumer';"], 5 + "mappings": ";AAyDO,IAAK,QAAL,kBAAKA,WAAL;AACH,EAAAA,OAAA,iBAAc;AACd,EAAAA,OAAA,mBAAgB;AAChB,EAAAA,OAAA,yBAAsB;AACtB,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,YAAS;AACT,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,qBAAkB;AAClB,EAAAA,OAAA,gBAAa;AACb,EAAAA,OAAA,aAAU;AACV,EAAAA,OAAA,mBAAgB;AAChB,EAAAA,OAAA,qBAAkB;AAClB,EAAAA,OAAA,0BAAuB;AACvB,EAAAA,OAAA,kBAAe;AACf,EAAAA,OAAA,uBAAoB;AACpB,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,uBAAoB;AACpB,EAAAA,OAAA,UAAO;AAlBC,SAAAA;AAAA,GAAA;;;ACzDL,IAAM,cAAc;AACpB,IAAM,eAAe;AACrB,IAAM,gBAAgB;", 6 6 "names": ["Event"] 7 7 }
+4 -2
typescript/message.ts
··· 12 12 */ 13 13 body: string; 14 14 /** 15 - * Clear scheduled jobs for the object_id before scheduling notifications 15 + * Clear scheduled jobs for the given event types on the object_id before scheduling 16 + * notifications 17 + * TODO: generate jsonschema annotation 16 18 */ 17 - clear_schedule: boolean; 19 + clear_schedule_for: string[]; 18 20 /** 19 21 * Type of event that triggered the notification 20 22 * next-line-generate event-enum-jsonschema-values