callbackWasCalledWith = *job } database = gobble.NewDatabase(sqlDB) queue = gobble.NewQueue(database, gobble.Config{}) worker = gobble.NewWorker(1, queue, callback) }) AfterEach(func() { queue.Close() }) Describe("Perform", func() { It("reserves a job, performs the callback, and then dequeues the completed job", func() { job, err := queue.Enqueue(gobble.Job{ Payload: "the-payload", }) if err != nil { panic(err) } worker.Perform() Expect(callbackWasCalledWith.ID).To(Equal(job.ID)) results, err := database.Connection.Select(gobble.Job{}, "SELECT * FROM `jobs`") if err != nil { panic(err) } Expect(len(results)).To(Equal(0))
queue = gobble.NewQueue(database, gobble.Config{ WaitMaxDuration: 50 * time.Millisecond, }) }) AfterEach(func() { queue.Close() }) Describe("Enqueue", func() { It("sticks the job in the database table", func() { job := gobble.NewJob(map[string]bool{ "testing": true, }) job, err := queue.Enqueue(job) Expect(err).NotTo(HaveOccurred()) results, err := database.Connection.Select(gobble.Job{}, "SELECT * FROM `jobs`") if err != nil { panic(err) } jobs := []gobble.Job{} for _, result := range results { jobs = append(jobs, *(result.(*gobble.Job))) } Expect(jobs).To(HaveLen(1)) Expect(jobs).To(ContainElement(job)) })