Skip to content

Commit

Permalink
initial commit of reworkings
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartcarnie committed Nov 17, 2016
1 parent 2f3e378 commit 13f1bde
Show file tree
Hide file tree
Showing 22 changed files with 5,449 additions and 617 deletions.
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Created by .ignore support plugin (hsz.mobi)
### Go template
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof

.gitignore
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

Empty file modified LICENSE
100644 → 100755
Empty file.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
PROJ=$(shell realpath $$PWD/../../../..)
ENV=env GOPATH=$(PROJ)
CLI=$(ENV) easyjson -all

JSON_SRC_FILES=\
structs.go

JSON_OUT_FILES:=$(JSON_SRC_FILES:%.go=%_easyjson.go)

json: $(JSON_OUT_FILES)

%_easyjson.go: %.go
$(CLI) $^

Empty file modified README.md
100644 → 100755
Empty file.
73 changes: 28 additions & 45 deletions client.go
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goqless
package qless

import (
"encoding/json"
Expand All @@ -19,38 +19,21 @@ type Client struct {
port string

events *Events
lua *Lua
lua *redis.Script
}

func NewClient(host, port string) *Client {
return &Client{host: host, port: port}
}

func Dial(host, port string) (*Client, error) {
c := NewClient(host, port)

conn, err := redis.Dial("tcp", fmt.Sprintf("%s:%s", host, port))
if err != nil {
return nil, err
}

c.lua = NewLua(conn)
dir, err := GetCurrentDir()
if err != nil {
println(err.Error())
conn.Close()
return nil, err
}
//println(dir + "/qless-core")
err = c.lua.LoadScripts(dir + "/qless-core") // make get from lib path
func Dial(host, port string, db int) (*Client, error) {
conn, err := redis.Dial("tcp", fmt.Sprintf("%s:%s", host, port), redis.DialDatabase(db))
if err != nil {
println(err.Error())
conn.Close()
return nil, err
}

c.conn = conn
return c, nil
return &Client{
host: host,
port: port,
lua: redis.NewScript(0, qlessLua),
conn: conn,
}, nil
}

func (c *Client) Close() {
Expand All @@ -65,8 +48,8 @@ func (c *Client) Events() *Events {
return c.events
}

func (c *Client) Do(name string, keysAndArgs ...interface{}) (interface{}, error) {
return c.lua.Do(name, keysAndArgs...)
func (c *Client) Do(args ...interface{}) (interface{}, error) {
return c.lua.Do(c.conn, args...)
}

func (c *Client) Queue(name string) *Queue {
Expand All @@ -76,12 +59,12 @@ func (c *Client) Queue(name string) *Queue {
}

func (c *Client) Queues(name string) ([]*Queue, error) {
args := []interface{}{0, "queues", timestamp()}
args := []interface{}{"queues", timestamp()}
if name != "" {
args = append(args, name)
}

byts, err := redis.Bytes(c.Do("qless", args...))
byts, err := redis.Bytes(c.Do(args...))
if err != nil {
return nil, err
}
Expand All @@ -105,17 +88,17 @@ func (c *Client) Queues(name string) ([]*Queue, error) {

// Track the jid
func (c *Client) Track(jid string) (bool, error) {
return Bool(c.Do("qless", 0, "track", timestamp(), "track", jid, ""))
return Bool(c.Do("track", timestamp(), "track", jid, ""))
}

// Untrack the jid
func (c *Client) Untrack(jid string) (bool, error) {
return Bool(c.Do("qless", 0, "track", timestamp(), 0, "untrack", jid))
return Bool(c.Do("track", timestamp(), 0, "untrack", jid))
}

// Returns all the tracked jobs
func (c *Client) Tracked() (string, error) {
return redis.String(c.Do("qless", 0, "track", timestamp()))
return redis.String(c.Do("track", timestamp()))
}

func (c *Client) Get(jid string) (interface{}, error) {
Expand All @@ -127,22 +110,22 @@ func (c *Client) Get(jid string) (interface{}, error) {
return job, err
}

func (c *Client) GetJob(jid string) (*Job, error) {
byts, err := redis.Bytes(c.Do("qless", 0, "get", timestamp(), jid))
func (c *Client) GetJob(jid string) (Job, error) {
byts, err := redis.Bytes(c.Do("get", timestamp(), jid))
if err != nil {
return nil, err
}

job := NewJob(c)
err = json.Unmarshal(byts, job)
var d jobData
err = json.Unmarshal(byts, d)
if err != nil {
return nil, err
}
return job, err
return &job{&d, c}, err
}

func (c *Client) GetRecurringJob(jid string) (*RecurringJob, error) {
byts, err := redis.Bytes(c.Do("qless", 0, "recur", timestamp(), "get", jid))
byts, err := redis.Bytes(c.Do("recur", timestamp(), "get", jid))
if err != nil {
return nil, err
}
Expand All @@ -156,7 +139,7 @@ func (c *Client) GetRecurringJob(jid string) (*RecurringJob, error) {
}

func (c *Client) Completed(start, count int) ([]string, error) {
reply, err := redis.Values(c.Do("qless", 0, "jobs", timestamp(), "complete"))
reply, err := redis.Values(c.Do("jobs", timestamp(), "complete"))
if err != nil {
return nil, err
}
Expand All @@ -170,7 +153,7 @@ func (c *Client) Completed(start, count int) ([]string, error) {
}

func (c *Client) Tagged(tag string, start, count int) (*TaggedReply, error) {
byts, err := redis.Bytes(c.Do("qless", 0, "tag", timestamp(), "get", tag, start, count))
byts, err := redis.Bytes(c.Do("tag", timestamp(), "get", tag, start, count))
if err != nil {
return nil, err
}
Expand All @@ -181,7 +164,7 @@ func (c *Client) Tagged(tag string, start, count int) (*TaggedReply, error) {
}

func (c *Client) GetConfig(option string) (string, error) {
interf, err := c.Do("qless", 0, "config.get", timestamp(), option)
interf, err := c.Do("config.get", timestamp(), option)
if err != nil {
return "", err
}
Expand All @@ -207,12 +190,12 @@ func (c *Client) GetConfig(option string) (string, error) {
}

func (c *Client) SetConfig(option string, value interface{}) {
intf, err := c.Do("qless", 0, "config.set", timestamp(), option, value)
intf, err := c.Do("config.set", timestamp(), option, value)
if err != nil {
fmt.Println("setconfig, c.Do fail. interface:", intf, " err:", err)
}
}

func (c *Client) UnsetConfig(option string) {
c.Do("qless", 0, "config.unset", timestamp(), option)
c.Do("config.unset", timestamp(), option)
}
16 changes: 16 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package qless

import (
"testing"
"github.com/stretchr/testify/assert"
"fmt"
)

func TestDial(t *testing.T) {
c := newClient()
c.SetConfig("test", "hello world")
v, _ := c.GetConfig("test")
fmt.Println(v)
assert.NotNil(t, c)
c.conn.Do("FLUSHDB")
}
2 changes: 1 addition & 1 deletion events.go
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package goqless
package qless

import (
"fmt"
Expand Down
Loading

0 comments on commit 13f1bde

Please sign in to comment.