Skip to content

Instantly share code, notes, and snippets.

@cevin
Created April 17, 2024 05:55
Show Gist options
  • Save cevin/64fceb91cefefa9e4b232a77748a4f5e to your computer and use it in GitHub Desktop.
Save cevin/64fceb91cefefa9e4b232a77748a4f5e to your computer and use it in GitHub Desktop.
handle laravel queue jobs by golang
package main
import (
"encoding/json"
"fmt"
"github.com/elliotchance/phpserialize"
"strings"
)
type job struct {
UUID string `json:"uuid"`
DisplayName string `json:"displayName"`
Job string `json:"job"`
MaxTries int `json:"maxTries"`
Data struct {
CommandName string `json:"commandName"`
Command string `json:"command"`
} `json:"data"`
}
/*
php:
class app\job\test
{
public __construct(public $a, public $b) {}
}
*/
type jobdetail struct {
A string `php:"*app\\job\\test*a"`
B string `php:"*app\\job\\test*b"`
}
func main() {
// pop message from MQ
j := `{"uuid":"519ac043-d459-450a-9cce-2b5a38067a4c","displayName":"........ttempts":0}`
// relace \u0000 -> *
// php serialze: O:N:\"\u0000App\\job...."
j = strings.ReplaceAll(s, "\\u0000", "*")
ijob := &job{}
json.Unmarshal([]byte(j), ijob)
// job data.command
fmt.Println(ijob.Data.Command)
ijd := &jobdetail{}
phpserialize.Unmarshal([]byte(ijob.Data.Command), ijd)
fmt.Printf("%#v", ijd)
// do your logic
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment