Skip to content
Snippets Groups Projects
fetch.go 1.29 KiB
Newer Older
  • Learn to ignore specific revisions
  • //
    //  tank
    //
    //  Import and Playlist Daemon for autoradio project
    //
    //
    //  Copyright (C) 2017-2018 Christian Pointner <equinox@helsinki.at>
    //
    //  This file is part of tank.
    //
    //  tank is free software: you can redistribute it and/or modify
    //  it under the terms of the GNU General Public License as published by
    //  the Free Software Foundation, either version 3 of the License, or
    //  any later version.
    //
    //  tank is distributed in the hope that it will be useful,
    //  but WITHOUT ANY WARRANTY; without even the implied warranty of
    //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    //  GNU General Public License for more details.
    //
    //  You should have received a copy of the GNU General Public License
    //  along with tank. If not, see <http://www.gnu.org/licenses/>.
    //
    
    package importer
    
    import (
    	"time"
    )
    
    const (
    	DEBUG_FETCH_TIME = 400
    )
    
    func (job *Job) fetch() error {
    	job.Progress.set(StepFetching, 0)
    
    	// TODO: actually fetch the file
    	t := time.NewTicker(100 * time.Millisecond)
    	defer t.Stop()
    	cnt := 0
    fetchLoop:
    	for {
    		select {
    		case <-job.ctx.Done():
    
    Christian Pointner's avatar
    Christian Pointner committed
    			return job.ctx.Err()
    
    		case <-t.C:
    			cnt++
    			if cnt > DEBUG_FETCH_TIME {
    				break fetchLoop
    			}
    			job.Progress.set(StepFetching, float32(cnt)/DEBUG_FETCH_TIME)
    		}
    	}
    
    	job.Progress.set(StepFetching, 1)
    	return nil
    }