Example #1
0
func saveObject(p *Pipe, pipeID string, obj interface{}) error {
	b, err := json.Marshal(obj)
	if err != nil {
		bugsnag.Notify(err)
		return err
	}
	_, err = db.Exec(`
	  INSERT INTO imports(workspace_id, key, data, created_at)
    VALUES($1, $2, $3, NOW())
	`, p.workspaceID, p.Service().keyFor(pipeID), b)
	if err != nil {
		bugsnag.Notify(err)
		return err
	}
	return nil
}
Example #2
0
func (p *Pipe) endSync(saveStatus bool, err error) error {
	if err != nil {
		p.PipeStatus.addError(err)
	}
	if saveStatus {
		if err := p.PipeStatus.save(); err != nil {
			bugsnag.Notify(err)
			return err
		}
	}
	return err
}
Example #3
0
func fetchAccounts(s Service) error {
	var response AccountsResponse
	accounts, err := s.Accounts()
	response.Accounts = accounts
	if err != nil {
		response.Error = err.Error()
	}

	b, err := json.Marshal(response)
	if err != nil {
		bugsnag.Notify(err)
		return err
	}
	_, err = db.Exec(`
    INSERT INTO imports(workspace_id, key, data, created_at)
    VALUES($1, $2, $3, NOW())
  	`, s.WorkspaceID(), s.keyFor("accounts"), b)
	if err != nil {
		bugsnag.Notify(err)
		return err
	}
	return nil
}
Example #4
0
func autoSyncRunner() {
	// Sleep 1 minute before starting
	time.Sleep(time.Minute)
	for {
		log.Println("-- Autosync started")
		pipes, err := loadAutomaticPipes()
		if err != nil {
			bugsnag.Notify(err)
		}
		for _, pipe := range pipes {
			pipe.run()
		}
		log.Println("-- Autosync finished")
		time.Sleep(10 * time.Minute)
	}
}