Created
April 17, 2024 05:55
-
-
Save cevin/64fceb91cefefa9e4b232a77748a4f5e to your computer and use it in GitHub Desktop.
handle laravel queue jobs by golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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