-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKue.hx
More file actions
178 lines (140 loc) · 3.75 KB
/
Kue.hx
File metadata and controls
178 lines (140 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package js.npm;
import js.support.Callback;
/**
See https://github.com/learnboost/kue
Things from the README currently not supported:
- Custom Redis connection
- Custom
**/
extern class Kue implements npm.Package.Require<"kue","*">
{
/**
The reference to the Kue web app interface
**/
static var app:App;
/**
Create a new job queue
**/
static function createQueue():Queue;
}
/**
A Kue web-app interface
**/
extern class App
{
/**
Start the Interface listening on a certain port
**/
function listen( port:Int ):Void;
/**
Set a config item on the app
**/
function set( name:String, value:Dynamic ):Void;
}
/**
A Kue Job Queue
**/
extern class Queue
{
/**
Create a new job in this queue.
The "jobType" should have a corresponding type defined with `process`
**/
function create( jobType:String, data:Dynamic ):Job;
/**
Add a callback for processing a specific type of job.
**/
@:overload(function( jobType:String, concurrency:Int, cb:Job->Callback<String>->Void ):Void {})
function process( jobType:String, fn:Job->Callback<String>->Void ):Void;
/**
Trigger a listener for an event
**/
function on( evt:String, cb:Int->Void ):Void;
/**
A shortcut for the "job complete" event
**/
inline function onComplete( cb:Int->Void ):Void {
on( "job complete", cb );
}
/**
Set the interval to check for delayed jobs that need to be promoted
**/
function promote( int:String ):Void;
}
/**
A Kue Job
**/
extern class Job
{
/**
Get a job with the given ID.
**/
static function get( id:Int ):Job;
/**
The ID of the job
**/
var id:Int;
/**
The data that was associated with this job
**/
var data:Dynamic;
/**
Change the priority.
An int between -20 and 19 I think. Or a string:
```
low: 10
normal: 0
medium: -5
high: -10
critical: -15
```
See https://github.com/learnboost/kue#job-priority
Returns itself, so chaining is enabled.
**/
@:overload(function ( priority:String ):Job {})
function priority( niceness:Int ):Job;
/**
Number of times to attempt the Job if it fails
See https://github.com/learnboost/kue#failure-attempts
Returns itself, so chaining is enabled.
**/
function attempts( numberAttempts:Int ):Job;
/**
Delay this job by a number of milliseconds
See https://github.com/learnboost/kue#delayed-jobs
Returns itself, so chaining is enabled.
**/
function delay( milliseconds:Int ):Job;
/**
Save the current job to the queue
**/
function save():Void;
/**
Create a log entry on the current job.
See https://github.com/learnboost/kue#job-logs
These externs support up to 4 arguments, though the underling function supports an unlimited number.
Not sure how to represent this in Haxe externs...
**/
@:overload(function ( log:String, data1:Dynamic ):Void {})
@:overload(function ( log:String, data1:Dynamic, data2:Dynamic ):Void {})
@:overload(function ( log:String, data1:Dynamic, data2:Dynamic, data3:Dynamic ):Void {})
@:overload(function ( log:String, data1:Dynamic, data2:Dynamic, data3:Dynamic, data4:Dynamic ):Void {})
function log( log:String ):Void;
/**
Update the progress marker for this job
**/
function progress( completed:Int, total:Int ):Void;
/**
Trigger events
**/
@:overload(function ( event:String, cb:Int->Void ):Void {})
function on( event:String, cb:Void->Void ):Void;
/** Shortcut function for on("progress", cb) **/
inline function onProgress(cb:Int->Void):Void on("progress", cb);
/** Shortcut function for on("complete", cb) **/
inline function onComplete(cb:Void->Void):Void on("complete", cb);
/** Shortcut function for on("failed", cb) **/
inline function onFailed(cb:Void->Void):Void on("failed", cb);
/** Shortcut function for on("promotion", cb) **/
inline function onPromotion(cb:Void->Void):Void on("promotion", cb);
}