Beispiel #1
0
// worker should take in a list of functions to "work" on
// pass in a slice
func Worker(functions []*Task, killSignal chan int) {

	// ensure that we have set up the correct function here etc
	bootstrap.Bootstrap()

	// now lets create our correct worker etc
	gearman := bootstrap.CreateWorker()

	// loop through each of the functions and print the corresponding values
	for _, element := range functions {

		gearman.AddFunc(element.TaskName, element.Task, worker.Immediately)
	}

	// now lets create a go routine to call this particular element
	go gearman.Work()

	// initialize a go routine for stopping the worker once started
	go func() {

		// now lets create a for loop to control the actual kill signal etc
		for {

			// capture the input variable that is pushed
			i := <-killSignal

			// check to see what type of signal we have sent
			if i == 0 {

				// close the connection
				gearman.Close()
			}
		}
	}()
}
// initialize a testSetupFunction here
func (s *TestSuite) SetUpSuite(c *C) {

	// initialize the bootstrap configuration
	bootstrap.Bootstrap()

	// initialize Task for this application
	Tasks[0] = NewTask("test::sample", testTask)
}
// make sure that we don'r reload the configuration file multiple times if we happend to bootstrap() multiple timesx
func (s *TestSuite) TestBootstrapCalledOnlyOnce(c *C) {

	// make sure that the memory location of the pointer is not different for each call to bootstrap
	initialConfig := bootstrap.Config

	// call the bootstrap function several times
	for i := 0; i < 10; i++ {

		bootstrap.Bootstrap()
		c.Assert(bootstrap.Config, Equals, initialConfig)
	}

	// assert that we still haven't called  the bootstrap function again
	c.Assert(bootstrap.Config, Equals, initialConfig)
}
// initialize a testSetupFunction here
func (s *TestSuite) SetUpSuite(c *C) {

	// initialize the bootstrap configuration
	bootstrap.Bootstrap()

	// cache a pointer to the config
	config := bootstrap.Config

	// initialize and cache our FixturesDir
	FixturesDir = path.Join(config.Get("baseDir").MustString(), config.Get("fixturesDir").MustString())

	// now initialize the sampleClip
	SampleClip = path.Join(FixturesDir, config.Get("fixtures").Get("clip").MustString())

	// initialize encodingType
	encodingType := config.Get("encodingTypes").MustArray()[0].(string)

	// now create a sampleJob
	SampleJob = NewJob(SampleClip, encodingType)
}