Exemplo n.º 1
0
func (avl *av_list) process_in_moved_to(file string) error {
	var (
		f_a, f_v   string
		outf       string
		channel_id string
	)

	// check the file name is like ./1.1111111.1111111.a.mp4
	splitedfile := strings.Split(file, ".")
	if len(splitedfile) == 5 {
		channel_id = splitedfile[0]
	} else {
		logger.Warn("file %s is error", file)
	}

	if f, ok := (*avl)[channel_id]; ok {
		delete(*avl, channel_id)

		if string(splitedfile[3]) == "a" {
			f_a = file
			f_v = f
			outf = strings.Join(strings.Split(f, ".")[0:3], ".") + ".mp4"
		} else if string(splitedfile[3]) == "v" {
			f_v = file
			f_a = f
			outf = strings.Join(strings.Split(f, ".")[0:3], ".") + ".mp4"
		}
		logger.Info("f_v: " + f_v + ", f_a: " + f_a + ", outf: " + outf)

		time.Sleep(time.Duration(time.Second * 5))
		// merge video and audio
		cmd := exec.Command("ffmpeg", "-y", "-i", f_v, "-i", f_a, "-codec", "copy", outf)
		//cmd := exec.Command("ffmpeg", " -y -i ", f_v, "-i ", f_a, " -codec copy ", outf, " >/dev/null 2>&1 ")
		logger.Info("cmd's args is: ", cmd.Args)
		err := cmd.Run()
		if err != nil {
			logger.Fatal("ffmpeg merge video error:", err)
		} else {
			cmd = exec.Command("rm", "-f", f_v, " ", f_a)
			err = cmd.Run()
			if err != nil {
				logger.Warn("rm files error: %s", err)
			}
		}
	} else {
		(*avl)[channel_id] = file
	}
	return nil
}
Exemplo n.º 2
0
func handleRegist(client *NetCore.Client, msg *NetCore.NetMsg) {
	if client != courier {
		Logger.Warn(LogConf.WorkerServerJob, LogConf.SERVER, "handleRegist error, %v %v!", courier, client)
	}
	Logger.Info(LogConf.WorkerServerJob, LogConf.SERVER, "handleRegist OK, %v %v!", courier, client)

	NetCore.MarkServer(client, NetConf.Courier)
}
Exemplo n.º 3
0
func handleServerRegist(client *NetCore.Client, msg *NetCore.NetMsg) bool {
	if client != courier {
		Logger.Warn(LogConf.Admin, LogConf.SERVER, "handleServerRegist error, %v %d!", courier, client.Idx)
		return false
	}
	client.CancelWaitRegist()

	Logger.Info(LogConf.Admin, LogConf.SERVER, "handleServerRegist OK, %v %d!", courier, client.Idx)

	NetCore.MarkServer(client, NetConf.Courier)

	return true
}
Exemplo n.º 4
0
// listenEvents starts a new goroutine for each event received.
func (q *Qubot) listenEvents() {
	var wg sync.WaitGroup
	c := make(chan error, 1)
	for {
		select {
		case event := <-q.rtm.Events():
			wg.Add(2)
			go func() {
				defer wg.Done()
				go func() {
					defer wg.Done()
					defer func() {
						if p := recover(); p != nil {
							logger.Warn("qubot", "listenEvents", "Panic! Regained control.", p)
						}
					}()
					c <- q.handleEvent(&event)
				}()
				// Await until one of the channels send.
				select {
				case <-c:
				case <-time.After(eventTimeout):
					return
				}
			}()
		case err := <-c:
			if err != nil {
				logger.Warn("qubot", "listenEvents", "error", err)
			}
		case <-q.ctx.Done():
			wg.Wait()
			logger.Info("qubot", "Disconnecting from Slack RTM")
			q.rtm.Disconnect()
			return
		}
	}
}
Exemplo n.º 5
0
func main() {
	install_logger()
	pid_file := "./var/run/video_merge.pid"
	pid_locker, err := pidlock.Lock_write_pid_file(pid_file)
	logger.Info("starting ...")
	//monitorpath := "/home/li_yun/Projects/test/go"
	monitorpath, err := getMonitorPath()
	if err != nil {
		logger.Fatal("get monitor path error: %s", err)
		os.Exit(1)
	}
	log.Println(monitorpath)
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		logger.Fatal("newWatcher error: %s", err)
	}

	done := make(chan bool)
	// Process events
	go func() {
		avfile_list := make(av_list)
		for {
			select {
			case ev := <-watcher.Event:
				(&avfile_list).process_in_moved_to(ev.Name)
			case err := <-watcher.Error:
				logger.Warn("errror: %s", err)
			}
		}
	}()

	// only monitor FSN_RENAME event
	err = watcher.WatchFlags(monitorpath, fsnotify.FSN_MOVEDTO)
	if err != nil {
		logger.Fatal("add watch flags error: %s", err)
	}

	<-done
	/* ... do stuff ... */
	watcher.Close()
	pid_locker.Close()
	logger.Info("done ...")

}
Exemplo n.º 6
0
// Start the service without blocking.
func (q *Qubot) Start() error {
	// This is primarily for testing purposes, so we can verify from outside
	// that this function does not block.
	defer func() {
		close(q.ready)
	}()

	// Connect to Slack.
	err := q.connect()
	if err != nil {
		return err
	}

	// Initialize all the listeners that has been registered.
	for _, h := range q.handlers {
		q.wg.Add(1)
		go func(h Handler) {
			defer q.wg.Done()
			err := h.Start(q.ctx)
			if err != nil {
				logger.Warn("qubot", fmt.Sprintf("Handler %s terminated", reflect.TypeOf(h)))
			}
		}(h)
	}

	// Start messenger.
	q.wg.Add(1)
	go func() {
		defer q.wg.Done()
		q.m = InitMessenger(q.ctx, q.rtm)
		<-q.ctx.Done()
		q.m.Close()
	}()

	// Start event listener.
	q.wg.Add(1)
	go func() {
		defer q.wg.Done()
		q.listenEvents()
	}()

	return nil
}
Exemplo n.º 7
0
// startPoller creates a new goroutine for a channel.
// TODO: confirm delivery or retry instead (circuitbreaker?)
func (m *messenger) startPoller(q *queue.Queue) {
	logger.Debug("messenger", "Starting new poller goroutine")
	tb := ratelimit.NewBucketWithRate(msnRateLimit, 1)
	for {
		select {
		case <-m.ctx.Done():
			logger.Debug("messenger", "Closing poller")
			return
		default:
			res, err := q.Poll(1, msnPollWaitTime)
			if err != nil {
				if err != queue.ErrTimeout {
					logger.Warn("messenger", "startPoller", "error", err)
				}
				continue
			}
			msg := res[0].(*slack.OutgoingMessage)
			m.rtm.SendMessage(msg)
			tb.Wait(1) // and relax for a bit!
		}
	}
}
Exemplo n.º 8
0
func handleRegist(client *NetCore.Client, msg *NetCore.NetMsg) bool {
	var ctype = binary.LittleEndian.Uint32(msg.Buf)
	//client.CancelWaitRegist()

	/*if ctype == NetConf.Client {
		binary.LittleEndian.PutUint32(msg.Buf[0:4], NetConf.Worker)
		client.SendMsg(msg)
	} else {*/
	if client != courier {
		Logger.Warn(LogConf.WorkerServerJob, LogConf.SERVER, "handleServerRegist error, %d!", client.Idx)
		return false
	}

	Logger.Info(LogConf.WorkerServerJob, LogConf.SERVER, "handleServerRegist OK, %d!", client.Idx)

	NetCore.MarkServer(client, ctype)
	//}

	Logger.Info(LogConf.WorkerServerJob, LogConf.SERVER, "handleRegist, type: %d %d!", ctype, client.Idx)

	return true
}