Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
repat committed Aug 29, 2019
0 parents commit 9296582
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
.DS_Store
composer.lock
vendor/
22 changes: 22 additions & 0 deletions LICENSE
@@ -0,0 +1,22 @@
[MIT LICENSE]

Copyright (c) 2019 repat, https://repat.de

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Software), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, andor sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 changes: 42 additions & 0 deletions README.md
@@ -0,0 +1,42 @@
# laravel-job-models
[![Latest Version on Packagist](https://img.shields.io/packagist/v/repat/laravel-job-models.svg?style=flat-square)](https://packagist.org/packages/repat/laravel-job-models)
[![Total Downloads](https://img.shields.io/packagist/dt/repat/laravel-job-models.svg?style=flat-square)](https://packagist.org/packages/repat/laravel-job-models)

**laravel-job-models** contains 2 Eloquent models for the tables `jobs` and `job_fails` as created by the 2 artisan commands `queue:table` and `queue:failed-table`.

## Installation
`$ composer require repat/laravel-job-models`

## Documentation

#### Casting
There is a casting to `\Carbon\Carbon` objects for: `reserved_at`, `available_at`, `created_at` and `failed_at` and a casting to array for `payload`.

#### Attributes/ Mutators
There are getters for all the keys of the payload, including the `data` array. For more information, see the [Laravel Documentation on Eloquent Mutators](https://laravel.com/docs/5.8/eloquent-mutators).

```php
$job = \Repat\LaravelJobs\Job::first();

$job->display_name;
$job->max_tries;
$job->delay;
$job->timeout;
$job->timeout_at; // cast to Carbon if not null
$job->command_name; // ->payload['data']['commandName']
$job->command; // unserialized
```

## License
* MIT, see [LICENSE](https://github.com/repat/laravel-job-models/blob/master/LICENSE)

## Version
* Version 0.1

## Contact
#### repat
* Homepage: https://repat.de
* e-mail: repat@repat.de
* Twitter: [@repat123](https://twitter.com/repat123 "repat123 on twitter")

[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=repat&url=https://github.com/repat/laravel-job-models&title=laravel-job-models&language=&tags=github&category=software)
20 changes: 20 additions & 0 deletions composer.json
@@ -0,0 +1,20 @@
{
"name": "repat/laravel-job-models",
"description": "Eloquent Models for the tables job and job_fails as created by artisan queue:table and queue:failed-table",
"keywords": ["laravel", "eloquent", "job", "jobs", "model", "job_fails", "artisan", "queue:table"],
"homepage": "https://repat.de",
"license": "MIT",
"version" : "0.1",
"authors": [
{"name": "repat", "email": "repat@repat.de"}
],
"require": {
"php": ">=5.6",
"laravel/framework": "^5.0"
},
"autoload": {
"psr-4": {
"Repat\\LaravelJobs\\": "src/Repat/LaravelJobs"
}
}
}
41 changes: 41 additions & 0 deletions src/Repat/LaravelJobs/Attributes.php
@@ -0,0 +1,41 @@
<?php

namespace Repat\LaravelJobs;

trait Attributes
{
public function getDisplayNameAttribute()
{
return $this->payload['displayName'];
}

public function getMaxTriesAttribute()
{
return $this->payload['maxTries'];
}

public function getDelayAttribute()
{
return $this->payload['delay'];
}

public function getTimeoutAttribute()
{
return $this->payload['timeout'];
}

public function getTimeoutAtAttribute()
{
return !is_null($this->payload['timeout_at']) ? new \Carbon\Carbon($this->payload['timeout_at']) : null;
}

public function getCommandNameAttribute()
{
return $this->payload['data']['commandName'];
}

public function getCommandAttribute()
{
return unserialize($this->payload['data']['command']);
}
}
17 changes: 17 additions & 0 deletions src/Repat/LaravelJobs/Job.php
@@ -0,0 +1,17 @@
<?php

namespace Repat\LaravelJobs;

class Job extends \Illuminate\Database\Eloquent\Model
{
use Attributes;

public $timestamps = false;

protected $casts = [
'payload' => 'array',
'reserved_at' => 'datetime',
'available_at' => 'datetime',
'created_at' => 'datetime',
];
}
15 changes: 15 additions & 0 deletions src/Repat/LaravelJobs/JobFail.php
@@ -0,0 +1,15 @@
<?php

namespace Repat\LaravelJobs;

class JobFail extends \Illuminate\Database\Eloquent\Model
{
use Attributes;

public $timestamps = false;

protected $casts = [
'payload' => 'array',
'failed_at' => 'datetime',
];
}

0 comments on commit 9296582

Please sign in to comment.