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

add ticket metric events stream for zendesk #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions tap_zendesk/schemas/ticket_metric_events.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"properties": {
"id": {
"type": [
"null",
"integer"
]
},
"instance_id": {
"type": [
"null",
"integer"
]
},
"metric": {
"type": [
"null",
"string"
]
},
"ticket_id": {
"type": [
"null",
"integer"
]
},
"time": {
"type": [
"null",
"string"
]
},
"type": {
"type": [
"null",
"string"
]
},
"sla": {
"type": [
"null",
"object"
],
"properties": {
"target": {
"type": [
"null",
"integer"
]
},
"business_hours": {
"type": [
"null",
"boolean"
]
},
"policy": {
"type": [
"null",
"object"
],
"properties": {
"id": {
"type": [
"null",
"integer"
]
},
"title": {
"type": [
"null",
"string"
]
},
"description": {
"type": [
"null",
"string"
]
}
}
}
}
},
"status": {
"type": [
"null",
"object"
],
"properties": {
"calendar": {
"type": [
"null",
"integer"
]
},
"business": {
"type": [
"null",
"integer"
]
}
}
},
"deleted": {
"type": [
"null",
"boolean"
]
}
},
"type": [
"null",
"object"
]
}
24 changes: 24 additions & 0 deletions tap_zendesk/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,29 @@ def sync(self, ticket_id):
self.count += 1
yield (self.stream, ticket_metric)

class TicketMetricEvents(Stream):
name = "ticket_metric_events"
replication_method = "INCREMENTAL"
replication_key = "time"
count = 0

def sync(self, state):
bookmark = self.get_bookmark(state)
start = bookmark - datetime.timedelta(seconds=1)

epoch_start = int(start.strftime('%s'))
parsed_start = singer.strftime(start, "%Y-%m-%dT%H:%M:%SZ")
ticket_metric_events = self.client.tickets.metrics_incremental(start_time=epoch_start)
for event in ticket_metric_events:
self.count += 1
assert parsed_start <= event.time, "TicketMetricEvents - Record found out of time order. Details: start ({}) is not less than or equal to event.time ({})".format(parsed_start, satisfaction_rating.updated_at)
if bookmark < utils.strptime_with_tz(event.time):
self.update_bookmark(state, event.time)
if parsed_start <= event.time:
yield (self.stream, event)
# if self.count%5000 == 0:
# LOGGER.info("Latest row at {time_at}".format(time_at=event.time))

class TicketComments(Stream):
name = "ticket_comments"
replication_method = "INCREMENTAL"
Expand Down Expand Up @@ -539,5 +562,6 @@ def sync(self, state): # pylint: disable=unused-argument
"satisfaction_ratings": SatisfactionRatings,
"tags": Tags,
"ticket_metrics": TicketMetrics,
"ticket_metric_events": TicketMetricEvents,
"sla_policies": SLAPolicies,
}