coencoppens/autotask-dashboards — pull request #23 by MattParr (2013-09-24 17:00:45+00:00)
Title: improve sync routines

I'd treat this like a quick look at what I've changed, and you let me know if you are interested in incorporating it.
If you are interested, I'll do the extra work to get it back into your repo:
* naming conventions may have slipped.
* anything else you don't like.

Not included in this pull request are two schema changes
----------------------------------------------------------------------------------
* modified field to timeentries
* last_activity field to tickets

What are all these changes?
-----------------------------------------
* I have created an object for querying the API, which abstracts the xml process
* I have moved each sync task into it's own task.
* I have removed the autotask behaivour
* Tickets and TimeEntries are sync on change only.

Why?
--------
This has reduced sync times like this log below. I can easily run my cronjob every 30 seconds.
Additionally, I do not delete tickets or timeentries, so data is saved for the future.
If you miss a few hours of syncing, reliance on the modified fields from the API means you will catch up.

```
2013-09-24 17:46:01 Cronjob: Starting CRONJOB run.
2013-09-24 17:46:01 Cronjob: Starting picklist sync
2013-09-24 17:46:06 Cronjob: Finished picklist sync
2013-09-24 17:46:06 Cronjob: Starting ticket import
2013-09-24 17:46:08 Cronjob: at query:
Ticket

LastActivityDate
2013-09-24 12:46:00

2013-09-24 17:46:09 Cronjob: Retrieved 2 Tickets
2013-09-24 17:46:09 Cronjob: Converting ticket id:55507
2013-09-24 17:46:09 Cronjob: Converting ticket id:57587
2013-09-24 17:46:09 Cronjob: Finished ticket import
2013-09-24 17:46:09 Cronjob: Starting time entry import
2013-09-24 17:46:11 Cronjob: at query:
TimeEntry

LastModifiedDateTime
2013-09-24 12:46:00

2013-09-24 17:46:12 Cronjob: Retrieved 1 time entries
2013-09-24 17:46:12 Cronjob: Converting time entry id:91948
2013-09-24 17:46:12 Cronjob: Finished time entry import
2013-09-24 17:46:12 Cronjob: - Saved kill rate history for dashboard "Dash" (180 new, 158 completed)
2013-09-24 17:46:12 Cronjob: - Saved queue health history for dashboard "Dash", queue "1st Line Support".
2013-09-24 17:46:12 Cronjob: - Saved queue health history for dashboard "Dash", queue "2nd Line Support".
2013-09-24 17:46:12 Cronjob: - Saved queue health history for dashboard "Dash", queue "3rd Line Support".
2013-09-24 17:46:12 Cronjob: > Calculating total open tickets for all dashboards..
2013-09-24 17:46:12 Cronjob: - Updated total open tickets count (844)
2013-09-24 17:46:12 Cronjob: ..done.
2013-09-24 17:46:12 Cronjob: > Clearing cache for all dashboards..
2013-09-24 17:46:12 Cronjob: ..done.
2013-09-24 17:46:12 Cronjob: Finished CRONJOB run.
```